集成测试:
require 'spec_helper'
describe "Create categories and items" do
before do
ItemCategory.create(id: 1, name: "Camping, backpacking, hiking gear")
ItemName.create(itemcategory_id: 1, name: "2-person tent")
ItemName.create(itemcategory_id: 1, name: "Sleeping bag")
ItemCategory.create(id: 2, name: "Household tools")
ItemName.create(itemcategory_id: 2, name: "Electric drill")
end
it "should have the categories and items" do
ItemCategory.count == 2
ItemName.count == 3
end
describe "Request page flows" do
before do
visit '/'
select "Camping, backpacking, hiking gear", from: "ItemCategory"
click_button "Go!"
save_and_open_page
end
it "should go to the right request form" do
expect(response).to have_content("Camping, backpacking, hiking gear")
page.assert_text("Camping, backpacking, hiking gear")
ItemName.where(itemcategory_id: ic.id).all.each do |i|
page.has_text?(i.name)
end
ItemName.where.not(itemcategory_id: ic.id).all.each do |i|
page.has_text?(i.name)
end
end
end
end
在第二个阻止(it "should go to the right request form"
)它似乎没有发生Capybara响应...或者我应该使用的语义,这里是错误:
expect(response).to have_content("Camping, backpacking, hiking gear")
==> undefined local variable or method `response' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fef26c24260>
page.assert_text("Camping, backpacking, hiking gear")
==> undefined method `assert_text' for #<Capybara::Session>
第二个看起来很明显,Capybara仍然认为我在用户会话中,我只是填写输入/点击按钮。但为什么?我已点击click_button
,添加save_and_open_page
会显示正确的输出。