Skip to content

Instantly share code, notes, and snippets.

@JohnPlummer
Created January 31, 2011 16:21
Show Gist options
  • Save JohnPlummer/804289 to your computer and use it in GitHub Desktop.
Save JohnPlummer/804289 to your computer and use it in GitHub Desktop.
Authentication with devise - Features
Feature: Authentication
So that users can be associated with an account
As the site owner
I want users to login
Feature: Authentication
So that users can be associated with an account
As the site owner
I want users to login
Scenario: User not signed in
Given I am not signed in
When I go to the home page
Then I should be redirected to the sign in page
module NavigationHelpers
# Maps a name to a path. Used by the
#
# When /^I go to (.+)$/ do |page_name|
#
# step definition in web_steps.rb
#
def path_to(page_name)
case page_name
when /the home\s?page/
'/'
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
else
begin
page_name =~ /the (.*) page/
path_components = $1.split(/\s+/)
self.send(path_components.push('path').join('_').to_sym)
rescue Object => e
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
end
module NavigationHelpers
...
def path_to(page_name)
case page_name
when /the home\s?page/
'/'
when /the sign in page/
new_user_session_path
...
end
end
Given /^I am not signed in$/ do
end
...
Then /^(?:|I )should be on (.+)$/ do |page_name|
current_path = URI.parse(current_url).path
if current_path.respond_to? :should
current_path.should == path_to(page_name)
else
assert_equal path_to(page_name), current_path
end
end
...
...
Then /^(?:|I )should be redirected to (.+)$/ do |page_name|
Then "I should be on #{page_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment