Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cucumber support #16

Closed
nilclass opened this issue Feb 7, 2012 · 4 comments
Closed

Cucumber support #16

nilclass opened this issue Feb 7, 2012 · 4 comments

Comments

@nilclass
Copy link

nilclass commented Feb 7, 2012

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
Copy link
Owner

pat commented Feb 7, 2012

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

@nilclass
Copy link
Author

nilclass commented Feb 7, 2012

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.

@nilclass
Copy link
Author

nilclass commented Feb 7, 2012

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.

@pat pat closed this as completed Dec 23, 2012
@tstepp
Copy link

tstepp commented Feb 16, 2013

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants