Create a gist now

Instantly share code, notes, and snippets.

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
# 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
# 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
# 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