Skip to content

Commit e64ca5c

Browse files
committed
Merge pull request #30 from hron/standart_cmd_args
Standardize command line args
2 parents c509f4e + f15bb56 commit e64ca5c

File tree

3 files changed

+50
-202
lines changed

3 files changed

+50
-202
lines changed

README.md

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,57 +53,49 @@ Please read the [Guard documentation](http://github.com/guard/guard#readme) for
5353

5454
## Options
5555

56-
You can pass any of the standard Cucumber CLI options using the :cli option:
56+
You can pass any of the standard Cucumber CLI options using the :cmd_additional_args option:
5757

5858
```ruby
59-
guard 'cucumber', :cli => '-c --drb --port 1234 --profile guard'
59+
guard 'cucumber', :cmd_additional_args => '-c --drb --port 1234 --profile guard'
6060
```
6161

62-
Former `:color`, `:drb`, `:port` and `:profile` options are thus deprecated and have no effect anymore.
62+
Former `:color`, `:drb`, `:port`, `:profile` and `:cli` options are thus deprecated and have no effect anymore.
6363

64-
### List of available options
64+
You can specify custom cucumber command to run using the :cmd option:
6565

6666
```ruby
67-
:cli => '--profile guard -c' # Pass arbitrary Cucumber CLI arguments,
68-
# default: '--no-profile --color --format progress --strict'
67+
guard 'cucumber', :cmd => 'spring cucumber'
68+
```
6969

70-
:feature_sets => # Use non-default feature directory/ies
71-
['set_a', 'set_b'] # default: ['features']
70+
Former `:bundler`, `:bin_stubs`, `:change_format`, `:rvm` and `:command_prefix` options are thus deprecated and have no effect anymore.
7271

73-
:bundler => false # Don't use "bundle exec" to run the Cucumber command
74-
# default: true
7572

76-
:binstubs => true # use "bin/cucumber" to run the Cucumber command (implies :bundler => true)
77-
# default: false
73+
### List of available options
7874

79-
:rvm => ['1.8.7', '1.9.2'] # Directly run your features on multiple ruby versions
80-
# default: nil
75+
```ruby
76+
cmd: 'spring cucumber' # Specify custom cucumber command to run, default: 'cucumber'
77+
cmd_additional_args: # Pass arbitrary Cucumber CLI arguments,
78+
'--profile guard -c' # default: '--no-profile --color --format progress --strict'
8179

82-
:notification => false # Don't display Growl (or Libnotify) notification
80+
feature_sets: # Use non-default feature directory/ies
81+
['set_a', 'set_b'] # default: ['features']
82+
83+
notification: false # Don't display Growl (or Libnotify) notification
8384
# default: true
8485

85-
:all_after_pass => false # Don't run all features after changed features pass
86+
all_after_pass: false # Don't run all features after changed features pass
8687
# default: true
8788

88-
:all_on_start => false # Don't run all the features at startup
89+
all_on_start: false # Don't run all the features at startup
8990
# default: true
9091

91-
:keep_failed => false # Keep failed features until they pass
92+
keep_failed: false # Keep failed features until they pass
9293
# default: true
9394

94-
:run_all => { :cli => "-p" } # Override any option when running all specs
95+
run_all: {cmd: "-p"} # Override any option when running all specs
9596
# default: {}
9697

97-
:change_format => 'pretty' # Use a different cucumber format when running individual features
98-
# This replaces the Cucumber --format option within the :cli option
99-
# default: nil
100-
101-
:command_prefix => 'xvfb-run' # Add a prefix to the cucumber command such as 'xvfb-run' or any
102-
# other shell script.
103-
# The example generates: 'xvfb-run bundle exec cucumber ...'
104-
# default: nil
105-
106-
:focus_on => 'dev' # Focus on scenarios tagged with '@dev'
98+
focus_on: 'dev' # Focus on scenarios tagged with '@dev'
10799
# If '@dev' is on line 6 in 'foo.feature',
108100
# this example runs: 'bundle exec cucumber foo.feature:6'
109101
# default: nil
@@ -125,14 +117,14 @@ then the default profile forces guard-cucumber to always run all features, becau
125117

126118
If you want to configure Cucumber from Guard solely, then you should pass `--no-profile` to the `:cli` option.
127119

128-
Since guard-cucumber version 0.3.2, the default `:cli` options are:
120+
Since guard-cucumber version 0.3.2, the default `:cmd_additional_args` options are:
129121

130122
```ruby
131-
:cli => '--no-profile --color --format progress --strict'
123+
cmd_additional_args: '--no-profile --color --format progress --strict'
132124
```
133125

134126
This default configuration has been chosen to avoid strange behavior when mixing configurations from
135-
the cucumber.yml default profile with the guard-cucumber `:cli` option.
127+
the cucumber.yml default profile with the guard-cucumber `:cmd_additional_args` option.
136128

137129
You can safely remove `config/cucumber.yml`, since all configuration is done in the `Guardfile`.
138130

@@ -161,7 +153,7 @@ guard 'spork' do
161153
watch('spec/spec_helper.rb')
162154
end
163155
164-
guard 'cucumber', :cli => '--drb --format progress --no-profile' do
156+
guard 'cucumber', :cmd_additional_args => '--drb --format progress --no-profile' do
165157
watch(%r{^features/.+\.feature$})
166158
watch(%r{^features/support/.+$}) { 'features' }
167159
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
@@ -174,23 +166,24 @@ There is a section with alternative configurations on the [Wiki](https://github.
174166

175167
To use Guard::Cucumber with [Zeus](https://github.com/burke/zeus), just set the command prefix:
176168
```
177-
guard 'cucumber', :command_prefix => 'zeus', :bundler => false do
169+
guard 'cucumber', :cmd => 'zeus cucumber' do
178170
...
179171
end
180172
```
181173

182-
You need to set `:bundler => false` to avoid using Bundler, as recommended in the Zeus documenation.
174+
Don't use `cmd: 'bundle exec zeus cucumber'` because Zeus recommends to avoid a bundler call.
183175
184176
## Cucumber with Spring
185177
186178
To use Guard::Cucumber with [Spring](https://github.com/jonleighton/spring), just set the command prefix:
187179
```
188-
guard 'cucumber', :command_prefix => 'spring', :bundler => false do
180+
guard 'cucumber', :cmd => 'spring cucumber' do
189181
...
190182
end
191183
```
192184

193-
You need to set `:bundler => false` to avoid using Bundler, as recommended in the Spring documenation.
185+
Don't use `cmd: 'bundle exec zeus cucumber'` because Spring recommends to avoid a bundler call.
186+
194187

195188
Issues
196189
------

lib/guard/cucumber/runner.rb

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,12 @@ def run(paths, options = {})
5959
#
6060
def cucumber_command(paths, options)
6161
cmd = []
62-
_add_cmd_prefix(cmd, options[:command_prefix])
63-
_add_rvm_options(cmd, options[:rvm])
64-
_add_bundler_options(cmd, options[:bundler])
65-
cmd << cucumber_exec(options)
66-
_add_cli_options(cmd, options[:cli])
62+
_add_cli_options(cmd, options[:cmd] || "cucumber")
6763
_add_notification(cmd, options)
68-
64+
_add_cli_options(cmd, options[:cmd_additional_args])
6965
(cmd + paths).join(" ")
7066
end
7167

72-
# Simple test if binstubs prefix should be used.
73-
#
74-
# @return [String] Cucumber executable
75-
#
76-
def cucumber_exec(options = {})
77-
options[:binstubs] == true ? "bin/cucumber" : "cucumber"
78-
end
79-
80-
# Simple test if bundler should be used. it just checks for the
81-
# `Gemfile`.
82-
#
83-
# @return [Boolean] bundler exists
84-
#
85-
def bundler?
86-
@bundler ||= File.exist?("#{ Dir.pwd }/Gemfile")
87-
end
88-
8968
# Returns a null device for all OS.
9069
#
9170
# @return [String] the name of the null device
@@ -111,22 +90,9 @@ def _add_notification(cmd, options)
11190
end.join(" ")
11291
end
11392

114-
def _add_rvm_options(cmd, rvm_args)
115-
return unless rvm_args.is_a?(Array)
116-
cmd << "rvm #{ rvm_args.join(',') } exec"
117-
end
118-
119-
def _add_bundler_options(cmd, bundler)
120-
cmd << "bundle exec" if bundler? && bundler != false
121-
end
122-
12393
def _add_cli_options(cmd, cli)
12494
cmd << cli if cli
12595
end
126-
127-
def _add_cmd_prefix(cmd, prefix)
128-
cmd << prefix if prefix
129-
end
13096
end
13197
end
13298
end

spec/guard/cucumber/runner_spec.rb

Lines changed: 18 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,18 @@
3636
end
3737
end
3838

39-
context "with a :rvm option" do
40-
it "executes cucumber through the rvm versions" do
41-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
42-
expect(runner).to receive(:system).with(
43-
"rvm 1.8.7,1.9.2 exec bundle exec cucumber"\
44-
" --require #{ req }"\
45-
" --format Guard::Cucumber::NotificationFormatter"\
46-
" --out #{ null_device }"\
47-
" --require features features"
48-
)
49-
runner.run(["features"], rvm: ["1.8.7", "1.9.2"])
50-
end
51-
end
52-
53-
context "with a :command_prefix option" do
54-
it "executes cucumber with the command_prefix option" do
55-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
56-
expect(runner).to receive(:system).with(
57-
"xvfb-run bundle exec cucumber "\
58-
"--require #{ req } "\
59-
"--format Guard::Cucumber::NotificationFormatter "\
60-
"--out #{ null_device } "\
61-
"--require features features"
62-
)
63-
runner.run(["features"], command_prefix: "xvfb-run")
64-
end
39+
it "runs cucumber according to passed cmd option" do
40+
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
41+
expect(runner).to receive(:system).with(
42+
"xvfb-run bundle exec cucumber "\
43+
"--require #{ req } "\
44+
"--format Guard::Cucumber::NotificationFormatter "\
45+
"--out #{ null_device } "\
46+
"--require features features"
47+
)
48+
runner.run(["features"], cmd: "xvfb-run bundle exec cucumber")
6549
end
66-
67-
context "with a :bundler option" do
68-
it "runs without bundler when false" do
69-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
70-
expect(runner).to receive(:system).with(
71-
"cucumber"\
72-
" --require #{ req }"\
73-
" --format Guard::Cucumber::NotificationFormatter"\
74-
" --out #{ null_device }"\
75-
" --require features features"
76-
)
77-
runner.run(["features"], bundler: false)
78-
end
79-
end
80-
50+
8151
context "with a :focus_on option" do
8252
it "passes the value in :focus_on to the Focuser" do
8353
paths = ["features"]
@@ -93,104 +63,23 @@
9363
end
9464
end
9565

96-
describe ":binstubs" do
97-
it "runs without Bundler with binstubs option to true and "\
98-
"bundler option to false" do
99-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
100-
expect(subject).to receive(:system).with(
101-
"bin/cucumber"\
102-
" --require #{ req }"\
103-
" --format Guard::Cucumber::NotificationFormatter"\
104-
" --out #{ null_device }"\
105-
" --require features features"
106-
).and_return(true)
107-
subject.run(["features"], bundler: false, binstubs: true)
108-
end
109-
110-
it "runs with Bundler and binstubs with bundler option to true "\
111-
"and binstubs option to true" do
112-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
113-
expect(subject).to receive(:system).with(
114-
"bundle exec bin/cucumber"\
115-
" --require #{ req }"\
116-
" --format Guard::Cucumber::NotificationFormatter"\
117-
" --out #{ null_device }"\
118-
" --require features features"
119-
).and_return(true)
120-
subject.run(["features"], bundler: true, binstubs: true)
121-
end
122-
123-
it "runs with Bundler and binstubs with bundler option unset "\
124-
"and binstubs option to true" do
125-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
126-
expect(subject).to receive(:system).with(
127-
"bundle exec bin/cucumber"\
128-
" --require #{ req } "\
129-
"--format Guard::Cucumber::NotificationFormatter "\
130-
"--out #{ null_device }"\
131-
" --require features features"
132-
).and_return(true)
133-
subject.run(["features"], binstubs: true)
134-
end
135-
136-
it "runs with Bundler and binstubs with bundler option unset, "\
137-
"binstubs option to true and all_after_pass option to true" do
138-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
139-
expect(subject).to receive(:system).with(
140-
"bundle exec bin/cucumber"\
141-
" --require #{ req } "\
142-
"--format Guard::Cucumber::NotificationFormatter"\
143-
" --out #{ null_device }"\
144-
" --require features features"
145-
).and_return(true)
146-
subject.run(["features"], binstubs: true, all_after_pass: true)
147-
end
148-
149-
it "runs with Bundler and binstubs with bundler option unset, "\
150-
"binstubs option to true and all_on_start option to true" do
151-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
152-
expect(subject).to receive(:system).with(
153-
"bundle exec bin/cucumber --require #{ req } "\
154-
"--format Guard::Cucumber::NotificationFormatter "\
155-
"--out #{ null_device } --require features features"
156-
).and_return(true)
157-
subject.run(["features"], binstubs: true, all_on_start: true)
158-
end
159-
160-
it "runs with Bundler and binstubs with bundler option unset, "\
161-
"binstubs option to true, all_on_start option to true and "\
162-
"all_after_pass option to true" do
163-
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
164-
165-
expect(subject).to receive(:system).with(
166-
"bundle exec bin/cucumber --require #{ req } "\
167-
"--format Guard::Cucumber::NotificationFormatter "\
168-
"--out #{ null_device } --require features features"
169-
).and_return(true)
170-
171-
subject.run(
172-
["features"],
173-
binstubs: true,
174-
all_after_pass: true,
175-
all_on_start: true)
176-
end
177-
end
178-
179-
context "with a :cli option" do
66+
context "with a :cmd_additional_args option" do
18067
it "appends the cli arguments when calling cucumber" do
18168
req = @lib_path.join("guard/cucumber/notification_formatter.rb")
18269
expect(runner).to receive(:system).with(
183-
"bundle exec cucumber --custom command --require #{req} "\
70+
"cucumber --require #{req} "\
18471
"--format Guard::Cucumber::NotificationFormatter "\
185-
"--out #{ null_device } --require features features")
186-
runner.run(["features"], cli: "--custom command")
72+
"--out #{ null_device } --require features "\
73+
"--custom command "\
74+
"features")
75+
runner.run(["features"], cmd_additional_args: "--custom command")
18776
end
18877
end
18978

19079
context "with a :notification option" do
19180
it "does not add the guard notification listener" do
19281
expect(runner).to receive(:system).with(
193-
"bundle exec cucumber features"
82+
"cucumber features"
19483
)
19584
runner.run(["features"], notification: false)
19685
end

0 commit comments

Comments
 (0)