Help RSpec + DatabaseCleaner - prematurely tearing

I lost a bit of work with RSpec, which has always adhered to xUnit-based test frameworks, but I give it an edge.

The nested nature of the way of writing specifications gives me some headaches as to where I should perform the database setup / breakaway though.

According to DatabaseCleaner README:

Spec::Runner.configure do |config|

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

end

Now I can’t use transactions because I use them in my code, so I just stick to truncation, but it should not be here or there.

I have it:

RSpec.configure do |config|
  config.mock_with :rspec

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
end

The problem is that any objects that I create in the block subjector lethave already disappeared (from the database) when I try to use them in the next block describeor it.

( Machinist ... ):

describe User do
  describe "finding with login credentials" do
    let(:user) { User.make(:username => "test", :password => "password") }
    subject { User.get_by_login_credentials!("test", "password") }
    it { should == user }
  end
end

, describe subject , , , , , , - after(:each), let?

+3
2

subject let , , / . subject user, let. , db subject, , .

, let!, before, user ( subject).

, API, RSpec :

describe User do
  it "finds a user with login credentials" do
    user = User.make(:username => "test", :password => "password")
    User.get_by_login_credentials!("test", "password").should eq(user)
  end
end

.

+5

:

, let ( ), .

, . ( Rails, - , Rails .)

(.. it) ( ) . . , , , (, , before, ).

... , . describe describe , . describe before after. , , - -
before
before

after
after

RSpec ( ), http://github.com/marnen/quorum2.

+3

All Articles