How can a gem provide Cucumber features and step definitions?

♀尐吖头ヾ 提交于 2020-01-03 18:33:12

问题


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"

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.

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.

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".


回答1:


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:

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.

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.



来源:https://stackoverflow.com/questions/11675137/how-can-a-gem-provide-cucumber-features-and-step-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!