Create a gist now

Instantly share code, notes, and snippets.

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