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 admin page' admin_path when 'the list of accounts' accounts_path when 'the list of plans page' plans_path when /^the memberships page for the "([^"]+)" account$/ account = Account.find_by_name!($1) account_memberships_path(account) when /^the projects page for the "([^"]+)" account$/ account = Account.find_by_name!($1) account_projects_path(account) when /settings page for the "([^"]+)" account$/i account = Account.find_by_name!($1) edit_account_path(account) when /settings page$/ edit_profile_path when /dashboard page$/ accounts_path when /sign up page for the "([^"]+)" plan$/i plan = Plan.find_by_name!($1) new_plan_account_path(plan) when /^the billing page for the "([^"]+)" account$/ account = Account.find_by_name!($1) account_billing_path(account) when /^the upgrade plan page for the "([^"]+)" account$/ account = Account.find_by_name!($1) edit_account_plan_path(account) when /^the new project page for the newest account by "([^"]*)"$/ user = User.find_by_email!($1) account = user.accounts.order("id desc").first new_account_project_path(account) when /^the "([^"]*)" project page$/ project = Project.find_by_name!($1) account_project_path(project.account, project) when /^the new project page for the "([^"]+)" account$/ account = Account.find_by_name!($1) new_account_project_path(account) # 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 NoMethodError, ArgumentError raise "Can't find mapping from \"#{page_name}\" to a path.\n" + "Now, go and add a mapping in #{__FILE__}" end end end end World(NavigationHelpers)