我遇到了一个问题:
- 导轨 (3.2)
- Rspec (2.14.1)
- 数据库清理器 (1.2.0)
这是我的 Rspec 配置的样子:
RSpec.configure do |config|
config.include Capybara::DSL
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
我会在我的块中创建记录,before(:each)
但我不会在我的应用程序代码中看到它们。
这会导致问题,因为我期望不存在的对象。
经过多次尝试,我终于找到了我的问题的答案。