Rails miniskirt duplicates on second run

109 Views Asked by At

I am currently running miniskirt and minitest in a very basic rails 3.2 app. The problem I am having is that if I declare two "it" tests within the same "describe" clause the miniskirt data in the setup method gets created twice. I am using the setup outlined by Ryan Bates in episode #327.

def setup
    @res_a = Factory(:reservation)
    @res_b = Factory(:reservation)
end

When I run the test using rake test. I get a total count of 2 reservations on the first test and then a count of 4 on the second test.

Any ideas?

UPDATE:

Here is an example of the tests I am running

it "should return all reservations for a given date" do
  Reservation.for_date(Time.mktime(2012, 1, 1)).all.count.must_equal 2
end

If I run the test above in two different it methods then the second one fails because the actual count is 4. So it seems to me that Miniskirt is not rolling back the database between tests.

1

There are 1 best solutions below

0
On

If using "describe", use before and after:

http://old.rspec.info/documentation/before_and_after.html

=== Specs

  require 'minitest/autorun'

  describe Meme do
    before do
      @meme = Meme.new
    end

    describe "when asked about cheeseburgers" do
      it "must respond positively" do
        @meme.i_can_has_cheezburger?.must_equal "OHAI!"
      end
    end

https://github.com/seattlerb/minitest