What is the best way to test JavaScript views (test to see if a page works JavaScript wise) in Rails?
So lets say I have a page called /users/new
that contains a form that does something. I would like to have it so that I submit the form and the JavaScript testing tool will let me know if that page breaks or not. What is the best way to do this?
I have come across three options for testing:
Konacha (best tool so far for JS BDD) http://www.solitr.com/blog/2012/04/konacha-tutorial-javascript-testing-with-rails/
JasmineRice (Jasmine + Rails + Guard) https://github.com/bradphelan/jasminerice/
Capybara Webkit. https://github.com/thoughtbot/capybara-webkit
The first two are basically there for BDD and isolated testing. The last one is more for what I'm looking for, but I don't want to have a separate testing setup for JavaScript BDD and integration testing.
Does anyone have a better solution?
Check the Teaspoon Project on github.
https://github.com/modeset/teaspoon
It supports Mocha, Jasmine, and QUnit.. has nice support for running your specs headlessly with PhantomJS (or Selenium Webdriver), and allows using the full Rails asset pipeline (coffeescript, fixtures, etc).
Also, it was heavily influenced by my experience with other test runners using Rails.
If you are using RSpec, you can use Capybara in an RSpec integration test:
spec/requests/my_spec.rb:
describe "my test", :js => true do
it "should do something" do
visit '/some/path'
click_on 'Submit'
page.should have_content 'Congratulations!'
end
end
Remember to set Capybara.javascript_driver = :webkit
in spec_helper.rb
.
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