使用Cucumber与模块化Sinatra应用程序

我正在使用Sinatra构建一个中型应用程序,当我有一个app.rb文件并且我在Github上遵循Aslak的指导时,一切都很顺利:

http://wiki.github.com/aslakhellesoy/cucumber/sinatra

随着应用程序变得更大并且app.rb文件开始膨胀,我使用Sinatra :: Base将很多位重构为“中间件”样式模块,使用机架文件映射事物(config.ru )等

该应用程序运行良好 – 但我的规格爆炸,因为没有更多的app.rb文件供webrat运行(如上面的链接中所定义)。

我试图找到如何处理这个问题的例子 – 我认为我只是不习惯Cuke的内部胆量,因为我找不到一种方法来覆盖所有应用程序。 我试着指向“config.ru”而不是app.rb – 但这不起作用。

我最终做的 – 完全是hackish – 是在我的支持目录中有一个单独的app.rb文件,它有所有需要的东西,所以我至少可以测试模型的东西。 我也可以在那里指定路线 – 但这根本不是我想做的。

所以 – 问题是:我怎样才能让Cucumber正确使用模块化应用程序方法?

更新以包括处理多个Sinatra应用程序

需要将应用程序放在一起并更改的文件

def app Sinatra::Application end 

  def app Rack::Builder.new do map '/a' { run MyAppA } map '/b' { run MyAppB } end end 

并且只是测试应用程序。

例如,如果您在config.ru中定义了要测试的中间件,可以将其加载到应用程序的定义中。

感谢BaroqueBobcat先生 – 当然,答案似乎非常明显:)。 这是env.rb(/features/support/env.rb):

 require 'sinatra' require 'test/unit' require 'spec/expectations' require 'rack/test' require 'webrat' require 'app1' require 'app2' require 'app3' Webrat.configure do |config| config.mode = :rack end class MyWorld require 'test/unit' set :environment, :test include Rack::Test::Methods include Webrat::Methods include Webrat::Matchers Webrat::Methods.delegate_to_session :response_code, :response_body, :response def app Rack::Builder.new do map '/' do run App1 #important - this is the class name end map '/app1' do run App2 end map '/app2' do run App3 end end end end World do MyWorld.new end 

https://gist.github.com/28d510d9fc25710192bc

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