Skip to content

Commit

Permalink
Warn user when using space-separated string with cucumber_opts (#1624)
Browse files Browse the repository at this point in the history
* Warn user when using space-separated string with cucumber_opts

* Add changelog entry

Signed-off-by: aurelien-reeves <aurelien.reeves@smartbear.com>

* Enabled YodaCondition and ClassEqualityComparison cops, and fix the code
  • Loading branch information
aurelien-reeves committed Apr 13, 2022
1 parent 33870f3 commit 322dda3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ Style/AccessModifierDeclarations:
Style/ClassAndModuleChildren:
Enabled: false

Style/ClassEqualityComparison:
Enabled: true

Style/Documentation:
Enabled: false

Expand All @@ -150,3 +153,6 @@ Style/StderrPuts:
Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

Style/YodaCondition:
Enabled: true
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Added

- Add support for TruffleRuby
([PR#1612](https://github.com/cucumber/cucumber-ruby/pull/1612)
- Add a *WARNING* message when using a space-separated string with cucumber_opts
([PR#](https://github.com/cucumber/cucumber-ruby/pull/1624)
[Issue#1614](https://github.com/cucumber/cucumber-ruby/issues/1614))

- Add support for TruffleRuby
([PR#1612](https://github.com/cucumber/cucumber-ruby/pull/1612)
[gogainda](https://github.com/gogainda))

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/formatter/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def url?(path_or_url_or_io)
end

def ensure_file(path, name)
raise "You *must* specify --out FILE for the #{name} formatter" unless String == path.class
raise "You *must* specify --out FILE for the #{name} formatter" unless path.instance_of? String
raise "I can't write #{name} to a directory - it has to be a file" if File.directory?(path)
raise "I can't write #{name} to a file in the non-existing directory #{File.dirname(path)}" unless File.directory?(File.dirname(path))

ensure_io(path, nil)
end

def ensure_dir(path, name)
raise "You *must* specify --out DIR for the #{name} formatter" unless String == path.class
raise "You *must* specify --out DIR for the #{name} formatter" unless path.instance_of? String
raise "I can't write #{name} reports to a file - it has to be a directory" if File.file?(path)

FileUtils.mkdir_p(path) unless File.directory?(path)
Expand Down
12 changes: 10 additions & 2 deletions lib/cucumber/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InProcessCucumberRunner # :nodoc:
attr_reader :args

def initialize(libs, cucumber_opts, feature_files)
raise 'libs must be an Array when running in-process' unless Array == libs.class
raise 'libs must be an Array when running in-process' unless libs.instance_of? Array

libs.reverse_each { |lib| $LOAD_PATH.unshift(lib) }
@args = (
Expand Down Expand Up @@ -113,7 +113,15 @@ def run
attr_reader :cucumber_opts

def cucumber_opts=(opts) # :nodoc:
@cucumber_opts = String == opts.class ? opts.split(' ') : opts
unless opts.instance_of? String
@cucumber_opts = opts
return
end

@cucumber_opts = opts.split(' ')
return if @cucumber_opts.length <= 1

$stderr.puts 'WARNING: consider using an array rather than a space-delimited string with cucumber_opts to avoid undesired behavior.'
end

# Whether or not to fork a new ruby interpreter. Defaults to true. You may gain
Expand Down
14 changes: 14 additions & 0 deletions spec/cucumber/rake/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,23 @@ module Rake
it { expect(subject.cucumber_opts).to be opts }
end

context 'when set via string' do
let(:opts) { 'foo=bar' }
it { expect(subject.cucumber_opts).to eq %w[foo=bar] }
end

context 'when set via space-delimited string' do
let(:opts) { 'foo bar' }

it { expect(subject.cucumber_opts).to eq %w[foo bar] }

it 'emits a warning to suggest using arrays rather than string' do
expect { subject.cucumber_opts = opts }.to output(
a_string_including(
'WARNING: consider using an array rather than a space-delimited string with cucumber_opts to avoid undesired behavior.'
)
).to_stderr
end
end
end

Expand Down

0 comments on commit 322dda3

Please sign in to comment.