Search code examples
ruby-on-rails-3.2capybararspec-rails

Unable to setup Rspec & Capybara in Rails 3.2


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

gem "rspec-rails", :group => [:test, :development]
group :test do
  gem "factory_girl_rails"
  gem "capybara"
  gem "guard-rspec"
end

Then executed the below steps:

  1. bundle.
  2. rails g rspec:install.
  3. mkdir spec/support spec/models spec/routing.

Added "require capybara/rspec" to my spec_helper file

Created a sample test as below:

require 'spec_helper'
describe "Users" do
  describe " List users" do
    it "List all users" do
      get users_path
      page.has_content?('List Users')
    end
  end
end

but it doesn't work, getting the below error


undefined local variable or method `page' 

* I suspect that I was not configured the capybara properly, Let me know the proper way to configure the capybara.


Solution

  • Got working after including the capybara dsl to spec helper

    config.include Capybara::DSL