Skip to content

Instantly share code, notes, and snippets.

@joelcogen
Created September 27, 2011 14:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelcogen/1245226 to your computer and use it in GitHub Desktop.
Save joelcogen/1245226 to your computer and use it in GitHub Desktop.
JS confirm dialog testing with Cucumber, Capybara, Rails 2 and 3
Then I expect to click "OK" on a confirmation box saying "Are you sure?"
And I press "Delete"
And the confirmation box should have been displayed
When /^I expect to click "([^"]*)" on a confirmation box saying "([^"]*)"$/ do |option, message|
retval = (option == 'OK') ? 'true' : 'false'
page.evaluate_script("window.confirm = function (msg) {
document.cookie = msg
return #{retval}
}")
@expected_message = message.gsub("\\n", "\n")
end
When /^the confirmation box should have been displayed$/ do
assert page.evaluate_script('document.cookie').include?(@expected_message),
"Expected confirm box with message: '#{@expected_message}'" +
" got: '#{page.evaluate_script('document.cookie')}'"
end
Then "Delete" should have a confirmation saying "Are you sure?"
When /^"([^\"]*)" should have a confirmation saying "([^\"]*)"$/ do |locator, message|
el = find_button(locator) || find_link(locator)
el['data-confirm'].should eql(message.gsub("\\n", "\n"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment