I have a test case:
describe User do
let(:user) { create(:user) } # FactoryGirl
it { User.count == 1 }
end
And setup:
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.before(:suite) { DatabaseCleaner.strategy = :truncation }
config.before(:each) { DatabaseCleaner.start }
config.after(:each) { DatabaseCleaner.clean }
config.use_transactional_fixtures = false
end
Why it is not working? How to use let and got a really persisted records?
let calls are lazy-evaluated, they aren't run unless the specific method is called:
describe User do
subject { user }
let(:user) { create(:user) } # FactoryGirl
it { … }
end
Alternatively, use let! for preconditions which are always evaluated:
describe User do
let!(:user) { create(:user) } # FactoryGirl
it { … }
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With