简体   繁体   中英

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. The company has been using RSpec and Capybara for acceptance tests. We've got some acceptance tests under spec/acceptance that are failing with the following message:

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

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

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.

I guess it's worth noting that these specs passed before I updated rspec-rails and 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. Could that be the issue?

Try and add config.include Capybara::DSL in spec_helper.rb , inside the config block. like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM