Skip to content

Commit

Permalink
Refactor/v13 prep (#273)
Browse files Browse the repository at this point in the history
* Remove random file

* Update gemspec

* Remove another random file

* Fix linting of lines

* Unpick some of the JRuby optimisations made

* Add documentation for metaprogramming unpicking and re-enable flaky test
  • Loading branch information
luke-hill committed Nov 10, 2023
1 parent fd431fc commit 7842d42
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 63 deletions.
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

6 changes: 0 additions & 6 deletions .yardopts

This file was deleted.

11 changes: 2 additions & 9 deletions cucumber-core.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

version = File.read(File.expand_path('VERSION', __dir__)).strip
Expand All @@ -25,7 +24,7 @@ Gem::Specification.new do |s|

s.add_dependency 'cucumber-gherkin', '>= 27', '< 28'
s.add_dependency 'cucumber-messages', '>= 20', '< 23'
s.add_dependency 'cucumber-tag-expressions', '~> 5.0', '>= 5.0.4'
s.add_dependency 'cucumber-tag-expressions', '> 5', '< 7'

s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
s.add_development_dependency 'rspec', '~> 3.11', '>= 3.11.0'
Expand All @@ -35,13 +34,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rubocop-packaging', '~> 0.5', '>= 0.5.1'
s.add_development_dependency 'unindent', '~> 1.0', '>= 1.0'

s.files = Dir[
'CHANGELOG.md',
'CONTRIBUTING.md',
'README.md',
'LICENSE',
'lib/**/*'
]
s.files = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'README.md', 'LICENSE', 'lib/**/*']
s.rdoc_options = ['--charset=UTF-8']
s.require_path = 'lib'
end
17 changes: 8 additions & 9 deletions lib/cucumber/core/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def self.new(*events)
return super if ancestors.index(Event) > 0

Class.new(Event) do
# NB: We need to use metaprogramming here instead of direct variable obtainment
# because JRuby does not guarantee the order in which variables are defined is equivalent
# to the order in which they are obtainable
#
# See https://github.com/jruby/jruby/issues/7988 for more info
attr_reader(*events)

define_method(:initialize) do |*attributes|
Expand All @@ -18,23 +23,17 @@ def self.new(*events)
end
end

def attributes
instance_variables.map { |var| instance_variable_get(var) }
define_method(:attributes) do
events.map { |var| instance_variable_get(:"@#{var}") }
end

def to_h
define_method(:to_h) do
events.zip(attributes).to_h
end

def event_id
self.class.event_id
end

private

def events
instance_variables.map { |var| (var[1..-1]).to_sym }
end
end
end

Expand Down
78 changes: 42 additions & 36 deletions spec/cucumber/core/test/filters/locations_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,26 @@ module Core
end

it 'works with wildcard locations' do
locations = [
Test::Location.new('features/test.feature')
]
locations = [Test::Location.new('features/test.feature')]
filter = described_class.new(locations)
compile([doc], receiver, [filter])
expect(receiver.test_case_locations).to eq([
Test::Location.new('features/test.feature', 3),
Test::Location.new('features/test.feature', 6)
])
expect(receiver.test_case_locations).to eq(
[
Test::Location.new('features/test.feature', 3),
Test::Location.new('features/test.feature', 6)
]
)
end

it "filters out scenarios that don't match" do
locations = [
Test::Location.new('features/test.feature', 3)
]
locations = [Test::Location.new('features/test.feature', 3)]
filter = described_class.new(locations)
compile([doc], receiver, [filter])
expect(receiver.test_case_locations).to eq(locations)
end

describe 'matching location' do
let(:file) { 'features/path/to/the.feature' }

let(:test_cases) do
receiver = double.as_null_object
result = []
Expand All @@ -81,7 +78,7 @@ module Core
Scenario: one
Given one a
# comment
# comment
@tags
Scenario: two
Given two a
Expand Down Expand Up @@ -150,40 +147,48 @@ def test_case_named(name)
location = Test::Location.new(file, 29)
filter = described_class.new([location])
compile [doc], receiver, [filter]
expect(receiver.test_case_locations).to eq([
test_case_named('with a rule and background').location,
test_case_named('another with a rule and background').location
])
expect(receiver.test_case_locations).to eq(
[
test_case_named('with a rule and background').location,
test_case_named('another with a rule and background').location
]
)
end

it "matches the rule background location to all of the rule's scenarios" do
location = Test::Location.new(file, 30)
filter = described_class.new([location])
compile [doc], receiver, [filter]
expect(receiver.test_case_locations).to eq([
test_case_named('with a rule and background').location,
test_case_named('another with a rule and background').location
])
expect(receiver.test_case_locations).to eq(
[
test_case_named('with a rule and background').location,
test_case_named('another with a rule and background').location
]
)
end

it "matches a rule background step location to all of the rule's scenarios" do
location = Test::Location.new(file, 31)
filter = described_class.new([location])
compile [doc], receiver, [filter]
expect(receiver.test_case_locations).to eq([
test_case_named('with a rule and background').location,
test_case_named('another with a rule and background').location
])
expect(receiver.test_case_locations).to eq(
[
test_case_named('with a rule and background').location,
test_case_named('another with a rule and background').location
]
)
end

it "matches a rule location (without a background) to all of the rule's scenarios" do
location = Test::Location.new(file, 39)
filter = described_class.new([location])
compile [doc], receiver, [filter]
expect(receiver.test_case_locations).to eq([
test_case_named('with a rule and no background').location,
test_case_named('another with a rule and no background').location
])
expect(receiver.test_case_locations).to eq(
[
test_case_named('with a rule and no background').location,
test_case_named('another with a rule and no background').location
]
)
end

it 'matches a scenario location to the scenario' do
Expand All @@ -199,10 +204,12 @@ def test_case_named(name)
whitespace_location = Test::Location.new(file, 7)
filter = described_class.new([scenario_location, another_scenario_location, whitespace_location])
compile([doc], receiver, [filter])
expect(receiver.test_case_locations).to eq([
test_case_named('one').location,
test_case_named('two').location
])
expect(receiver.test_case_locations).to eq(
[
test_case_named('one').location,
test_case_named('two').location
]
)
end

it 'matches the first scenario step location to the scenario' do
Expand Down Expand Up @@ -306,7 +313,7 @@ def test_case_named(name)
Given one a
# comment on line 6
@tags-on-line-7
@tag-on-line-7
Scenario Outline: two <arg>
Given two a
And two <arg>
Expand All @@ -315,7 +322,7 @@ def test_case_named(name)
"""
# comment on line 15
@tags-on-line-16
@tag-on-line-16
Examples: x1
| arg |
| b |
Expand Down Expand Up @@ -421,8 +428,7 @@ def test_case(test_case)
test_cases << test_case
end

def done
end
def done; end

def test_case_locations
test_cases.map(&:location)
Expand Down
2 changes: 0 additions & 2 deletions spec/cucumber/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@
end

it 'fires events' do
pending 'This spec fails in JRuby. See https://github.com/jruby/jruby/issues/7988, for details' if defined?(JRUBY_VERSION)

observed_events = []
execute [gherkin_document], [Cucumber::Core::Test::Filters::ActivateStepsForSelfTest.new] do |event_bus|
event_bus.on(:test_case_started) do |event|
Expand Down

0 comments on commit 7842d42

Please sign in to comment.