2
votes

I'm writing an rspec 2.10 view spec for Rails 3.2.11. I have some JavaScript in the view that I'm testing that is critical to its behavior. I have been able to enable JavaScript testing in rspec controller tests, but I have not had any luck with view specs by following the instructions here. In summary, you add the following lines to spec_helper.rb:

require 'capybara/rspec'
require 'capybara/rails'

I set my Capybara driver as webkit in my spec:

Capybara.javascript_driver = :webkit
Capybara.current_driver = Capybara.javascript_driver

I've also included the Capybara-webkit gem in my Gemfile and have run bundle install to install it. In addition, I add , :js => true before the spec block definitions.

Yet, when I run a test like

rendered.should have_content('Text in JavaScript button')

I basically get an error message that shows that the rendered view has the JavaScript within the <script></script> tags as text.

Is there a way I can enable JavaScript for my rspec view specs? I need to do unit testing, which is why I want to test this in a view spec rather than in a feature spec. Also, I don't want to use Jasmine, as this view spec interacts with Rails and I want to at least mock that behavior.

1

1 Answers

1
votes

I wasn't able to find a working solution to this problem, so I just converted my unit test into an integration/feature test.