cucumber / cucumber-ruby

Cucumber for Ruby. It's amazing!
https://cucumber.io
MIT License
5.18k stars 1.11k forks source link

packaging and dependencies of features and step_definitions #1404

Closed micheelengronne closed 4 years ago

micheelengronne commented 4 years ago

Summary

I would like to be able to package and reuse features and step definitions. I have multiple projects that have common functionnalities.

Is there a possibility to package groups of features and step definitions and create dependencies between these packages to avoid rewriting everything with every project ?

If we take a look at inspec profiles for instance, we can reuse previous definitions easily.

Expected Behavior

Given a new project When a similar functionnality than another project is tested Then download the features/step_definitions package from the other project and reuse it here

Current Behavior

AFAIK, there is no packaging and dependencies sytem in cucumber.

Context & Motivation

I want to greatly simplify maintaining features, step definitions and scenarios by spliting them in small structures and heavily reuse these structures.

mattwynne commented 4 years ago

You can use the --require switch on the command-line to load step definitions from a Ruby file, which could be in a gem.

See, for example, the aruba gem which bundles step definitions for testing command-line apps.

micheelengronne commented 4 years ago

Thanks. Does it also work with features files ? Is there a possibility to have a meta features file that can load specific features scenarios from a sort of features library (bundled in a gem)?

luke-hill commented 4 years ago

Yes it's worth pointing out that a step file (Written in ruby), is just a series of commands which get loaded into your cucumber runtime and then converted. So if you had a gem for example which had a file which had 2 Given steps, then requiring that gem would allow you to use those common given steps.

Matt linked to some good examples. Here is a bit more detail.

Feature in cucumber-ruby https://github.com/cucumber/cucumber-ruby/blob/master/features/docs/exception_in_after_hook.feature#L26-L35

Consuming this step in aruba https://github.com/cucumber/aruba/blob/master/lib/aruba/cucumber/file.rb#L23-L25

^^^^ This step in aruba is used in 50+ scenarios in cucumber-ruby's acceptance tests. It allows us to dynamically create a step or feature quickly using a docstring.

micheelengronne commented 4 years ago

Right for the steps but for features themselves ? In fact, this issue is related to https://github.com/cucumber/cucumber-ruby/issues/1076 and https://github.com/cucumber/cucumber-ruby/issues/821

micheelengronne commented 4 years ago

Is the suites system implemented ?

mattwynne commented 4 years ago

Suites were not implemented, yet, no. They're still a great idea but we're waiting for them to work their way up the team's priorities.

micheelengronne commented 4 years ago

Ok. This issue describes exactly what I am looking for https://github.com/cucumber/cucumber-ruby/issues/1109

luke-hill commented 4 years ago

Re-running features as described there I'd do in a ruby block, and run the features with whatever additional env vars / params are needed. Something like this pseudo-code

['var1', 'var2', 'var3'].each do |var|
  bundle exec cucumber MYVAR=var
end
micheelengronne commented 4 years ago

Hum... I think I will create a quick gem that download remote cucumber projects in tar.gz, unpack them, merge them and create a new cucumber project with all features together. A bit like Inspec does with profile dependencies.

That way, I can easily call this tar.gz in my project to test.

micheelengronne commented 4 years ago

Question :

luke-hill commented 4 years ago

@micheelengronne do you mean in cucumber-ruby, if so they don't exist, they're created dynamically on the fly.

micheelengronne commented 4 years ago

No, in general. When you created a features folder with cucumber -init, how do you distribute it ? Via git only ? Is there a norm to package it ?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

stale[bot] commented 4 years ago

This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.