diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 90f7be8d01..2226344d32 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,10 +19,12 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - ruby: ['3.0', '3.1', '3.2', '3.3'] + ruby: ['3.0', '3.1', '3.2', '3.3', '3.4'] include: - os: ubuntu-latest ruby: jruby-9.4 + - os: ubuntu-latest + ruby: truffleruby-24 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 51c25fd788..f5545bede9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -22,7 +22,7 @@ jobs: - os: ubuntu-latest ruby: jruby-9.4 - os: ubuntu-latest - ruby: truffleruby-head + ruby: truffleruby-24 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/.rubocop.yml b/.rubocop.yml index a1d842ed08..f91dfd78f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,6 @@ inherit_mode: - Exclude require: - - rubocop-capybara - rubocop-packaging - rubocop-rake - rubocop-rspec diff --git a/CHANGELOG.md b/CHANGELOG.md index 810eae6b5f..758376a70e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,7 +70,7 @@ All logic contained in [compatibility](./compatibility) ([luke-hill](https://git ## [9.1.0] - 2023-11-14 ### Changed -- First couple of passes of tidying up approximately 40% of the manual fix cops +- First iteration to tidy up approximately 40% of the manual fix cops ([#1739](https://github.com/cucumber/cucumber-ruby/pull/1739) [#1740](https://github.com/cucumber/cucumber-ruby/pull/1740) [#1741](https://github.com/cucumber/cucumber-ruby/pull/1741) [#1742](https://github.com/cucumber/cucumber-ruby/pull/1742) [luke-hill](https://github.com/luke-hill)) - Removed a bunch of example files / sample projects from ancient projects no longer viable ([#1740](https://github.com/cucumber/cucumber-ruby/pull/1740) [luke-hill](https://github.com/luke-hill)) diff --git a/README.md b/README.md index 1833af09f7..605ae8d907 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,11 @@ Later in this document, bundler is considered being used so all commands are usi ### Supported platforms +- Ruby 3.4 +- Ruby 3.3 - Ruby 3.2 - Ruby 3.1 - Ruby 3.0 -- Ruby 2.7 - TruffleRuby 22.0.0+ - JRuby 9.4+ (with [some limitations](https://github.com/cucumber/cucumber-ruby/blob/main/docs/jruby-limitations.md)) @@ -91,12 +92,11 @@ Feature: Rule Sample Given this will fail When I do an action Then some results should be there - ``` ### Automate your specification -And a file named `steps.rb` in `features/step_definitions` with: +And a file named `rule_steps.rb` in `features/step_definitions` with: ```ruby # features/step_definitions/steps.rb @@ -149,4 +149,4 @@ You can also find documentation on the command line possibilities in [features/d ## Copyright -Copyright (c) Cucumber Ltd. and Contributors. See LICENSE for details. +Copyright (c) Cucumber and Contributors. See LICENSE for details. diff --git a/RELEASING.md b/RELEASING.md index 3a1ef9a25e..71e0bb8772 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,11 +1 @@ See [.github/RELEASING](https://github.com/cucumber/.github/blob/main/RELEASING.md). - -## When done ## - -Update the cucumber-ruby version in the documentation project: - -* https://github.com/cucumber/docs.cucumber.io - -The cucumber-ruby version for the docs is specified in the docs [versions.yaml](https://github.com/cucumber/docs.cucumber.io/blob/master/data/versions.yaml) - -All done! Hurray! diff --git a/compatibility/features/attachments/attachments_steps.rb b/compatibility/features/attachments/attachments_steps.rb index 984b44f2d2..b7a8025ed9 100644 --- a/compatibility/features/attachments/attachments_steps.rb +++ b/compatibility/features/attachments/attachments_steps.rb @@ -25,16 +25,18 @@ def cck_asset_path attach(data, media_type) end +# To be removed in CCK v19 alongside removing duplicate scenarios: https://github.com/cucumber/compatibility-kit/pull/127 When('a JPEG image is attached') do attach(File.open("#{cck_asset_path}/cucumber.jpeg"), 'image/jpeg') end +# To be removed in CCK v19 alongside removing duplicate scenarios: https://github.com/cucumber/compatibility-kit/pull/127 When('a PNG image is attached') do attach(File.open("#{cck_asset_path}/cucumber.png"), 'image/png') end When('a PDF document is attached and renamed') do - attach(File.open("#{cck_asset_path}/document.pdf"), 'document/pdf', 'renamed.pdf') + attach(File.open("#{cck_asset_path}/document.pdf"), 'application/pdf', 'renamed.pdf') end When('a link to {string} is attached') do |link| diff --git a/compatibility/features/examples-tables-attachment/examples-tables-attachment_steps.rb b/compatibility/features/examples-tables-attachment/examples-tables-attachment_steps.rb new file mode 100644 index 0000000000..274397a013 --- /dev/null +++ b/compatibility/features/examples-tables-attachment/examples-tables-attachment_steps.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +def cck_asset_path + "#{Gem.loaded_specs['cucumber-compatibility-kit'].full_gem_path}/features/examples-tables-attachment" +end + +When('a JPEG image is attached') do + attach(File.open("#{cck_asset_path}/cucumber.jpeg"), 'image/jpeg') +end + +When('a PNG image is attached') do + attach(File.open("#{cck_asset_path}/cucumber.png"), 'image/png') +end diff --git a/compatibility/features/hooks-attachment/hooks-attachment_steps.rb b/compatibility/features/hooks-attachment/hooks-attachment_steps.rb new file mode 100644 index 0000000000..7e5361e0cd --- /dev/null +++ b/compatibility/features/hooks-attachment/hooks-attachment_steps.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +def cck_asset_path + "#{Gem.loaded_specs['cucumber-compatibility-kit'].full_gem_path}/features/hooks-attachment" +end + +Before do + attach(File.open("#{cck_asset_path}/cucumber.svg"), 'image/svg+xml') +end + +After do + attach(File.open("#{cck_asset_path}/cucumber.svg"), 'image/svg+xml') +end + +When('a step passes') do + # no-op +end diff --git a/compatibility/features/hooks-conditional/hooks-conditional_steps.rb b/compatibility/features/hooks-conditional/hooks-conditional_steps.rb new file mode 100644 index 0000000000..ab1dbf00d6 --- /dev/null +++ b/compatibility/features/hooks-conditional/hooks-conditional_steps.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +Before('@passing-hook') do + # no-op +end + +Before('@fail-before') do + raise 'Exception in conditional hook' +end + +When('a step passes') do + # no-op +end + +After('@passing-hook') do + # no-op +end + +After('@fail-after') do + raise 'Exception in conditional hook' +end diff --git a/compatibility/features/hooks-named/hooks-named_steps.rb b/compatibility/features/hooks-named/hooks-named_steps.rb new file mode 100644 index 0000000000..b5971799c7 --- /dev/null +++ b/compatibility/features/hooks-named/hooks-named_steps.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +Before(name: 'A named before hook') do + # no-op +end + +When('a step passes') do + # no-op +end + +After(name: 'A named after hook') do + # no-op +end diff --git a/compatibility/features/hooks/hooks_steps.rb b/compatibility/features/hooks/hooks_steps.rb index 2eb59a0eac..fa26531e9b 100644 --- a/compatibility/features/hooks/hooks_steps.rb +++ b/compatibility/features/hooks/hooks_steps.rb @@ -4,14 +4,6 @@ # no-op end -Before(name: 'A named hook') do - # no-op -end - -def cck_asset_path - "#{Gem.loaded_specs['cucumber-compatibility-kit'].full_gem_path}/features/hooks" -end - When('a step passes') do # no-op end @@ -23,11 +15,3 @@ def cck_asset_path After do # no-op end - -After('@some-tag or @some-other-tag') do - raise 'Exception in conditional hook' -end - -After('@with-attachment') do - attach(File.open("#{cck_asset_path}/cucumber.svg"), 'image/svg+xml') -end diff --git a/cucumber.gemspec b/cucumber.gemspec index c33d1b8567..5990302ad8 100644 --- a/cucumber.gemspec +++ b/cucumber.gemspec @@ -26,8 +26,8 @@ Gem::Specification.new do |s| s.add_dependency 'base64', '~> 0.2' s.add_dependency 'builder', '~> 3.2' s.add_dependency 'cucumber-ci-environment', '> 9', '< 11' - s.add_dependency 'cucumber-core', '~> 15.0' - s.add_dependency 'cucumber-cucumber-expressions', '~> 17.0' + s.add_dependency 'cucumber-core', '> 15', '< 17' + s.add_dependency 'cucumber-cucumber-expressions', '> 17', '< 19' s.add_dependency 'cucumber-html-formatter', '> 20.3', '< 22' s.add_dependency 'diff-lcs', '~> 1.5' s.add_dependency 'logger', '~> 1.6' @@ -35,16 +35,15 @@ Gem::Specification.new do |s| s.add_dependency 'multi_test', '~> 1.1' s.add_dependency 'sys-uname', '~> 1.3' - s.add_development_dependency 'cucumber-compatibility-kit', '~> 16.2' + s.add_development_dependency 'cucumber-compatibility-kit', '~> 18.0' # Only needed whilst we are testing the formatters. Can be removed once we remove tests for those s.add_development_dependency 'nokogiri', '~> 1.15' s.add_development_dependency 'rake', '~> 13.2' s.add_development_dependency 'rspec', '~> 3.13' - s.add_development_dependency 'rubocop', '~> 1.69.2' - s.add_development_dependency 'rubocop-capybara', '~> 2.21.0' + s.add_development_dependency 'rubocop', '~> 1.71.0' s.add_development_dependency 'rubocop-packaging', '~> 0.5.2' s.add_development_dependency 'rubocop-rake', '~> 0.6.0' - s.add_development_dependency 'rubocop-rspec', '~> 3.3.0' + s.add_development_dependency 'rubocop-rspec', '~> 3.4.0' s.add_development_dependency 'simplecov', '~> 0.22.0' s.add_development_dependency 'webrick', '~> 1.8' diff --git a/lib/cucumber/cli/main.rb b/lib/cucumber/cli/main.rb index 42ffa6bfba..a550ac9846 100644 --- a/lib/cucumber/cli/main.rb +++ b/lib/cucumber/cli/main.rb @@ -93,8 +93,7 @@ def trap_interrupt def runtime(existing_runtime) return Runtime.new(configuration) unless existing_runtime - existing_runtime.configure(configuration) - existing_runtime + existing_runtime.tap { |runtime| runtime.configure(configuration) } end end end diff --git a/lib/cucumber/deprecate.rb b/lib/cucumber/deprecate.rb index e0bc75177d..b8d1217dd2 100644 --- a/lib/cucumber/deprecate.rb +++ b/lib/cucumber/deprecate.rb @@ -6,7 +6,7 @@ module Cucumber def self.deprecate(message, method, remove_after_version) $stderr.puts( - "\nWARNING: ##{method} is deprecated" \ + "\nWARNING: #{method} is deprecated" \ " and will be removed after version #{remove_after_version}. #{message}.\n" \ "(Called from #{caller(3..3).first})" ) diff --git a/lib/cucumber/filters/broadcast_test_case_ready_event.rb b/lib/cucumber/filters/broadcast_test_case_ready_event.rb index 15675803a2..378a83e5da 100644 --- a/lib/cucumber/filters/broadcast_test_case_ready_event.rb +++ b/lib/cucumber/filters/broadcast_test_case_ready_event.rb @@ -4,7 +4,7 @@ module Cucumber module Filters class BroadcastTestCaseReadyEvent < Core::Filter.new(:config) def test_case(test_case) - config.notify :test_case_ready, test_case + config.notify(:test_case_ready, test_case) test_case.describe_to(receiver) end end diff --git a/lib/cucumber/formatter/backtrace_filter.rb b/lib/cucumber/formatter/backtrace_filter.rb index d35d2b014e..3558cb0506 100644 --- a/lib/cucumber/formatter/backtrace_filter.rb +++ b/lib/cucumber/formatter/backtrace_filter.rb @@ -34,7 +34,6 @@ def initialize(exception) def exception return @exception if ::Cucumber.use_full_backtrace - pwd_pattern = /#{::Regexp.escape(::Dir.pwd)}\//m backtrace = @exception.backtrace.map { |line| line.gsub(pwd_pattern, './') } filtered = (backtrace || []).reject do |line| @@ -42,16 +41,36 @@ def exception end if ::ENV['CUCUMBER_TRUNCATE_OUTPUT'] - # Strip off file locations - regexp = RUBY_VERSION >= '3.4' ? /(.*):in '/ : /(.*):in `/ filtered = filtered.map do |line| - match = regexp.match(line) + # Strip off file locations + match = regexp_filter.match(line) match ? match[1] : line end end - @exception.set_backtrace(filtered) - @exception + @exception.tap { |e| e.set_backtrace(filtered) } + end + + private + + def pwd_pattern + /#{::Regexp.escape(::Dir.pwd)}\//m + end + + def regexp_filter + ruby_greater_than_three_four? ? three_four_filter : three_three_filter + end + + def ruby_greater_than_three_four? + RUBY_VERSION.to_f >= 3.4 + end + + def three_four_filter + /(.*):in '/ + end + + def three_three_filter + /(.*):in `/ end end end diff --git a/lib/cucumber/formatter/message_builder.rb b/lib/cucumber/formatter/message_builder.rb index 6f7fb0bc54..42caa087fa 100644 --- a/lib/cucumber/formatter/message_builder.rb +++ b/lib/cucumber/formatter/message_builder.rb @@ -7,6 +7,7 @@ require 'cucumber/formatter/query/pickle_step_by_test_step' require 'cucumber/formatter/query/step_definitions_by_test_step' require 'cucumber/formatter/query/test_case_started_by_test_case' +require 'cucumber/formatter/query/test_run_started' module Cucumber module Formatter @@ -21,6 +22,7 @@ def initialize(config) @pickle_step_by_test_step = Query::PickleStepByTestStep.new(config) @step_definitions_by_test_step = Query::StepDefinitionsByTestStep.new(config) @test_case_started_by_test_case = Query::TestCaseStartedByTestCase.new(config) + @test_run_started = Query::TestRunStarted.new(config) config.on_event :envelope, &method(:on_envelope) config.on_event :gherkin_source_read, &method(:on_gherkin_source_read) @@ -34,6 +36,7 @@ def initialize(config) config.on_event :undefined_parameter_type, &method(:on_undefined_parameter_type) @test_case_by_step_id = {} + @current_test_run_started_id = nil @current_test_case_started_id = nil @current_test_step_id = nil end @@ -94,7 +97,8 @@ def on_test_case_ready(event) test_case: Cucumber::Messages::TestCase.new( id: event.test_case.id, pickle_id: @pickle_by_test.pickle_id(event.test_case), - test_steps: event.test_case.test_steps.map { |step| test_step_to_message(step) } + test_steps: event.test_case.test_steps.map { |step| test_step_to_message(step) }, + test_run_started_id: @current_test_run_started_id ) ) @@ -150,9 +154,12 @@ def parameter_type_name(step_match_argument) end def on_test_run_started(*) + @current_test_run_started_id = @test_run_started.id + message = Cucumber::Messages::Envelope.new( test_run_started: Cucumber::Messages::TestRunStarted.new( - timestamp: time_to_timestamp(Time.now) + timestamp: time_to_timestamp(Time.now), + id: @current_test_run_started_id ) ) @@ -245,7 +252,8 @@ def on_test_run_finished(event) message = Cucumber::Messages::Envelope.new( test_run_finished: Cucumber::Messages::TestRunFinished.new( timestamp: time_to_timestamp(Time.now), - success: event.success + success: event.success, + test_run_started_id: @current_test_run_started_id ) ) diff --git a/lib/cucumber/formatter/query/test_run_started.rb b/lib/cucumber/formatter/query/test_run_started.rb new file mode 100644 index 0000000000..be3e4c6f03 --- /dev/null +++ b/lib/cucumber/formatter/query/test_run_started.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Cucumber + module Formatter + module Query + class TestRunStarted + def initialize(config) + @config = config + end + + def id + @id ||= @config.id_generator.new_id + end + end + end + end +end diff --git a/lib/cucumber/glue/dsl.rb b/lib/cucumber/glue/dsl.rb index 5c6d620630..b713cbd42b 100644 --- a/lib/cucumber/glue/dsl.rb +++ b/lib/cucumber/glue/dsl.rb @@ -18,8 +18,8 @@ def build_rb_world_factory(world_modules, namespaced_world_modules, proc) @rb_language.build_rb_world_factory(world_modules, namespaced_world_modules, proc) end - def register_rb_hook(phase, tag_names, proc, name: nil) - @rb_language.register_rb_hook(phase, tag_names, proc, name: name) + def register_rb_hook(type, tag_names, proc, name: nil) + @rb_language.register_rb_hook(type, tag_names, proc, name: name) end def define_parameter_type(parameter_type) diff --git a/lib/cucumber/glue/hook.rb b/lib/cucumber/glue/hook.rb index d1a1694c3c..bdbe4114d0 100644 --- a/lib/cucumber/glue/hook.rb +++ b/lib/cucumber/glue/hook.rb @@ -28,12 +28,13 @@ def invoke(pseudo_method, arguments, &block) ) end - def to_envelope + def to_envelope(type) Cucumber::Messages::Envelope.new( hook: Cucumber::Messages::Hook.new( id: id, name: name, tag_expression: tag_expressions.empty? ? nil : tag_expressions.join(' '), + type: hook_type_to_enum_value[type.to_sym], source_reference: Cucumber::Messages::SourceReference.new( uri: location.file, location: Cucumber::Messages::Location.new( @@ -43,6 +44,20 @@ def to_envelope ) ) end + + private + + def hook_type_to_enum_value + { + before: 'BEFORE_TEST_CASE', + after: 'AFTER_TEST_CASE', + around: nil, # This needs deleting and removing from cucumber-ruby in v11 + after_step: 'AFTER_TEST_STEP', + install_plugin: 'BEFORE_TEST_RUN', + before_all: 'BEFORE_TEST_RUN', + after_all: 'AFTER_TEST_RUN' + } + end end end end diff --git a/lib/cucumber/glue/registry_and_more.rb b/lib/cucumber/glue/registry_and_more.rb index 5af26d17e5..349977a596 100644 --- a/lib/cucumber/glue/registry_and_more.rb +++ b/lib/cucumber/glue/registry_and_more.rb @@ -85,9 +85,9 @@ def step_matches(name_to_match) end end - def register_rb_hook(phase, tag_expressions, proc, name: nil) - hook = add_hook(phase, Hook.new(@configuration.id_generator.new_id, self, tag_expressions, proc, name: name)) - @configuration.notify :envelope, hook.to_envelope + def register_rb_hook(type, tag_expressions, proc, name: nil) + hook = add_hook(type, Hook.new(@configuration.id_generator.new_id, self, tag_expressions, proc, name: name)) + @configuration.notify(:envelope, hook.to_envelope(type)) hook end @@ -166,8 +166,8 @@ def after_all end end - def add_hook(phase, hook) - hooks[phase.to_sym] << hook + def add_hook(type, hook) + hooks[type.to_sym] << hook hook end @@ -175,8 +175,8 @@ def clear_hooks @hooks = nil end - def hooks_for(phase, scenario) # :nodoc: - hooks[phase.to_sym].select { |hook| scenario.accept_hook?(hook) } + def hooks_for(type, scenario) # :nodoc: + hooks[type.to_sym].select { |hook| scenario.accept_hook?(hook) } end def create_expression(string_or_regexp) diff --git a/lib/cucumber/runtime.rb b/lib/cucumber/runtime.rb index 80bd2e9568..4575bae85c 100644 --- a/lib/cucumber/runtime.rb +++ b/lib/cucumber/runtime.rb @@ -255,13 +255,13 @@ def filters filters << Filters::ApplyBeforeHooks.new(@support_code) filters << Filters::ApplyAfterHooks.new(@support_code) filters << Filters::ApplyAroundHooks.new(@support_code) + filters << Filters::BroadcastTestRunStartedEvent.new(@configuration) + filters << Filters::Quit.new end filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration) unless configuration.dry_run? - filters << Filters::BroadcastTestRunStartedEvent.new(@configuration) - filters << Filters::Quit.new filters << Filters::Retry.new(@configuration) # need to do this last so it becomes the first test step filters << Filters::PrepareWorld.new(self) diff --git a/spec/cucumber/deprecate_spec.rb b/spec/cucumber/deprecate_spec.rb index a71600a160..3796c11827 100644 --- a/spec/cucumber/deprecate_spec.rb +++ b/spec/cucumber/deprecate_spec.rb @@ -7,10 +7,10 @@ module Cucumber it 'outputs a message to $stderr' do allow($stderr).to receive(:puts) - Cucumber.deprecate('Use some_method instead', 'someMethod', '1.0.0') + Cucumber.deprecate('Use #some_other_method instead', '#some_method', '1.0.0') expect($stderr).to have_received(:puts).with( a_string_including( - 'WARNING: #someMethod is deprecated and will be removed after version 1.0.0. Use some_method instead.' + 'WARNING: #some_method is deprecated and will be removed after version 1.0.0. Use #some_other_method instead.' ) ) end diff --git a/spec/cucumber/formatter/interceptor_spec.rb b/spec/cucumber/formatter/interceptor_spec.rb index 3ca81405bc..6d27044ea2 100644 --- a/spec/cucumber/formatter/interceptor_spec.rb +++ b/spec/cucumber/formatter/interceptor_spec.rb @@ -12,13 +12,8 @@ end context 'when passed :stderr' do - before :each do - @stderr = $stderr - end - - after :each do - $stderr = @stderr - end + before { @stderr = $stderr } + after { $stderr = @stderr } it 'wraps $stderr' do wrapped = described_class.wrap(:stderr) @@ -29,13 +24,8 @@ end context 'when passed :stdout' do - before :each do - @stdout = $stdout - end - - after :each do - $stdout = @stdout - end + before { @stdout = $stdout } + after { $stdout = @stdout } it 'wraps $stdout' do wrapped = described_class.wrap(:stdout) @@ -82,11 +72,35 @@ it 'disables the pipe bypass' do buffer = '(::)' - described_class.unwrap! :stdout + described_class.unwrap!(:stdout) @wrapped.write(buffer) expect(@wrapped.buffer_string).not_to end_with(buffer) end + + it 'wraps $stderr' do + wrapped = described_class.wrap(:stderr) + + expect($stderr).to be_instance_of described_class + expect($stderr).to be wrapped + end + + context 'when passed :stdout' do + before :each do + @stdout = $stdout + end + + after :each do + $stdout = @stdout + end + + it 'wraps $stdout' do + wrapped = described_class.wrap(:stdout) + + expect($stdout).to be_instance_of described_class + expect($stdout).to be wrapped + end + end end describe '#write' do diff --git a/spec/cucumber/formatter/spec_helper.rb b/spec/cucumber/formatter/spec_helper.rb index 7797fab012..85b7ad34b5 100644 --- a/spec/cucumber/formatter/spec_helper.rb +++ b/spec/cucumber/formatter/spec_helper.rb @@ -42,8 +42,8 @@ def filters Filters::ApplyBeforeHooks.new(actual_runtime.support_code), Filters::ApplyAfterHooks.new(actual_runtime.support_code), Filters::ApplyAroundHooks.new(actual_runtime.support_code), - Filters::BroadcastTestCaseReadyEvent.new(actual_runtime.configuration), Filters::BroadcastTestRunStartedEvent.new(actual_runtime.configuration), + Filters::BroadcastTestCaseReadyEvent.new(actual_runtime.configuration), Filters::PrepareWorld.new(actual_runtime) ] end diff --git a/spec/cucumber/glue/step_definition_spec.rb b/spec/cucumber/glue/step_definition_spec.rb index ab557763d7..81b4385fab 100644 --- a/spec/cucumber/glue/step_definition_spec.rb +++ b/spec/cucumber/glue/step_definition_spec.rb @@ -31,12 +31,8 @@ def step_match(text) end it 'allows calling of other steps' do - dsl.Given(/Outside/) do - step 'Inside' - end - dsl.Given(/Inside/) do - @@inside = true - end + dsl.Given('Outside') { step 'Inside' } + dsl.Given('Inside') { @@inside = true } run_step 'Outside' @@ -44,19 +40,19 @@ def step_match(text) end it 'allows calling of other steps with inline arg' do - dsl.Given(/Outside/) do - step 'Inside', table([['inside']]) - end - dsl.Given(/Inside/) do |t| - @@inside = t.raw[0][0] - end + dsl.Given('Outside') { step 'Inside', table([['inside']]) } + dsl.Given('Inside') { |t| @@inside = t.raw[0][0] } run_step 'Outside' - expect(@@inside).to eq 'inside' + expect(@@inside).to eq('inside') end context 'when mapping to world methods' do + before do + skip('These tests are problematic on truffleruby. See: https://github.com/oracle/truffleruby/issues/3870') if RUBY_ENGINE.start_with?('truffleruby') + end + it 'calls a method on the world when specified with a symbol' do expect(registry.current_world).to receive(:with_symbol) @@ -90,15 +86,14 @@ def step_match(text) end it 'has the correct location' do - dsl.Given(/With symbol/, :with_symbol) - expect(step_match('With symbol').file_colon_line).to eq "spec/cucumber/glue/step_definition_spec.rb:#{__LINE__ - 1}" + dsl.Given('With symbol', :with_symbol) + + expect(step_match('With symbol').file_colon_line).to eq("spec/cucumber/glue/step_definition_spec.rb:#{__LINE__ - 2}") end end it 'raises UndefinedDynamicStep when inside step is not defined' do - dsl.Given(/Outside/) do - step 'Inside' - end + dsl.Given('Outside') { step 'Inside' } expect { run_step 'Outside' }.to raise_error(Cucumber::UndefinedDynamicStep) end @@ -139,16 +134,13 @@ def step_match(text) end it 'allows forced pending' do - dsl.Given(/Outside/) do - pending('Do me!') - end + dsl.Given('Outside') { pending('Do me!') } expect { run_step 'Outside' }.to raise_error(Cucumber::Pending, 'Do me!') end it 'raises ArityMismatchError when the number of capture groups differs from the number of step arguments' do - dsl.Given(/No group: \w+/) do |arg| - end + dsl.Given(/No group: \w+/) { |_arg| } expect { run_step 'No group: arg' }.to raise_error(Cucumber::Glue::ArityMismatchError) end @@ -177,8 +169,8 @@ def step_match(text) it 'uses the instance created by the ParameterType transformer proc' do dsl.Given 'capture this: {actor}' do |arg| - expect(arg.name).to eq 'Anjie' - expect(arg).to be @actor + expect(arg.name).to eq('Anjie') + expect(arg).to eq(@actor) end run_step 'capture this: Anjie' @@ -191,8 +183,8 @@ def step_match(text) run_step 'capture this: Anjie' step_args = step_match('capture this: Anjie').args - expect(step_args[0].name).not_to eq 'Dave' - expect(step_args[0].name).to eq 'Anjie' + expect(step_args[0].name).not_to eq('Dave') + expect(step_args[0].name).to eq('Anjie') end end @@ -200,18 +192,14 @@ def step_match(text) it 'calls "attach" with the correct media type' do expect(user_interface).to receive(:attach).with('wasup', 'text/x.cucumber.log+plain', nil) - dsl.Given(/Loud/) do - log 'wasup' - end + dsl.Given('Loud') { log 'wasup' } run_step 'Loud' end it 'calls `to_s` if the message is not a String' do expect(user_interface).to receive(:attach).with('["Not", 1, "string"]', 'text/x.cucumber.log+plain', nil) - dsl.Given(/Loud/) do - log ['Not', 1, 'string'] - end + dsl.Given('Loud') { log 'wasup' } run_step 'Loud' end end @@ -225,20 +213,9 @@ def step_match(text) end it 'has a JSON representation of the signature' do - expect(described_class.new( - id, - registry, - /I CAN HAZ (\d+) CUKES/i, - -> {}, - {} - ).to_hash).to eq( - source: { - type: 'regular expression', - expression: 'I CAN HAZ (\\d+) CUKES' - }, - regexp: { - source: 'I CAN HAZ (\\d+) CUKES', flags: 'i' - } + expect(described_class.new(id, registry, /I CAN HAZ (\d+) CUKES/i, -> {}, {}).to_hash).to eq( + source: { type: 'regular expression', expression: 'I CAN HAZ (\\d+) CUKES' }, + regexp: { source: 'I CAN HAZ (\\d+) CUKES', flags: 'i' } ) end end