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?
letcalls are lazy-evaluated, they aren’t run unless the specific method is called:Alternatively, use
let!for preconditions which are always evaluated: