ChaosPredictor ChaosPredictor - 3 months ago 14
Ruby Question

How to create functional test for Ruby on Rails

What is the best way create tests that include:


  • set checkbox

  • bush buttom

  • etc.



for Ruby on Rails test environment?

Answer

Use ActionDispatch::IntegrationTest to do this.

See the guides for more information: http://guides.rubyonrails.org/testing.html#integration-testing

If you want a better html control you can use capybara for this. (see the repo's README)

In your case the test would look something like this (with capybara):

class UiTest < ActionDispatch::IntegrationTest
  test "select check box and push button" do 
    visit "/my-route"
    check "A Checkbox" # => you can use the label or the id here
    click_on "A button" # => here too.
  end
end

Make sure that you have it setup right! See: https://github.com/jnicklas/capybara#using-capybara-with-testunit