Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View cash_out.feature
1 2 3 4 5 6 7
Scenario: Attempt to cash out less than the available balance
Given I am signed in as a complete member
And I have $25.50 in cash
When I follow "Redeem"
And I fill in the Amazon gift card amount field with "25"
And I press "Redeem"
Then I should see error messages
View cash_out.feature
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# in features/support
 
require "webrat/core/locators/locator"
 
# Lets you find a Webrat::Field via a CSS selector
module Webrat
module Locators
 
class FieldBySelectorLocator < Locator # :nodoc:
 
def locate
Field.load(@session, field_element)
end
 
def field_element
@dom.at(@value)
end
 
def error_message
"Could not find field with selector #{@value.inspect}"
end
 
end
 
def field_by_selector(selector, *field_types)
FieldBySelectorLocator.new(@session, dom, selector, *field_types).locate!
end
 
end
 
class Session
def_delegators :current_scope, :field_by_selector
end
 
module Methods
delegate_to_session :field_by_selector
end
end
 
View cash_out.feature
1 2 3 4 5 6
# in features/step_definitions
 
When /^(?:|I )fill in ([^"].*) with "([^\"]*)"$/ do |named_element, value|
field = field_by_selector(selector_for(named_element))
fill_in(field, :with => value)
end
View cash_out.feature
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# in features/support
 
module NamedElements
# Accepts a named element (such as "the user info area") and returns a
# selector to find that element on the page (such as "#user-info").
def selector_for(named_element)
case named_element
when /Amazon gift card amount/i
'input#cash_out_amazon_giftcard_amount'
 
# Add more named elements here
else
raise %{No selector defined for an element with name "#{named_element}"\n} +
"Check out features/support/named_elements.rb and add one"
end
end
end
 
World(NamedElements)
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.