ruby-on-rails-3 – 黄瓜step_definitions中未定义的webrat方法

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – 黄瓜step_definitions中未定义的webrat方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我运行我的功能,我得到这个错误
  1. undefined method `visit' for #<Cucumber::Rails::World:0x81b17ac0> (NoMethodError)

这是我的Gemfile的相关部分.

  1. group :development,:test do
  2. gem "rspec-rails",">= 2.0.0.beta.19"
  3. gem "cucumber"
  4. gem "cucumber-rails",">= 0.3.2"
  5. gem 'webrat',">= 0.7.2.beta.1"
  6. end

相关的step_definition(虽然我不认为这很重要)

  1. When /^I create a movie Caddyshack in the Comendy genre$/ do
  2. visit movies_path
  3. click_link "Add Movie"
  4. fill_in "Title",:with => "Caddyshack"
  5. check "Comedy"
  6. click_button "Save"
  7. end

在env.rb中,我有以下Webrat配置:

  1. # […]
  2. require 'webrat'
  3. require 'webrat/core/matchers'
  4.  
  5. Webrat.configure do |config|
  6. config.mode = :rails
  7. config.open_error_files = false # Set to true if you want error pages to pop up in the browser
  8. end
  9. # […]

我在这里失踪了吗

解决方法

我必须将config.mode设置为:rack而不是:rails:
  1. # […]
  2. require 'webrat'
  3. require 'webrat/core/matchers'
  4.  
  5. Webrat.configure do |config|
  6. config.mode = :rack
  7. config.open_error_files = false # Set to true if you want error pages to pop up in the browser
  8. end
  9. # […]

现在按预期工作.

猜你在找的Ruby相关文章