Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 水豚2.1.0&;Rspec 2';拥有选择器';考试失败了_Ruby On Rails_Ruby_Rspec_Capybara - Fatal编程技术网

Ruby on rails 水豚2.1.0&;Rspec 2';拥有选择器';考试失败了

Ruby on rails 水豚2.1.0&;Rspec 2';拥有选择器';考试失败了,ruby-on-rails,ruby,rspec,capybara,Ruby On Rails,Ruby,Rspec,Capybara,我有一个循环“have_selector”测试没有通过,但是使用Capybara.string的更直接的测试通过了。有人能解释一下吗 require 'spec_helper' describe "Item pages" do subject { page } describe "Item list" do let(:user) { FactoryGirl.create(:user) } before do FactoryGirl.create(:it

我有一个循环“have_selector”测试没有通过,但是使用Capybara.string的更直接的测试通过了。有人能解释一下吗

require 'spec_helper'

describe "Item pages" do

  subject { page }

  describe "Item list" do
    let(:user) { FactoryGirl.create(:user) }

    before do
      FactoryGirl.create(:item, user: user, description: "Testing")
      FactoryGirl.create(:item, user: user, description: "Testing 2")
      sign_in user
      visit items_path
    end

    it { should have_link("Logout") }

    it "should render the user's list of items" do
        user.items.each do |item|
          #expect(page).to have_selector("li##{item.id}", text: item.description)
          Capybara.string(page.body).has_selector?("li##{item.id}", text: item.description)
        end
      end
  end
end
执行此测试时,注释掉的“expect()”测试未通过,但下面的测试通过。故障信息为:

Failure/Error: expect(page.body).to have_selector("li##{item.id}", text: item.description)
     NoMethodError:
       undefined method `has_selector?' for #<String:0x007fe2a9782dd0>
Failure/Error:expect(page.body).to have_选择器(“li##{item.id}”,text:item.description)
命名错误:
未定义的方法'has_selector'#

出现错误的原因是您正在调用
字符串上的
has\u selector?
<代码>是否有选择器?
来自模块

要修复此问题,请使用以下内容更新示例:

it "should render the user's list of items" do
  user.items.each do |item|
    #expect(page).to have_selector("li##{item.id}", text: item.description)
    page.has_selector?("li##{item.id}", text: item.description)
  end
end