Reputation: 97
I am trying to wrap my head around BDD using Cucumber (for feature tests) and RSpec (for Unit Tests).
I am having trouble writing my first test for Cucumber. I need to authenticate first, but don't know how.
Given(/^A logged in user$/) do
visit new_user_session_path
fill_in "Email Address", :with => "[email protected]"
fill_in "Password", :with => "123456"
click_button "Log In"
end
When(/^I go to the teams page$/) do
visit teams_path
end
Then(/^I should see a list of my teams$/) do
expect(page).to have_content("Teams#index")
end
Feature:
Feature: Hello Cucumber
As a user
I want to see a list of teams on the Teams page
So that I can manage them
Background: User is Authenticated
Given A logged in user
Scenario: User sees teams
When I go to the teams page
Then I should see a list of my teams
I expect the test to pass now. But it seems that it is getting the "You need to sign in or sign up before continuing" on the sign-in page.
Upvotes: 1
Views: 1425
Reputation: 97
This worked
Given (/^I am not authenticated$/) do
visit('/users/sign_out') # ensure that at least
end
Given (/^I am a new, authenticated user$/) do
email = '[email protected]'
password = 'secretpass'
User.new(:email => email, :password => password, :password_confirmation => password).save!
visit '/users/sign_in'
fill_in "user_email", :with => email
fill_in "user_password", :with => password
click_button "Log In"
end
When(/^I go to the teams page$/) do
visit teams_path
end
Then(/^I should see a list of my teams$/) do
expect(page).to have_content("Teams#index")
end
Feature:
Feature: Hello Cucumber
As a user
I want to see a list of teams on the Teams page
So that I can manage them
Background: User Authenticates
Given I am not authenticated
Given I am a new, authenticated user
Scenario: User sees teams
When I go to the teams page
Then I should see a list of my teams
Upvotes: 1