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?