Capybaras eating cucumbers
(or, testing static sites with Cucumber and Capybara)
While working on an app built purely in HTML and Javascript, we needed a good way to write integration tests. We played around with a few different approaches, including “functional” tests using one of the Javascript unit testing libraries. But for now, we settled on using Selenium.
OMG you’re crazy!
No, we’re not. The latest version of Cucumber comes with capybara, which makes it super simple to use Selenium. Capybara just uses any rack app, so we made a simple rack app that serves our static files. So here is what we ended up with in features/support/env.rb:
require 'rubygems' require 'spec' require 'cucumber' require 'rack' require 'capybara' require 'capybara/dsl' Capybara.app = Rack::Builder.new do map "/" do use Rack::Static, :urls => ["/"], :root => 'public' run lambda {|env| [404, {}, '']} end end.to_app require 'capybara/cucumber' require 'capybara/session' Capybara.default_selector = :css Capybara.default_driver = :selenium
Now just copy over the web_steps.rb that cucumber generates from another project, and proceed as normal.
2 Comments
Good stuff… I didn’t have much luck getting Selenium to play with Cucumber back along, must give it another shot.
I’m trying to get into some web development with Node.js and this will be extremely useful. Thanks!
Post a Comment