【问题标题】:Undefined webrat methods in cucumber step_definitions黄瓜 step_definitions 中未定义的 webrat 方法
【发布时间】:2011-04-02 12:57:44
【问题描述】:

当我运行我的功能时,我得到了这个错误:

undefined method `visit' for #<Cucumber::Rails::World:0x81b17ac0> (NoMethodError)

这是我Gemfile的相关部分。

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

相关的step_definition(虽然我觉得不重要)

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

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

# […]
require 'webrat'
require 'webrat/core/matchers'

Webrat.configure do |config|
  config.mode = :rails
  config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]

我在这里缺少什么?

【问题讨论】:

  • 哇……因为我刚刚得到了一个热门问题徽章,在我看来这还没有被修补。稍后会检查...

标签: ruby-on-rails-3 cucumber webrat


【解决方案1】:

我在两个不同的情况下也遇到过这个错误:第一个例子是对 confg.mode 的调整解决了这个问题;然而,第二次,在经历了很多挫折之后,我发现了一个链接,表明捆绑器的错误版本可能是罪魁祸首。更新它解决了这个问题。

【讨论】:

    【解决方案2】:

    Paul Nelligan 尝试将其添加到 env.rb 以修复错误:“没有要加载的文件 -- action_controller/integration”

    World(Webrat::Methods)
    World(Webrat::Matchers)
    

    【讨论】:

      【解决方案3】:

      我必须将config.mode 设置为:rack 而不是:rails

      # […]
      require 'webrat'
      require 'webrat/core/matchers'
      
      Webrat.configure do |config|
        config.mode = :rack
        config.open_error_files = false # Set to true if you want error pages to pop up in the browser
      end
      # […]
      

      现在按预期工作。

      【讨论】:

      • 如果人们不知道这是要在 features/support/env.rb 中编辑
      • 这个解决方案对我有用......但是,为什么需要它?我认为 rails 生成器应该生成正确的东西,无论是 :rails 的模式(顺便说一下,webrat readme 似乎说是正确的东西)还是 :rack ......但这似乎不是就是这样。有谁知道为什么?
      • 非常感谢,这是一个非常烦人的问题。
      • 我遇到过这个问题,但是当我将 webrat 方法更改为 :rack 而不是 :rails 时,所有 response.should be_success 测试都失败了。每个人都有这个:未定义的方法“成功?”对于#<:mockresponse:00000000000000> (NoMethodError)
      猜你喜欢
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多