gem如何提供黄瓜的特性和步骤定义? [英] How can a gem provide Cucumber features and step definitions?
问题描述
我有两个Rails项目(A和B),其中包括以下gem:
I have two Rails projects (A and B) with the following gems, among others:
#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"
这两个项目都有一个特性dir特征和步骤。
这两个主题,红色和绿色,应该有常见的功能,如
登录/注销按钮,html元标签等。
Both projects, A and B, have a features dir for features and steps. Both themes, red and green, should have common functionalities like login/logout buttons, html meta-tags, and so on.
我需要做的是把相同的主题相关的功能和步骤
在devel_tasks宝石内。这样我可以共享测试和使用
他们来检查一个给定的模板是否符合标准。
What I need to do is place the common theme related features and steps inside the devel_tasks gem. This way I can share the tests and use them to check whether a given template is compliant with the standard.
一个简单的方法来测试我需要什么do是创建一个新的Rails项目
与一个样本Cucumber功能,然后尝试运行黄瓜
examples / i18n / en /功能。
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".
推荐答案
如果可能的话,我会将两个项目中的公共功能提取到一个gem中,然后进行测试。
If possible I'd extract the common functionality out of the two projects into a gem and test it once there.
由于某些原因,两个项目真的必须单独实现相同的功能:
If for some reason the two projects really have to separately implement the same functionality:
您可以通过将一个gem中的步骤定义放在一个文件中,并指示用户 require
该文件在他们的env.rb。
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.
我不知道一种方法提供功能在gem,可以简单地运行到位,因此您必须提供一个生成器将功能复制到features目录。如果你要生成的功能,它可能更简单的用户生成步骤定义太。
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. And if you're going to generate the features it's probably simpler for the user to generate the step definitions too.
这篇关于gem如何提供黄瓜的特性和步骤定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!