Skip to content

Instantly share code, notes, and snippets.

@rocknrollMarc
Created March 5, 2014 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rocknrollMarc/9367413 to your computer and use it in GitHub Desktop.
Save rocknrollMarc/9367413 to your computer and use it in GitHub Desktop.
# features/support/paths.rb
module NavigationHelpers
# Maps a name to a path. Used by the
#
# When /^I go to (.+)$/ do |page_name|
#
# step definition
#
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 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)
# features/support/selectors.rb
module HtmlSelectorsHelpers
# Maps a name to a selector. Used primarily by the
#
# When /^(.+) within (.+)$/ do |step, scope|
#
# step definitions
#
def selector_for(locator)
case locator
when "the page"
"html > body"
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
# when /^the (notice|error|info) flash$/
# ".flash.#{$1}"
# You can also return an array to use a different selector
# type, like:
#
# when /the header/
# [:xpath, "//header"]
# This allows you to provide a quoted selector as the scope
# for "within" steps as was previously the default for the
# web steps:
when /^"(.+)"$/
$1
else
raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
World(HtmlSelectorsHelpers)
# features/step_definitions/web_steps.rb
require 'cucumber/websteps'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment