Skip to content

Commit 64092da

Browse files
authored
Port CCK logic (#1748)
* Port runner of specs to same location as JS * Copy+Paste of the three files required to run the specs alongside the shared examples * Add calculator file * Switch first class requires over to using newly copied files * Convert all requires over to localised files * Copy over gem code * Fix file structure * Fix up namespacing issues * Remove all NDJSON files as those are stored on the gem as the source of truth * Remove redundant code to run single groups * Spike to get tests passing partially * Remove redundant variable assignment * Use new namespace to avoid conflicts * Fix up of all naming conventions for new layout * Remove redundant requires * Require support code locally but feature code from the gem * Remove all .feature files from core repo as those will be housed/ran on cck * Calculate gherkin examples in gem to be ran locally * Preserve markdown folder structure but remove feature * Renames to show local code is supporting code * Re-move helpers back into helper * Remove all feature example detection as that now lives in the gem proper * Copy, port and adapt meta-tests for CCK::Examples * Copy over remaining specs from CCK repo proper and add bugfix for missing require * Tidy up rakefile * Remove old ref to cck tests * Fix rake to test newly imported CCK correctly * Use type metadata to signify a feature test to ignore rubocop issues * Slight rubocop tweaks * Use new namespaces / method names from unreleased CCK major * Remove oddity from step definition code for attachments feature (Now we're using our own steps we don't need to be conformant)" * Final tidies * Use latest CCK * Add changelog entry * Fix example name in negative test * Fix naming conflict for local/gem based feature location * Fix issue where blank hook generated a different number of messages * Fix up changelog docs * Fix JRuby nuance with NME's triggering with more info * Fix style to avoid size issues in the future * Fix file pattern mismatch
1 parent 09f4d30 commit 64092da

35 files changed

+628
-46
lines changed

.rubocop.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ AllCops:
1818
DisplayCopNames: true
1919
DisplayStyleGuide: true
2020
Exclude:
21-
- 'bin/*'
22-
- 'tmp/**/*'
23-
- 'vendor/**/*'
24-
- 'temp_app/**/*'
25-
- 'cck/features/**/*'
21+
- bin/*
22+
- tmp/**/*
23+
- vendor/**/*
24+
- temp_app/**/*
2625

2726
# A line length of 200 covers most violations in the repo while still being a more up to date length given today's screen sizes
2827
Layout/LineLength:
@@ -32,29 +31,29 @@ Layout/LineLength:
3231
# In pretty_spec.rb & progress_spec.rb offences look false as the trailing spaces are in fact multiline string literals
3332
Layout/TrailingWhitespace:
3433
Exclude:
35-
- 'spec/cucumber/formatter/pretty_spec.rb'
36-
- 'spec/cucumber/formatter/progress_spec.rb'
34+
- spec/cucumber/formatter/pretty_spec.rb
35+
- spec/cucumber/formatter/progress_spec.rb
3736

3837
# TODO: [LH] - This needs a re-review. I think we can pretty much delete / phase this out with incremental updates
3938
# We exclude proto_world for documentation (rdoc) purpose
4039
Lint/UselessMethodDefinition:
4140
Enabled: true
4241
Exclude:
43-
- 'lib/cucumber/glue/proto_world.rb'
42+
- lib/cucumber/glue/proto_world.rb
4443

4544
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
4645
Metrics/ClassLength:
4746
Max: 375
4847
Exclude:
49-
- 'lib/cucumber/cli/options.rb'
48+
- lib/cucumber/cli/options.rb
5049
# TODO: Manually added! - be careful with regenning the file - this needs a fix
5150
- lib/cucumber/formatter/pretty.rb
5251

5352
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
5453
Metrics/ModuleLength:
5554
Max: 135
5655
Exclude:
57-
- './spec/**/*'
56+
- spec/**/*
5857
# TODO: Manually added! - be careful with regenning the file - this needs a fix
5958
- lib/cucumber/formatter/console.rb
6059

@@ -73,13 +72,18 @@ Metrics/MethodLength:
7372
Naming/AsciiIdentifiers:
7473
Enabled: false
7574

75+
# These directories (And associated files), are named according to the CCK convention which is kebab-case
76+
Naming/FileName:
77+
Exclude:
78+
- compatibility/features/**/*
79+
7680
# For the most part, the project is solid on naming. There are though, a few
7781
# cases where the cop doesn't need to catch.
7882
Naming/MethodName:
7983
Exclude:
80-
- 'examples/i18n/ar/lib/calculator.rb'
81-
- 'examples/i18n/he/lib/calculator.rb'
82-
- 'lib/cucumber/glue/dsl.rb'
84+
- examples/i18n/ar/lib/calculator.rb
85+
- examples/i18n/he/lib/calculator.rb
86+
- lib/cucumber/glue/dsl.rb
8387

8488
RSpec/ExampleLength:
8589
CountAsOne: ['array', 'hash', 'heredoc']

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
99
Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber.
1010

1111
## [Unreleased]
12-
13-
## [9.1.1] - 2024-01-04
1412
### Added
1513

1614
### Changed
17-
- Updated dependencies to slightly more permissive / up to date versions ([luke-hill](https://github.com/luke-hill))
18-
- Fixed most of the `Layout` cop offenses ([luke-hill](https://github.com/luke-hill))
15+
- Moved all CCK step definition/miscellaneous file logic from CCK gem to this repo.
16+
All logic contained in [compatibility](./compatibility) ([luke-hill](https://github.com/luke-hill))
1917

2018
### Fixed
2119

20+
### Removed
21+
22+
## [9.1.1] - 2024-01-04
23+
### Changed
24+
- Updated dependencies to slightly more permissive / up to date versions ([luke-hill](https://github.com/luke-hill))
25+
- Fixed most of the `Layout` cop offenses ([luke-hill](https://github.com/luke-hill))
26+
2227
### Removed
2328
- The sample sinatra tests are no longer used in internal testing (This removes a bunch of superfluous dev gems) ([#1743](https://github.com/cucumber/cucumber-ruby/pull/1743) [luke-hill](https://github.com/luke-hill))
2429
- Removed all references to autotest as this is an ancient plugin that is not correctly integrated

Rakefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'rubygems'
4-
require 'bundler'
5-
6-
Bundler::GemHelper.install_tasks
7-
83
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
94
Dir['gem_tasks/**/*.rake'].each { |rake| load rake }
105

@@ -15,7 +10,5 @@ require 'cucumber/rake/task'
1510
Cucumber::Rake::Task.new
1611

1712
default_tasks = %i[spec cucumber cck]
18-
1913
default_tasks << :examples if ENV['CI']
20-
2114
task default: default_tasks

compatibility/cck_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'support/shared_examples'
4+
require_relative 'support/cck/examples'
5+
6+
require 'cucumber-compatibility-kit'
7+
8+
describe 'Cucumber Compatibility Kit', type: :feature, cck: true do
9+
let(:cucumber_command) { 'bundle exec cucumber --publish-quiet --profile none --format message' }
10+
11+
CCK::Examples.gherkin.each do |example_name|
12+
describe "'#{example_name}' example" do
13+
include_examples 'cucumber compatibility kit' do
14+
let(:example) { example_name }
15+
let(:extra_args) { example == 'retry' ? '--retry 2' : '' }
16+
let(:support_code_path) { CCK::Examples.supporting_code_for(example) }
17+
let(:messages) { `#{cucumber_command} #{extra_args} --require #{support_code_path} #{cck_path}` }
18+
end
19+
end
20+
end
21+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
# This blank hook has been re-added in. See https://github.com/cucumber/compatibility-kit/issues/83 for more details
4+
Before { nil }
5+
6+
When('the string {string} is attached as {string}') do |text, media_type|
7+
attach(text, media_type)
8+
end
9+
10+
When('the string {string} is logged') do |text|
11+
log(text)
12+
end
13+
14+
When('text with ANSI escapes is logged') do
15+
log("This displays a \x1b[31mr\x1b[0m\x1b[91ma\x1b[0m\x1b[33mi\x1b[0m\x1b[32mn\x1b[0m\x1b[34mb\x1b[0m\x1b[95mo\x1b[0m\x1b[35mw\x1b[0m")
16+
end
17+
18+
When('the following string is attached as {string}:') do |media_type, doc_string|
19+
attach(doc_string, media_type)
20+
end
21+
22+
When('an array with {int} bytes is attached as {string}') do |size, media_type|
23+
data = (0..size - 1).map { |i| [i].pack('C') }.join
24+
attach(data, media_type)
25+
end
26+
27+
When('a JPEG image is attached') do
28+
attach(File.open("#{__dir__}/cucumber.jpeg"), 'image/jpeg')
29+
end
30+
31+
When('a PNG image is attached') do
32+
attach(File.open("#{__dir__}/cucumber.png"), 'image/png')
33+
end
34+
35+
When('a PDF document is attached and renamed') do
36+
attach(File.open("#{__dir__}/document.pdf"), 'document/pdf', 'renamed.pdf')
37+
end
1.41 KB
Loading
Loading
9.82 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
Given('I have {int} <![CDATA[cukes]]> in my belly') do |_cuke_count|
4+
# no-op
5+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
When('the following table is transposed:') do |table|
4+
@transposed = table.transpose
5+
end
6+
7+
Then('it should be:') do |expected|
8+
@transposed.diff!(expected)
9+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
Given('there are {int} cucumbers') do |initial_count|
4+
@count = initial_count
5+
end
6+
7+
When('I eat {int} cucumbers') do |eat_count|
8+
@count -= eat_count
9+
end
10+
11+
Then('I should have {int} cucumbers') do |expected_count|
12+
expect(@count).to eq(expected_count)
13+
end
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
Before do
4+
# no-op
5+
end
6+
7+
Before(name: 'A named hook') do
8+
# no-op
9+
end
10+
11+
When('a step passes') do
12+
# no-op
13+
end
14+
15+
When('a step fails') do
16+
raise 'Exception in step'
17+
end
18+
19+
After do
20+
# no-op
21+
end
22+
23+
After('@some-tag or @some-other-tag') do
24+
raise 'Exception in conditional hook'
25+
end
26+
27+
After('@with-attachment') do
28+
attach(File.open("#{__dir__}/cucumber.svg"), 'image/svg+xml')
29+
end

compatibility/features/markdown/.keep

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
Given('I have {int} cukes in my belly') do |_cuke_count|
4+
# no-op
5+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
class Flight
4+
attr_reader :from, :to
5+
6+
def initialize(from, to)
7+
@from = from
8+
@to = to
9+
end
10+
end
11+
12+
ParameterType(
13+
name: 'flight',
14+
regexp: /([A-Z]{3})-([A-Z]{3})/,
15+
transformer: ->(from, to) { Flight.new(from, to) }
16+
)
17+
18+
Given('{flight} has been delayed') do |flight|
19+
expect(flight.from).to eq('LHR')
20+
expect(flight.to).to eq('CDG')
21+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
Given('an implemented non-pending step') do
4+
# no-op
5+
end
6+
7+
Given('an implemented step that is skipped') do
8+
# no-op
9+
end
10+
11+
Given('an unimplemented pending step') do
12+
pending('')
13+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--retry 2
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
Given('a step that always passes') do
4+
# no-op
5+
end
6+
7+
second_time_pass = 0
8+
Given('a step that passes the second time') do
9+
second_time_pass += 1
10+
raise 'Exception in step' if second_time_pass < 2
11+
end
12+
13+
third_time_pass = 0
14+
Given('a step that passes the third time') do
15+
third_time_pass += 1
16+
raise 'Exception in step' if third_time_pass < 3
17+
end
18+
19+
Given('a step that always fails') do
20+
raise 'Exception in step'
21+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
Given('the customer has {int} cents') do |money|
4+
@money = money
5+
end
6+
7+
Given('there are chocolate bars in stock') do
8+
@stock = ['Mars']
9+
end
10+
11+
Given('there are no chocolate bars in stock') do
12+
@stock = []
13+
end
14+
15+
When('the customer tries to buy a {int} cent chocolate bar') do |price|
16+
@chocolate = @stock.pop if @money >= price
17+
end
18+
19+
Then('the sale should not happen') do
20+
expect(@chocolate).to be_nil
21+
end
22+
23+
Then('the sale should happen') do
24+
expect(@chocolate).not_to be_nil
25+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
Before('@skip') do
4+
skip_this_scenario('')
5+
end
6+
7+
Given('a step that does not skip') do
8+
# no-op
9+
end
10+
11+
Given('a step that is skipped') do
12+
# no-op
13+
end
14+
15+
Given('I skip a step') do
16+
skip_this_scenario('')
17+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
When('a step throws an exception') do
4+
raise 'BOOM'
5+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
Given('an implemented step') do
4+
# no-op
5+
end
6+
7+
Given('a step that will be skipped') do
8+
# no-op
9+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
Given('{airport} is closed because of a strike') do |_airport|
4+
raise 'Should not be called because airport parameter type has not been defined'
5+
end

0 commit comments

Comments
 (0)