Re: [turnip] How to use Devise's "sign_in"

206 views
Skip to first unread message

Harlow Ward

unread,
Jul 18, 2012, 2:03:52 PM7/18/12
to ruby-...@googlegroups.com
Could you do something more like this and just have capybara replicate the steps a regular user would sign in with:

module SessionSteps
  step "i am logged in" do
     @user = mock_user # or use FactoryGirl to create a user in the database?
     visit sign_in_path

     fill_in 'Email', with: @user.email
     fill_in 'Password', with: @user.password
     click_button 'Sign in'
  end
end
RSpec.configure { |config| config.include SessionSteps }

Harlow


On Wed, Jul 18, 2012 at 10:29 AM, Dwayne Macgowan <dway...@gmail.com> wrote:
I've defined this step:

module SessionSteps
  include Devise::TestHelpers

  step "i am logged in" do
    @user = mock_user
    sign_in @user
  end
end
RSpec.configure { |config| config.include SessionSteps }


And have this feature:

Feature: list contacts
  In order to see my contacts
  As a user
  I want to list contacts

  Background: logged inq

    Given i am logged in

  Scenario: Only one contact
    Given i only have "Dwayne" on my contacts lists
    When i go to contacts page with no filters
    Then i should find "Dwayne"


I get the error:  "undefined method `env' for nil:NilClass"
Reading Devise's docs I find this is because sign_in helper should be used in controller tests. In my specs it works just fine.

What am I doing wrong?



--
--
Harlow Ward

Reply all
Reply to author
Forward
0 new messages