Vell Vell - 3 months ago 19
Ruby Question

How to execute jQuery inside an RSpec feature spec for a Rails application?

Is there a way to execute jQuery inside an RSpec feature spec for a Rails app?

I am using a plugin called jQuery TE to have a formatting toolbar. The issue is that it makes the associated textarea invisible so I don't have any direct interaction with it.

According to the jQuery TE documentation, I can use something like

$(".editor").jqte();


to add text to the textarea.

I would like to know how I can use this inside my feature spec in order to add text to the textarea.

If I create a function in a JavaScript file in the Rails application, how would I be able to execute that in the feature spec if I can't just execute the code as is?

Answer

Yes, Capybara provides an execute_script method with which you can execute Javascript: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#execute_script-instance_method

If you need to return a result there's also evaluate_script.