Ruby on rails 如何使用RSpec和水豚以更惯用的方式实现这一点?
不起作用:Ruby on rails 如何使用RSpec和水豚以更惯用的方式实现这一点?,ruby-on-rails,rspec,capybara,factory-bot,Ruby On Rails,Rspec,Capybara,Factory Bot,不起作用: feature "home: don't list inactive flash sales" do let(:inactive_flash_sale) { create(:inactive_flash_sale, active: false) } scenario "does not list inactive flash sales" do visit spree.root_path expect(page).to_not have_content(in
feature "home: don't list inactive flash sales" do
let(:inactive_flash_sale) { create(:inactive_flash_sale, active: false) }
scenario "does not list inactive flash sales" do
visit spree.root_path
expect(page).to_not have_content(inactive_flash_sale.name)
end
end
作品:
feature "home: don't list inactive flash sales" do
scenario "does not list inactive flash sales" do
inactive_flash_sale = create(:inactive_flash_sale, active: false)
visit spree.root_path
expect(page).to_not have_content(inactive_flash_sale.name)
end
end
上述内容在第一种形式中不会通过,但在第二种形式中会通过。这是因为Factorygirl部分在第一个版本中访问之后才初始化,但在第二个版本中它是在访问之前初始化的。这不允许我使用let,尽管这是目前使用RSpec的惯用方法。我做错了什么?或者应该是这样吗?你应该简单地用
let替换let
代码>,这将直接创建对象