Rails 3 +Devise + RSpec: undefined method 'visit'

I met strange problem. I have never work with Devise gem before. So, i try to write simple RSpec test:

require 'spec_helper'

describe "Admins" do
  before(:each) do
    @email = "test@test.ru"
    user = FactoryGirl.create(:user, :email => @email )

  describe "sign in/out" do
    describe "success" do
      it "should sign a user in and out" do
        visit new_user_session_path

And i receive such error:

  1) Admins sign in/out success should sign a user in and out
     Failure/Error: visit new_user_session_path
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007fb2b7e393d0>
     # ./spec/requests/admins_spec.rb:12:in `block (4 levels) in <top (required)>'

Finished in 0.05646 seconds

My Factory:

FactoryGirl.define do
  factory :user do |user|
    user.admin true
    user.password "qwerty"
    user.sequence(:email) { |n| "user#{n}@user.com" }


        new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
            user_session POST   /users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
       user_registration POST   /users(.:format)               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                         PUT    /users(.:format)               devise/registrations#update
                         DELETE /users(.:format)               devise/registrations#destroy


visit is capybara method, not Rspec. You have to add capybara gem to your Gemfile, run bundle, and require 'capybara/rspec' in spec_helper, just like ArcaneRain pointed out.

Move any tests that use capybara from spec/requests to spec/features.


You have to add Capybara DSL to the spec_helper

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

Need Your Help

Creating a database for search

java database hashmap java.util.scanner

I've created code that lets the user input a planet name and it returns the date the planet was found in, else it would return invalid planet name.

Class to manage e-mail from iPhone

iphone email class

I'm working on an iPhone app that offers the user the opportunity to send an e-mail in 3 different places in the app, and for 3 different purposes.