将 Cucumber 与模块化 Sinatra 应用程序一起使用 [英] Using Cucumber With Modular Sinatra Apps

查看:12
本文介绍了将 Cucumber 与模块化 Sinatra 应用程序一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sinatra 构建一个中型应用程序,当我只有一个 app.rb 文件并在 Github 上按照 Aslak 的指导进行操作时,一切都很好:

I'm building out a medium-sized application using Sinatra and all was well when I had a single app.rb file and I followed Aslak's guidance up on Github:

https://github.com/cucumber/cucumber/wiki/Sinatra

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

As the app grew a bit larger and the app.rb file started to bulge, I refactored out a lot of of the bits into "middleware" style modules using Sinatra::Base, mapping things using a rack-up file (config.ru) etc.

该应用运行良好 - 但我的规范崩溃了,因为没有更多 app.rb 文件可供 webrat 运行(如上面的链接中所定义).

The app works nicely - but my specs blew up as there was no more app.rb file for webrat to run against (as defined in the link above).

我试图找到有关如何使用此功能的示例 - 我认为我还没有习惯 Cuke 的内部结构,因为我找不到一种方法可以让它涵盖所有应用程序.我试着只指向config.ru"而不是 app.rb——但这不起作用.

I've tried to find examples on how to work this - and I think I'm just not used to the internal guts of Cuke just yet as I can't find a single way to have it cover all the apps. I tried just pointing to "config.ru" instead of app.rb - but that doesn't work.

我最终做的——这完全是骇人听闻的——是在我的支持目录中有一个单独的 app.rb 文件,其中包含所有需要的东西,所以我至少可以测试模型的东西.我也可以在那里指定路线 - 但这根本不是我想要做的.

What I ended up doing - which is completely hackish - is to have a separate app.rb file in my support directory, which has all the requires stuff so I can at least test the model stuff. I can also specify routes in there - but that's not at all what I want to do.

所以 - 问题是:如何让 Cucumber 正确使用模块化应用程序方法?

So - the question is: how can I get Cucumber to properly work with the modular app approach?

推荐答案

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

需要你的应用程序所在的文件并更改

Require the file where your app comes together and change

  def app
    Sinatra::Application
  end

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

然后正确地测试应用程序.

and just test the app proper.

例如,如果您在 config.ru 中定义要测试的中间件,则可以将这些中间件加载到您的应用定义中.

eg, if you define middleware in your config.ru that you want to test, maybe move loading those into your app's definition.

这篇关于将 Cucumber 与模块化 Sinatra 应用程序一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆