I am using rspec and capybara for test with rails 4.0
I am displaying an alert box after sending ajax request. I want to test alert box text in my spec. Is there any way to test it ?
You can only do this if you are testing with Capybara using a javascript driver such as Selenium or Poltergeist. Using rspec/capybara and selenium you can do it like this:
text = page.driver.browser.switch_to.alert.text
expect(text).to eq 'Message you are looking for'
If you are using poltergeist alert boxes are automatically confirmed, and it seems there is currently no way of interrogating the box contents before this is done. You would need to test for some change or lack thereof after the alert box is dismissed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With