简体   繁体   English

如何使用虚拟应用程序测试gem(最好使用Cucumber)?

[英]How do I use a dummy application to test a gem (preferably with Cucumber)?

I'm making a gem that will add some custom responders to an application's controllers. 我正在制作一个宝石,它将在应用程序的控制器中添加一些自定义响应器。 To test this, I'm going to need a dummy application sitting inside of a test directory that I can load and somehow generate views from. 为了测试这一点,我将需要一个虚拟应用程序,该应用程序位于可以加载并以某种方式生成视图的测试目录中。

I'd prefer to use Cucumber to test this gem, because that is what I'm most comfortable with having used it in the past. 我更喜欢使用Cucumber来测试该宝石,因为这是我过去最习惯使用的。

How do I generate an application inside of my test directory like this? 我如何像这样在测试目录中生成应用程序? I will need at least a controller and a model, but views aren't necessary (the responder is only for JSON). 我将至少需要一个控制器和一个模型,但是视图不是必需的(响应器仅用于JSON)。 Can I just generate a new Rails app within /features/support/dummy ? 我可以在/features/support/dummy内生成一个新的Rails应用程序吗? How would I run the dummy application from within my test suite? 如何在测试套件中运行虚拟应用程序?

At first, do not generate anything within features/support/ . 首先,不要在features/support/生成任何东西。 That's the place for global hooks. 那是全局钩子的地方。

Your problem sounds not hard if I understood correctly. 如果我理解正确,您的问题听起来并不难。 Here is my proposed steps. 这是我建议的步骤。

  1. Create a demo directory in project root. 在项目根目录中创建一个demo目录。 New demo app will be under it. 新的演示应用程序将在其下。

  2. Create a ruby module/class under features/support/ , with methods to generate a demo app and delete it. features/support/下创建一个ruby模块/类,并带有生成演示应用程序并将其删除的方法。 The demo app will be simply some directories like app/contorllers for test purpose. 演示应用程序只是用于测试目的的一些目录,例如app/contorllers Making a whole new Rails app sounds overkill. 制作一个全新的Rails应用听起来有些过分。

  3. Create a tag for the Scenario which need generate app. 为需要生成应用的场景创建标签。 Add Before and After hook for this tag to add and remove app for this Scenario, by calling the module/class in #2 添加BeforeAfter挂钩,此标签添加并为此方案中删除的应用程序,通过调用模块/类#2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM