简体   繁体   English

水豚验收测试:#的未定义方法“访问”

[英]Capybara Acceptance Tests: undefined method `visit' for #<RSpec::Core::ExampleGroup

I'm in the process of upgrading an old krufty application to Rails 3.1. 我正在将旧的krufty应用程序升级到Rails 3.1。 The company has been using RSpec and Capybara for acceptance tests. 该公司一直在使用RSpec和Capybara进行验收测试。 We've got some acceptance tests under spec/acceptance that are failing with the following message: 我们已经按照spec/acceptance验收进行了一些验收测试,但失败,并显示以下消息:

Failure/Error: get @url
 NoMethodError:
   undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007feb7c0abf58>

Here's an example of one of the tests (from the top of the file): 这是其中一个测试的示例(从文件顶部开始):

require_relative 'acceptance_helper'                                                                                                                                                 

feature 'Catalog' do                                                                                                                                                                 
  before do                                                                                                                                                                          
    Settings.use_catalog_navigation = true                                                                                                                                           
  end                                                                                                                                                                                

  context 'with a Vendor' do                                                                                                                                                         
    before do                                                                                                                                                                        
      @vendor = create(:vendor, slug: 'abc')                                                                                                                                         
      @product = create(:product_with_variants, vendor: @vendor)                                                                                                                     

      @non_vendor_product = create(:product_with_variants)                                                                                                                           
      @invisible_product = create(:product_with_variants,                                                                                                                            
                                   vendor: @vendor,                                                                                                                                  
                                   visible: false)                                                                                                                                   
      @non_available_product = create(:product_with_variants,                                                                                                                        
                                       vendor: @vendor,                                                                                                                              
                                       available: false)                                                                                                                             

      @url = "/#{@vendor.slug}"                                                                                                                                                      
    end                                                                                                                                                                              

    it 'sets @vendor' do   # <- FIRST FAILING TEST                                                                                                                                                          
      get @url                                                                                                                                                                       
      assigns(:vendor).should == @vendor                                                                                                                                             
    end

    ...  

When consulting the oracle, I keep stumbling across issues mentioning the 'visit' method such as this: https://github.com/jnicklas/capybara/issues/814 在咨询oracle时,我总是在提到“访问”方法的问题上绊脚石,例如: https : //github.com/jnicklas/capybara/issues/814

I also keep coming across posts related to this article: http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html 我还不断遇到与本文相关的帖子: http : //alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html

I'm not sure that I'm having the same issue. 我不确定是否遇到相同的问题。 I can post my spec_helper.rb and acceptance_helper.rb if they will be of any use. 如果可以使用,我可以发布我的spec_helper.rbacceptance_helper.rb

I guess it's worth noting that these specs passed before I updated rspec-rails and capybara. 我想值得注意的是,这些规格在我更新rspec-rails和capybara之前已经通过。

My gut feeling is that perhaps rspec-rails is clobbering some of capybara's methods, or some of capybara's methods are simply no longer being loaded. 我的直觉是,也许rspec-rails破坏了capybara的某些方法,或者只是不再加载某些capybara的方法。 Could that be the issue? 这可能是问题吗?

Try and add config.include Capybara::DSL in spec_helper.rb , inside the config block. 尝试在config块内的spec_helper.rb添加config.include Capybara::DSL spec_helper.rb config.include Capybara::DSL like so: 像这样:

RSpec.configure do |config|
  config.include Capybara::DSL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RSpec 3未定义方法`允许&#39;为# <RSpec::Core::ExampleGroup…> - RSpec 3 undefined method `allow' for #<RSpec::Core::ExampleGroup…> RSpec :: Core :: ExampleGroup :: Nested_2中未定义的方法&#39;it&#39; - undefined method `it' in RSpec::Core::ExampleGroup::Nested_2 未定义的方法`visit` rspec / capybara - undefined method `visit` rspec/capybara rspec capybara错误-#的未定义方法`visit&#39; - rspec capybara error - undefined method `visit' for #<RSpec RSpec:#的未定义方法“允许” - RSpec: undefined method `allow' for #<RSpec::Core::ExampleGroup::Nested 失败/错误:{访问signup_path}之前NameError:#的未定义局部变量或方法`signup_path&#39; - Failure/Error: before { visit signup_path } NameError: undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup RSpec错误“ Rspec :: Core :: ExampleGroup :: Nested的未定义方法&#39;respond_to&#39;” - RSpec error “undefined method 'respond_to' for Rspec::Core::ExampleGroup::Nested” 水豚,rspec的“未定义方法访问”错误 - “undefined method visit” error with capybara, rspec 未定义的“访问”方法(使用rspec和capybara) - Undefined method 'visit' (using rspec and capybara) RSpec :: Core :: ExampleGroup:Class的未定义方法“ alias_example_to” - undefined method `alias_example_to' for RSpec::Core::ExampleGroup:Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM