RoR - 失败/错误:response.should have.selector,Integration Test Failure

时间:2012-01-28 08:22:35

标签: ruby-on-rails integration-testing capybara webrat

嗨,我在RoR中很新,我正在尝试按照Michael Hartl的教程进行集成测试时遇到问题。

我尝试了这里给出的解决方案,Why is Rspec saying "Failure/Error: Unable to find matching line from backtrace"?。但我仍然遇到错误。

所以,当我运行$ rspec spec /时,它会显示

1) LayoutLinks should have a Home page at '/'
 Failure/Error: response.should have.selector('title', :content => "Home")
 ArgumentError:
   wrong number of arguments (0 for 1)
 # ./spec/requests/layout_links_spec.rb:7:in `block (2 levels) in <top (required)>'

这是我的宝石清单:

webrat (0.7.1)
xpath (0.1.4)
ZenTest (4.6.2)
rspec (2.8.0, 2.0.1)
rspec-core (2.8.0, 2.0.1)
rspec-expectations (2.8.0, 2.0.1)
rspec-mocks (2.8.0, 2.0.1)
rspec-rails (2.8.1, 2.8.0, 2.0.1, 2.0.0.beta.18)
rubyzip (0.9.5)
sass (3.1.12)
sass-rails (3.2.3, 3.1.5)
capybara (1.1.2)
childprocess (0.3.0)
coffee-rails (3.2.1, 3.1.1)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
cucumber (1.1.4)
cucumber-rails (1.2.1)
factory_girl (2.4.2)
factory_girl_rails (1.5.0)

这是我的宝石文件:

gem 'therubyracer'
gem 'sqlite3'

group :development do
gem 'rspec-rails'
end

group :test do
gem 'webrat', '0.7.1'
gem 'rspec'
end

Gems used only for assets and not required
in production environments by default.
group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.0'

gem 'uglifier', '>= 1.0.3'
end

我的猜测是webrat / capybara问题,但我不知道如何解决这个问题。任何帮助都感激不尽。谢谢!

1 个答案:

答案 0 :(得分:0)

我对标题选择器和水豚有同样的问题。这个代码对我很有用,试试看:

within('head title') { page.should have_content "Home" }