0
votes

I run across problems when I execute the cucumber tests on devise.

The tests that are failing are just the default ones provided when you install devise (I just modified some words for "sign in" that became "login" on my website but I don't think it's the reason of the problem).

As I'm a beginner, I don't understand what is even wrong or what cucumber is telling me. Why is it mentioning rspec here? should I add the rspec-expectations gem ?

The error I get on my console when I run cucumber:

Scenario: User signs in successfully      # features/users/sign_in.feature:12
Given I exist as a user                 # features/step_definitions/user_steps.rb:58
And I am not logged in                  # features/step_definitions/user_steps.rb:49
When I sign in with valid credentials   # features/step_definitions/user_steps.rb:72
Then I see a successful sign in message # features/step_definitions/user_steps.rb:152
  expected to find text "Signed in successfully." in "Mywebsite Follow us How it works More Login × Invalid email or password. Login * Email Password Remember me Not a member yet? Sign Up Now!Forgot your password?Didn't receive confirmation instructions? Rails Tutorial About Contact Help" (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/user_steps.rb:153:in `/^I see a successful sign in message$/'
  features/users/sign_in.feature:16:in `Then I see a successful sign in message'
When I return to the site               # features/step_definitions/user_steps.rb:110
Then I should be signed in              # features/step_definitions/user_steps.rb:136

The files the error is refering to:

/features/step_definitions/user_steps.rb

### UTILITY METHODS ###

def create_visitor
@visitor ||= { :name => "xxx", :email => "[email protected]",
:password => "xxx", :password_confirmation => "xxx" }
end

def find_user
@user ||= User.first conditions: {:email => @visitor[:email]}
end

def create_unconfirmed_user
create_visitor
delete_user
sign_up
visit '/users/sign_out'
end

def create_user
create_visitor
delete_user
@user = FactoryGirl.create(:user, email: @visitor[:email])
end

def delete_user
@user ||= User.first conditions: {:email => @visitor[:email]}
@user.destroy unless @user.nil?
end

def sign_up
delete_user
visit '/users/sign_up'
fill_in "Name", :with => @visitor[:name]
fill_in "Email", :with => @visitor[:email]
fill_in "user_password", :with => @visitor[:password]
fill_in "user_password_confirmation", :with => @visitor[:password_confirmation]
click_button "Sign up"
find_user
end

def sign_in
visit '/users/sign_in'
fill_in "Email", :with => @visitor[:email]
fill_in "Password", :with => @visitor[:password]
click_button "Login"
end

(....) and more below:

Then /^I see a successful sign in message$/ do
page.should have_content "Signed in successfully."
end

and /features/users/sign_in.feature

    Scenario: User signs in successfully
  Given I exist as a user
    And I am not logged in
  When I sign in with valid credentials
  Then I see a successful sign in message
  When I return to the site
  Then I should be signed in

When i manually go on my website, it does display "Signed in successfully." when I sign in so what's the problem? I really don't understand.

2
Do you have a test db? If not, run: rake db:test:preparedpaluy
For some reason the user creation / sign in is failing. The message about expectations is telling you why the test failed. Cucumber is like a front end, RSpec is the actual test framework under which the test are run. If you look at the failure message, it is telling you that the text you expect is not on the page that is displayedmuttonlamb
@dpaluy i'll test that indeed.Mathieu

2 Answers

1
votes

Add the following step to debug:

Then /^show me the page$/ do
  save_and_open_page
end

And add show me the page to the feature:

Given I exist as a user                 
And I am not logged in                  
When I sign in with valid credentials
Then show me the page
And I see a successful sign in message

It will help you to debug the error.

0
votes

Put this into spec_helper, or support/devise.rb

  config.include Devise::TestHelpers, :type => [:feature, :controller]