Skip to content

Commit

Permalink
Bugfix/invalid conversion (#285)
Browse files Browse the repository at this point in the history
* Fix invalid conversion for time

* AF: Lint/Symbolconversion

* Fix line spacing for some specs
Fix situation where an invalid context let was redundant

* Fix reference to helpers message uuid being wrong

* Bump minimum messages requirement

* Add changelog entry

* Bump minimum ruby and max messages requirements

* Bump rubocop config min version

* Set min patch of rubocop-rspec to 5

* Update changelog

* Drop ruby 2.7 from testing matrix and run on system rubies / bundlers by default!
  • Loading branch information
luke-hill authored Sep 10, 2024
1 parent 10c5107 commit fb1f1df
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
rubygems: latest
ruby-version: 3.0
bundler-cache: true
- run: bundle exec rubocop
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
ruby: ['3.0', '3.1', '3.2', '3.3']
include:
- os: ubuntu-latest
ruby: jruby
Expand All @@ -33,8 +33,6 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler: 2.4.19
rubygems: latest
bundler-cache: true
- name: Run tests
run: bundle exec rake
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require:

AllCops:
# Keep this inline with the gemspec
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
DisplayCopNames: true
DisplayStyleGuide: true
NewCops: enable
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber.

## [Unreleased]
### Changed
- Permit usage of gherkin up to v29 and messages up to v28

### Fixed
- References to the Time Conversion and UUID helpers needed altering to use the `Helpers` namespace

### Removed
- Remove support for ruby 2.7 and below. 3.0 or higher is required now (Owing to messages bump)

## [14.0.0] - 2024-08-08
### Changed
Expand Down
6 changes: 3 additions & 3 deletions cucumber-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.homepage = 'https://cucumber.io'
s.platform = Gem::Platform::RUBY
s.license = 'MIT'
s.required_ruby_version = '>= 2.7'
s.required_ruby_version = '>= 3.0'
s.required_rubygems_version = '>= 3.2.8'

s.metadata = {
Expand All @@ -24,15 +24,15 @@ Gem::Specification.new do |s|
}

s.add_dependency 'cucumber-gherkin', '> 27', '< 30'
s.add_dependency 'cucumber-messages', '> 22', '< 27'
s.add_dependency 'cucumber-messages', '> 25', '< 28'
s.add_dependency 'cucumber-tag-expressions', '> 5', '< 7'

s.add_development_dependency 'rake', '~> 13.2'
s.add_development_dependency 'rspec', '~> 3.13'
s.add_development_dependency 'rubocop', '~> 1.61.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.0.1'
s.add_development_dependency 'rubocop-rspec', '~> 3.0.5'

s.files = Dir['CHANGELOG.md', 'README.md', 'LICENSE', 'lib/**/*']
s.rdoc_options = ['--charset=UTF-8']
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Compiler

def initialize(receiver, gherkin_query, event_bus = nil)
@receiver = receiver
@id_generator = Cucumber::Messages::IdGenerator::UUID.new
@id_generator = Cucumber::Messages::Helpers::IdGenerator::UUID.new
@gherkin_query = gherkin_query
@event_bus = event_bus
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.new(*events)

define_method(:initialize) do |*attributes|
events.zip(attributes) do |name, value|
instance_variable_set("@#{name}".to_sym, value)
instance_variable_set(:"@#{name}", value)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/core/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.new(*attributes, &block)

define_method(:initialize) do |*args|
attributes.zip(args) do |name, value|
instance_variable_set("@#{name}".to_sym, value)
instance_variable_set(:"@#{name}", value)
end
end

Expand All @@ -63,7 +63,7 @@ def done
end

define_method(:with_receiver) do |new_receiver|
args = attributes.map { |name| instance_variable_get("@#{name}".to_sym) }
args = attributes.map { |name| instance_variable_get(:"@#{name}") }
args[-1] = new_receiver
self.class.new(*args)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/core/test/result.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'cucumber/messages'
require 'cucumber/messages/time_conversion'
require 'cucumber/messages/helpers/time_conversion'

module Cucumber
module Core
Expand Down Expand Up @@ -404,7 +404,7 @@ def increment_total(status)
end

class Duration
include Cucumber::Messages::TimeConversion
include Cucumber::Messages::Helpers::TimeConversion

attr_reader :nanoseconds

Expand All @@ -425,7 +425,7 @@ def to_message_duration
end

class UnknownDuration
include Cucumber::Messages::TimeConversion
include Cucumber::Messages::Helpers::TimeConversion

def tap
self
Expand Down
7 changes: 3 additions & 4 deletions spec/cucumber/core/event_bus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@ class TestEvent < Core::Event.new(:some_attribute)
called = false
event_bus.on(:test_event) { called = true }
event_bus.test_event

expect(called).to be true
end

it 'can broadcast by calling the `broadcast` method with an instance of the event type' do
called = false
event_bus.on(:test_event) { called = true }
event_bus.broadcast(Events::TestEvent.new(:some_attribute))

expect(called).to be true
end

it 'calls a subscriber for an event, passing details of the event' do
received_payload = nil
event_bus.on :test_event do |event|
received_payload = event
end

event_bus.on(:test_event) { |event| received_payload = event }
event_bus.test_event :some_attribute

expect(received_payload.some_attribute).to eq(:some_attribute)
Expand Down
7 changes: 3 additions & 4 deletions spec/cucumber/core/test/locations_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,28 +254,27 @@ def test_case_named(name)
end

context 'with a docstring' do
let(:test_case) do
test_cases.detect { |tc| tc.name == 'with docstring' }
end

it 'matches a location at the start the docstring' do
location = Cucumber::Core::Test::Location.new(file, 17)
filter = described_class.new([location])
compile([doc], receiver, [filter])

expect(receiver.test_case_locations).to eq([test_case_named('with docstring').location])
end

it 'matches a location in the middle of the docstring' do
location = Cucumber::Core::Test::Location.new(file, 18)
filter = described_class.new([location])
compile([doc], receiver, [filter])

expect(receiver.test_case_locations).to eq([test_case_named('with docstring').location])
end

it 'matches a location at the end of the docstring' do
location = Cucumber::Core::Test::Location.new(file, 19)
filter = described_class.new([location])
compile([doc], receiver, [filter])

expect(receiver.test_case_locations).to eq([test_case_named('with docstring').location])
end
end
Expand Down
32 changes: 16 additions & 16 deletions spec/cucumber/core/test/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,18 @@
end

context 'with around hooks' do
let(:passing_around_hook) do
Cucumber::Core::Test::AroundHook.new { |block| block.call }
end
let(:failing_around_hook) do
Cucumber::Core::Test::AroundHook.new do |block|
block.call
raise StandardError
end
end

it "passes normally when around hooks don't fail" do
around_hook = Cucumber::Core::Test::AroundHook.new { |block| block.call }
test_case = Cucumber::Core::Test::Case.new(double, double, [passing], double, double, double, double, [around_hook])
test_case = Cucumber::Core::Test::Case.new(double, double, [passing], double, double, double, double, [passing_around_hook])
expect(event_bus).to receive(:test_case_finished).with(test_case, anything) do |_reported_test_case, result|
expect(result).to be_passed
end
Expand All @@ -260,34 +269,25 @@
end

it 'gets a failed result if the Around hook fails after the test case is run' do
around_hook = Cucumber::Core::Test::AroundHook.new do |block|
block.call
raise StandardError
end
test_case = Cucumber::Core::Test::Case.new(double, double, [passing], double, double, double, double, [around_hook])
test_case = Cucumber::Core::Test::Case.new(double, double, [passing], double, double, double, double, [failing_around_hook])
expect(event_bus).to receive(:test_case_finished).with(test_case, anything) do |_reported_test_case, result|
expect(result).to be_failed
expect(result.exception).to be_a StandardError
expect(result.exception).to be_a(StandardError)
end
test_case.describe_to runner
end

it 'fails when a step fails if the around hook works' do
around_hook = Cucumber::Core::Test::AroundHook.new { |block| block.call }
test_case = Cucumber::Core::Test::Case.new(double, double, [failing], double, double, double, double, [around_hook])
test_case = Cucumber::Core::Test::Case.new(double, double, [failing], double, double, double, double, [passing_around_hook])
expect(event_bus).to receive(:test_case_finished).with(test_case, anything) do |_reported_test_case, result|
expect(result).to be_failed
expect(result.exception).to be_a StandardError
expect(result.exception).to be_a(StandardError)
end
test_case.describe_to runner
end

it 'sends after_test_step for a step interrupted by (a timeout in) the around hook' do
around_hook = Cucumber::Core::Test::AroundHook.new do |block|
block.call
raise StandardError
end
test_case = Cucumber::Core::Test::Case.new(double, double, [], double, double, double, double, [around_hook])
test_case = Cucumber::Core::Test::Case.new(double, double, [], double, double, double, double, [failing_around_hook])
allow(runner).to receive(:running_test_step).and_return(passing)
expect(event_bus).to receive(:test_step_finished).with(passing, anything) do |_reported_test_case, result|
expect(result).to be_failed
Expand Down

0 comments on commit fb1f1df

Please sign in to comment.