Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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/6/opengl/4.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 安装Capybara后控制器测试失败?_Ruby On Rails_Ruby On Rails 3_Rspec_Capybara - Fatal编程技术网

Ruby on rails 安装Capybara后控制器测试失败?

Ruby on rails 安装Capybara后控制器测试失败?,ruby-on-rails,ruby-on-rails-3,rspec,capybara,Ruby On Rails,Ruby On Rails 3,Rspec,Capybara,我用rspec编写了一系列控制器/视图组合测试。我添加了水豚宝石,并编写了一些通过良好的集成测试。唯一的问题是现在在我所有的控制器测试中 response.should_选择器(“某些选择器”) rspec给出了如下错误: NoMethodError: undefined method `has_selector?' for #<ActionController::TestResponse:0xa03e7ec> 下面是一个失败测试的示例: # spec/control

我用rspec编写了一系列控制器/视图组合测试。我添加了水豚宝石,并编写了一些通过良好的集成测试。唯一的问题是现在在我所有的控制器测试中

response.should_选择器(“某些选择器”)

rspec给出了如下错误:

NoMethodError:
       undefined method `has_selector?' for #<ActionController::TestResponse:0xa03e7ec>
下面是一个失败测试的示例:

# spec/controllers/books_controller_spec.rb
require 'spec_helper'

describe BooksController do
  render_views

  it "should have the right page title" do
    get :show, :id => @book.ean
    response.should have_selector("title", :content => "Lexicase | " + @book.title)
  end
end
这是一个相关的错误:

  1) BooksController GET 'show' should have the right page title
     Failure/Error: response.should have_selector("title", :content => "Lexicase | " + @book.title)
     NoMethodError:
       undefined method `has_selector?' for #<ActionController::TestResponse:0xa8488c0>
     # ./spec/controllers/books_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
1)BooksController GET'show'应具有正确的页面标题
失败/错误:response.should具有_选择器(“title”,:content=>“Lexicase |”+@book.title)
命名错误:
未定义的方法'has_selector'#
#./spec/controllers/books\u controller\u spec.rb:23:in'block(3层)in'

您可能在前面使用了Webrat,并且具有\u选择器?是Webrat匹配器。水豚没有has_选择器匹配器,它有一个名为has_css的匹配器。您可能需要将“has_选择器”替换为“has_css”。

您可能之前使用过Webrat,而has_选择器?是Webrat匹配器。水豚没有has_选择器匹配器,它有一个名为has_css的匹配器。您可能希望将“has_选择器”替换为“has_css”。

水豚助手仅在请求规范内工作。创建一个新的请求规范,或者在描述块部分传入:type=>:request,如下所示:

describe "test for the testing test", :type => :request do
  it "should work with capybara" do
    visit root_path
    click_link "Home"
    page.should WHATEVA
  end
end

我知道这个问题很久以前就被问过了,但我想我还是会和大家分享的。GLHF

水豚助手仅在请求规范内工作。创建一个新的请求规范,或者在描述块部分传入:type=>:request,如下所示:

describe "test for the testing test", :type => :request do
  it "should work with capybara" do
    visit root_path
    click_link "Home"
    page.should WHATEVA
  end
end

我知道这个问题很久以前就被问过了,但我想我还是会和大家分享的。GLHF

你能添加你的失败测试吗?你能添加你的失败测试吗?不管怎样,关于Webrat你是对的。据我所知,有一个has_选择器?方法,但它位于page方法而不是request方法上。另一件事是,我认为我不能再像对待webrat那样使用“get:show”。我必须使用visit(book_path(@book.ean))来代替。然而,visit只能通过设计发出get请求,这使得它不适合控制器单元测试。还有一个更大的问题我在这里遗漏了。哈哈,事实证明,水豚和网鼠并不像我最初设想的那样相互排斥。问题解决了!我希望博主们不要再称水豚为Webrat的替代品,或者至少用可能需要的代码更改来限定声明。在进行切换后,我不得不做很多小的修改才能让代码正常工作。是的,我也是。这不是一个临时替代品。不管怎样,你对Webrat的看法是正确的。据我所知,有一个has_选择器?方法,但它位于page方法而不是request方法上。另一件事是,我认为我不能再像对待webrat那样使用“get:show”。我必须使用visit(book_path(@book.ean))来代替。然而,visit只能通过设计发出get请求,这使得它不适合控制器单元测试。还有一个更大的问题我在这里遗漏了。哈哈,事实证明,水豚和网鼠并不像我最初设想的那样相互排斥。问题解决了!我希望博主们不要再称水豚为Webrat的替代品,或者至少用可能需要的代码更改来限定声明。在进行转换后,我不得不做很多小的修改来让我的代码正常工作。是的,我也是..这不是一个临时的替代品