Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn user when using space-separated string with cucumber_opts #1624

Merged
merged 3 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
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.'
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
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