by Ryan Walker

Steak + Capybara + Envjs = Refreshing take on Rails integration testing

Testing Rails apps that rely on Javascript has been rough, but recently pure Ruby implementations are emerging thanks to Steven Parkes who has put together a Ruby version of Envjs and hooking it up to Capybara. This makes it possible to test Javascript in Cucumber integration tests.

One side effect of this new power is that with Cucumber’s step definition abstraction layer, it sometimes feels like too much work, especially in situations where there is no business analyst looking at or using the plain text features.

Steak is an integration testing library alternative to Cucumber. It’s just a thin layer on top of Rspec, but effectively rips out an abstraction layer (Cucumber step matchers) and helps improve developer productivity.

  • Steak - Rspec-based integration testing library.
  • Capybara - Helper library for integration testing. Replaces webrat, supports many browser simulators including Culerity, Celerity, Selenium and Envjs.
  • Capybara-envjs - wires Capybara up to the Ruby-based env.js fork.
  • smparkes/envjs fork - fork of env.js project that uses Johnson (Ruby) rather than Rhino (Java).
  • Johnson - effectively provides Ruby implementation of Javascript (Ruby wrapper around SpiderMonkey).
  • Spidermonkey - C implementation of Javascript.
  • thatcher/env-js fork - active development fork of the original Rhino (Java) implementation of Envjs. (Official site)

Notable alternatives:

  • Cucumber - You could just keep on chugging with Cucumber + Capybara + Envjs. Nothing wrong with that decision if you have non-developers involved in your software development process.

  • Harmony and Holy Grail - Harmony allows you to execute Javascript within Ruby (any testing framework), Holy Grails plugs it into Rails. (Doesn’t yet support Rails 3 or integration tests.)

  • Blue Ridge JavaScript Testing Rails Plugin - write your Javascript unit tests in Javascript.