简体   繁体   中英

How can a gem provide Cucumber features and step definitions?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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