Created
July 8, 2010 07:33
-
-
Save chrisdarroch/467738 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
# Now I can do stuff like this! | |
# ... | |
When I follow "Personal Details" | |
Then I should see an inline error "can't be blank" for the following formtastic fields: | |
| label | within | | |
| Full Name | .identity | | |
| Date of birth | .identity | | |
| Gender | .identity | | |
| Marital status | .citizenship | | |
And I should see an inline error "must be selected" for the formtastic field "Title" within ".identity" | |
And I should see an inline error "Please indicate your citizenship status" for the formtastic field "Citizenship status" | |
And I should see an inline error "Please indicate how many dependants you have" for the formtastic field "Number of dependants" |
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
Then /^I should see an inline error "([^\"]*)" for the following formtastic fields:?$/ do |text, label_table| | |
label_table.hashes.each do |hash| | |
field = hash["label"] | |
scope = hash["within"] | |
if scope | |
Then "I should see an inline error \"#{text}\" for the formtastic field \"#{field}\" within \"#{scope}\"" | |
else | |
Then "I should see an inline error \"#{text}\" for the formtastic field \"#{field}\"" | |
end | |
end | |
end | |
Then /^I should see (?:the|an) (?:|inline )error "([^\"]*)" for the formtastic field "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, label, scope| | |
with_scope(scope) do | |
selector = Capybara::XPath.new("//label[contains(text(),'#{label}')]/ancestor::li") | |
selector = selector.append("//fieldset/legend/descendant-or-self::*[contains(normalize-space(.),'#{label}')]/ancestor::li") | |
element = find(:xpath, selector) | |
if element.nil? | |
msg = "The the formastic field '#{label}' could not be found" | |
msg << " within #{scope}" if scope | |
msg << "." | |
msg << " Perhaps it is hidden?" | |
msg << "\n" << "The XPath produced was: #{selector}" | |
raise Capybara::ElementNotFound, msg | |
end | |
within(:xpath, selector) do | |
result = find(:xpath, Capybara::XPath.content(text)) | |
if result.nil? | |
msg = "The text '#{text}' could not be found for the formastic field '#{label}'" | |
msg << " within #{scope}" if scope | |
msg << "." | |
msg << " Perhaps it is hidden?" | |
raise Capybara::ElementNotFound, msg | |
end | |
if page.respond_to? :should | |
page.should have_content(text) | |
else | |
assert page.has_content?(text) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment