pat/combustion

Cucumber support

nilclass opened this issue · 4 comments

There are a few things required to make Cucumber play nicely.
I'm using this issue to document the steps I had to take to make it work.
Maybe this will lead to a patch in the future :)

in env.rb:

Bundler.require :default, :development

$:.push(File.expand_path('../../../lib', __FILE__))
require 'my_engine'

World(Capybara::RSpecMatchers)
World(Capybara::DSL)

module RouteProxy
  # didn't find a cleaner way to get route helpers into my steps
  def method_missing(sym, *args)
    if route_helpers.respond_to?(sym)
      route_helpers.send(sym, *args)
    else
      super
    end
  end

  def route_helpers
    MyEngine::Engine.routes.url_helpers
  end
end

World(RouteProxy)

Before do
  MyEngine::Engine.routes.default_url_options[:host] = 'test.host'
end
pat commented

Thanks for those notes, definitely helpful - just to confirm, are you using just straight cucumber, or cucumber-rails?

using cucumber-rails gave me some error which I had trouble tracking down (and forgot right now), will post later. so just using plain cucumber.

Oh, actually the error was simply "no such file to load -- (...)/config/environment (LoadError)". So probably I could have fixed it by creating that file and loading my engine. However, I consider it a bad idea cluttering up my source tree with circumstantial requirements like that, which don't have some legitimate use. Maybe I could have saved a few lines above though, by doing so.

The following code will use config.ru to initialize the app (like rackup) and include url_helpers:

Bundler.require :default, :test

require 'my_engine'
require 'capybara/cucumber'

World(Capybara::RSpecMatchers)
World(Capybara::DSL)

Capybara.save_and_open_page_path = 'tmp/capybara'

combustion_rack_builder = eval "Rack::Builder.new {( " + File.read(File.dirname(__FILE__) + '/../../config.ru') + "\n )}"
Capybara.app = combustion_rack_builder.to_app
World{Capybara.app.routes.url_helpers}