Created
March 5, 2014 13:45
-
-
Save rocknrollMarc/9367423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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