views:

21

answers:

1

How to simulate clicking button outside the form in Rails? This button performs some javascript operations that add some elements to page. How can I test this?

A: 

If you're testing anything other than basic document structure, which you can validate in a Rails functional test, you'll need to invoke a browser environment of some sort. There are automated testing front-ends for web applications like Selenium which can be scripted to do this for you.

Testing JavaScript within Rails isn't really practical because the way JavaScript works is highly browser dependent. The only way to verify for sure is to run an instance of each target browser and perform the action.

tadman
I know Selenium but I need something integrated with Rails. Javascript is only an example. I want to do some integration tests but I can't find anything which helps me to simulate mouse clicking on all kind of buttons. I also know Webrat plugin but it only give me ability to click on form submit button.
jesper
Things like Webrat only pretend to click on buttons, it doesn't actually run the JavaScript. Webrat can tie in with Selenium, but this could end up being a ton of duct-tape and not very elegant.
tadman