Unable to setup Rspec & Capybara in Rails 3.2

后端 未结 4 509
旧巷少年郎
旧巷少年郎 2021-01-13 10:55

I am creating a sample application for rspec testing, and I followed the below steps In Gemfile:

gem \"rspec-rails\", :group => [:test, :         


        
相关标签:
4条回答
  • 2021-01-13 11:20

    Got working after including the capybara dsl to spec helper

    config.include Capybara::DSL
    
    0 讨论(0)
  • 2021-01-13 11:28

    Since you didn't specify a version for Capybara in your Gemfile, I assume you've got version >= 2.0, which means that any tests that use page should go under a spec/features directory.

    Have a look at the following links for more information:

    • rspec-rails and capybara 2.0: what you need to know
    • rspec-rails gem Capybara page

    If you don't want to use a spec/features directory, you should be able to mark a test as a feature in the following way:

    require 'spec_helper'
    describe "Users" do
      describe " List users", type: :feature do
        it "List all users" do
          get users_path
          page.has_content?('List Users')
        end
      end
    end
    
    0 讨论(0)
  • 2021-01-13 11:30

    Its worth checking out the new Capybara DSL for integration tests (note the features directory):

    # spec/features/user_list_spec.rb
    require 'spec_helper'
    
    feature 'User list' do
      scenario 'List all users' do
        visit users_path
        expect(page).to have_content 'List Users'
      end
    end
    

    I wrote a blog post with some detailed information on End-to-end testing with RSpec integration tests and Capybara using RSpec 2.0 expect syntax, along with Capybara DSL for feature/scenarios.

    0 讨论(0)
  • 2021-01-13 11:42

    You could also just add this to your spec_helper.rb:

    require 'capybara/rspec'
    
    0 讨论(0)
提交回复
热议问题