当我设置一个新的rails 3.1.3项目并用Webrat代码写一个Cucumber故事时,如下所示:
response.should contain("abc")
我运行rake cucumber
,我得到:
undefined method `contain' for #<Cucumber::Rails::World:0x00000003d2c578> (NoMethodError)
我相信Cucumber或Webrat或Rails都被破坏了,因为我没有做任何特别的事情并坚持使用文档。
以下步骤重现错误:
rvm 1.9.2
rails new testapp -d mysql
cd testapp
rake db:create
rake db:migrate
gem install cucumber-rails
gem install webrat
gem install database_cleaner
bundle install
rails g cucumber:install
rails g controller genres index
Feature: Create movie
Description
Scenario: Create a movie in genre
Given a genre named Comedy
When I create a movie Caddyshack in the Comedy genre
Then Caddyshack should be in the Comedy genre
Description
Scenario: Create a movie in genre
Given a genre named Comedy
When I create a movie Caddyshack in the Comedy genre
Then Caddyshack should be in the Comedy genre
Given /^a genre named Comedy$/ do
end
When /^I create a movie Caddyshack in the Comedy genre$/ do
end
Then /^Caddyshack should be in the Comedy genre$/ do
visit genres_path
response.should contain("abc")
end
When /^I create a movie Caddyshack in the Comedy genre$/ do
end
Then /^Caddyshack should be in the Comedy genre$/ do
visit genres_path
response.should contain("abc")
end
rails 3.1.3
黄瓜1.1.4
黄瓜轨道1.2.1
webrat 0.7.3
机架1.3.5
rake 0.9.2.2
有关如何解决此问题的任何提示?
答案 0 :(得分:2)
现在默认使用Cucumber而不是Webrat。
您需要使用have_content。
以下正确的摘录:
When /^I create a movie Caddyshack in the Comedy genre$/ do
end
Then /^Caddyshack should be in the Comedy genre$/ do
visit genres_path
response.should have_content("abc")
end
答案 1 :(得分:0)
我刚刚收到了来自Cucumber(cukes)Google小组的回复:
Cucumber-Rails在v0.5.0.beta1中放弃了对Webrat的支持(参见 https://github.com/cucumber/cucumber-rails/blob/master/History.md)
改用Capybara。