Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

JS confirm dialog testing with Cucumber, Capybara, Rails 2 and 3

View rails2_feature.feature
1 2 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
View rails2_feature.feature
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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
View rails2_feature.feature
1
Then "Delete" should have a confirmation saying "Are you sure?"
View rails2_feature.feature
1 2 3 4
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
Something went wrong with that request. Please try again.