Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup Cucumber, Capybara and RSpec with Modular Sinatra application

Here's my config.ru

$:.unshift File.join(File.expand_path(File.dirname(__FILE__)), 'config')
require 'boot'

Routes = Rack::Mount::RouteSet.new do |set|
  set.add_route App::Users, { :path_info => %r{^/users*} }, {}, :users
  set.add_route App::Dashboard, { :path_info => %r{^/$} }, {}, :dashboard
  set.add_route Rack::File.new(File.dirname(__FILE__) + "/public"), { :path_info => %r{^/*} }, {}, :public
end

run Routes

boot.rb

require 'bundler'
Bundler.setup
Bundler.require(:default)
Mongoid.load!(File.join(File.dirname(__FILE__), '/mongoid.yml'))
%w(sinatra json yaml rack/mount rack/contrib).each {|l| require l }
Dir["./lib/**/*.rb"].each { |f| require f }

And my lib contains the apps and the models.

How to let Cucumber to see my application:

here's cucumber env.rb

require 'capybara'
require 'capybara/cucumber'
require 'rspec'

World do
  Capybara.app = App
  include Capybara
  include RSpec::Expectations
  include RSpec::Matchers
end

What I want is to let env.rb read my config.ru and get my cucumber ready for testing.

like image 734
amrnt Avatar asked May 14 '11 11:05

amrnt


1 Answers

In @amrnt's solution you can replace that line

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

with this:

Capybara.app, _ = Rack::Builder.parse_file(File.expand_path('../../config.ru', __FILE__))

or

Capybara.app = Rack::Builder.parse_file(File.expand_path('../../config.ru', __FILE__)).first    
like image 93
Vasiliy Ermolovich Avatar answered Sep 29 '22 11:09

Vasiliy Ermolovich