Multiple Sinatra Apps and Cucumber

How do I test a stack of modular (multiple) Sinatra applications with Cucumber? Honestly, I was a bit baffled about how I would get my env.rb to load my the way it should be loaded. Specifically, I wanted Cucumber to run features with my Rack::Map and other middleware just the same as when my server actually starts. There’s nothing short of several thousand blog posts about Cucumber usage and setup, but I couldn’t find anything about how to do this. Here is an example of Cucumber with Capybara env.rb loading the with Rack::Builder.

ENV['RACK_ENV'] = 'test'
require File.expand_path(File.dirname(__FILE__) + "/../../init")
require 'capybara'
require 'capybara/cucumber'
require 'spec'
class SinatraWorld
require "selenium-webdriver"
Capybara.default_driver = :selenium
# use the rackup file to load the apps w/their respective URL mappings, sweet! = eval " {( " + + '/../../') + "\n )}"
include Capybara
include Spec::Expectations
include Spec::Matchers
World do

Since the Sinatra applications are defined in the with Rack::Map, I’m not limited to just a singular Sinatra app (as so many examples demonstrate).

Here is an example of the

require File.expand_path(File.dirname(__FILE__) + "/init")
use Rack::Static, :urls => ['/javascripts', '/stylesheets', '/images', '/html'], :root => File.join(File.dirname(__FILE__), 'public')
use Rack::Lint
map "/app1" do
  run SinatraAppOne
map "/app2" do
  run SinatraAppTwo
map "/app3" do
  run SinatraAppThree

2 thoughts on “Multiple Sinatra Apps and Cucumber”

  1. You can use this, _ = Rack::Builder.parse_file(File.expand_path(‘../../’, __FILE__))
    instead of using eval

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>