Posted about 1 month ago. Visible to the public. Repeats.

Ensure passing Jasmine specs from your Ruby E2E tests

Jasmine Archive is a great way to unit test your JavaScript components without writing an expensive end-to-end test for every small requirement.

After we integrated Jasmine into a Rails app we often add an E2E test that opens that Jasmine runner and expects all specs to pass. This way we see Jasmine failures in our regular test runs.

RSpec

In a feature spec Archive you can run Jasmine specs like this:

Copy
scenario 'Jasmine tests' do visit test_jasmine_path expect(page).to have_content('finished in') # wait for all tests to finish expect(page).not_to have_css('.jasmine-failed .jasmine-description') # better error messages expect(page).to have_css('.jasmine-bar.jasmine-passed') # safer check end

Cucumber

In Cucumber you can run Jasmine specs like this:

Copy
Scenario: Jasmine tests When I run Jasmine tests Then all specs should have passed
Copy
When 'I run Jasmine tests' do visit test_jasmine_path end Then 'all specs should have passed' do expect(page).to have_css('.jasmine-version'), 'Failed to load Jasmine page' using_wait_time 60 do expect(page).to have_content('finished in') # patiently wait for all tests to finish end # The above check will wait until tests are finished; once they are, we want # to show fails early using_wait_time 0 do failed_specs = page.all('.jasmine-failed .jasmine-description').map(&:text) puts 'Failed Jasmine specs:' if failed_specs.any? failed_specs.each do |description| puts "* #{description}" end expect(failed_specs.size).to eq(0), "Some Jasmine Specs failed (see above)" expect(page).to have_css('.jasmine-bar.jasmine-passed') # safer check end end

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Avatar
Henning Koch
Last edit:
16 days ago
by Klaus Weidinger
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more