简体   繁体   English

宝石如何提供Cucumber功能和步骤定义?

[英]How can a gem provide Cucumber features and step definitions?

I have two Rails projects (A and B) with the following gems, among others: 我有两个Rails项目(A和B),其中包括以下宝石:

#project A
gem "green_theme", :path => "~/dev/themes/green_theme"
gem "devel_tasks", :path => "~/dev/themes/devel_tasks"

#project B
gem "red_theme", :path => "~/dev/themes/red_theme"
gem "devel_tasks", :path => "~/dev/themes/devel_tasks"

Both projects, A and B, have a features dir for features and steps. A和B两个项目都具有功能和步骤的功能目录。 Both themes, red and green, should have common functionalities like login/logout buttons, html meta-tags, and so on. 红色和绿色这两个主题应该具有共同的功能,如登录/注销按钮,html元标记等。

What I need to do is place the common theme related features and steps inside the devel_tasks gem. 我需要做的是将常见的主题相关功能和步骤放在devel_tasks gem中。 This way I can share the tests and use them to check whether a given template is compliant with the standard. 这样我就可以共享测试并使用它们来检查给定模板是否符合标准。

A simple way to test what I need to do is create a new Rails project with a sample Cucumber feature, then try to run "cucumber examples/i18n/en/features". 测试我需要做的一个简单方法是使用示例Cucumber功能创建一个新的Rails项目,然后尝试运行“cucumber examples / i18n / en / features”。

If possible I'd extract the common functionality out of the two projects into a gem and test it once there. 如果可能的话,我会将两个项目中的常用功能提取到gem中并在那里进行测试。

If for some reason the two projects really have to separately implement the same functionality: 如果由于某种原因,这两个项目真的必须单独实现相同的功能:

You can provide step definitions in a gem simply by putting them in a file and instructing the user to require that file in their env.rb. 您只需将它们放在一个文件中并指示用户在其env.rb中require该文件,就可以在gem中提供步骤定义。

I don't know of a way to provide features in a gem that can simply be run in place, so you'll have to provide a generator that copies the features to the features directory. 我不知道如何在gem中提供可以简单地运行的功能,因此您必须提供将功能复制到功能目录的生成器。 And if you're going to generate the features it's probably simpler for the user to generate the step definitions too. 如果您要生成功能,则用户生成步骤定义可能更简单。

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

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