Capybara:未定义的方法`assert_text&#39;对于#<capybara :: session>,未定义的本地变量&#39;响应&#39; </capybara :: session>

时间:2014-10-11 20:01:57

标签: ruby-on-rails-4 rspec capybara

集成测试:

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会显示正确的输出。

0 个答案:

没有答案