undefined method `visit' when using RSpec and Capybara in rails

后端 未结 5 1059
面向向阳花
面向向阳花 2020-12-02 09:20

I can\'t get capybara working with rspec. It gives me this error:

undefined method `visit\' for #

        
5条回答
  •  不知归路
    2020-12-02 10:04

    I also had this problem,

    Adding require 'rails_helper' at the top of my feature ended up fixing my problem:

    require 'rails_helper'
    
    RSpec.describe "Products", type: :request do
     describe "GET /products" do
     it "display tasks" do
      Product.create!(:name => "samsung")
      visit products_path
      page.should have_content("samsung")
      #expect(response).to have_http_status(200)
      end
     end
    end
    

    And add the 'config.include Capybara::DSL' in rails_helper.rb

    RSpec.configure do |config|
    
     config.fixture_path = "#{::Rails.root}/spec/fixtures"
    
     config.use_transactional_fixtures = true
    
     config.infer_spec_type_from_file_location!
    
     config.include Capybara::DSL
    
    end
    

提交回复
热议问题