Skip to content

Commit fbdc375

Browse files
Deprecate usage of built-in cucumber wire protocol (#1564)
* Deprecate usage of built-in cucumber wire protocol * Update CHANGELOG * Make it work with future version of cucumber-ruby-wire * Add an UPGRADING.md document * Add a registry wrapper to avoid exposing RegistryAndMore * Add a new InstallPlugin hook That prevent changing the AfterConfiguration hook and allows to have a dedicated hook for external plugins.
1 parent ee3d176 commit fbdc375

File tree

7 files changed

+157
-2
lines changed

7 files changed

+157
-2
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
1414

1515
### Added
1616

17+
- New hook: `InstallPlugin`
18+
19+
It is intended to be used to install an external plugin, like cucumber-ruby-wire.
20+
21+
It is fired just after the `AfterConfiguration` one. Two parameters are given:
22+
the same `configuration` instance that is given to `AfterConfiguration`,
23+
and a [`registry_wrapper`](./lib/cucumber/glue/registry_wrapper.rb) which allows
24+
plugins to have access to specific internal methods.
25+
26+
See [cucumber-ruby-wire](https://github.com/cucumber/cucumber-ruby-wire/) for a
27+
usage example.
28+
29+
([1564](https://github.com/cucumber/cucumber-ruby/pull/1564)
30+
[aurelien-reeves](https://github.com/aurelien-reeves))
31+
1732
### Fixed
1833

1934
### Changed
@@ -22,6 +37,18 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
2237

2338
### Security fixes
2439

40+
### Deprecated
41+
42+
- The built-in Wire protocol
43+
44+
The Wire protocol is still officially supported, but as an optional plugin rather
45+
than a built-in feature. See the
46+
[UPGRADING.md](./UPGRADING.md#upgrading-to-710)
47+
to update your code accordingly.
48+
49+
([1564](https://github.com/cucumber/cucumber-ruby/pull/1564)
50+
[aurelien-reeves](https://github.com/aurelien-reeves))
51+
2552
## [7.0.0](https://github.com/cucumber/cucumber-ruby/compare/v6.1.0...v7.0.0)
2653

2754
### Fixed

UPGRADING.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Upgrading to 7.1.0
2+
3+
## The wire protocol
4+
5+
Usage of built-in wire protocol with `cucumber-ruby` will be deprecated in cucumber
6+
7.1.0, and removed in cucumber 8.0.0.
7+
8+
The wire protocol will still be available by explicitely using the `cucumber-wire`
9+
gem.
10+
11+
### Before cucumber 7.1.0
12+
13+
Before cucumber 7.1.0, the wire protocol was automatically installed with cucumber,
14+
and automatically activated when it had detected a `.wire` file.
15+
16+
### With cucumber 7.1.0
17+
18+
The wire protocol will work as before, but you will notice a deprecation message.
19+
20+
To prevent the deprecation message to be shown, add the gem `cucumber-wire` to your
21+
Gemfile alongside the `cucumber` one, and install it:
22+
23+
```ruby
24+
# Gemfile
25+
26+
# ...
27+
28+
gem "cucumber"
29+
gem "cucumber-wire"
30+
31+
# ...
32+
33+
```
34+
```shell
35+
bundle install
36+
```
37+
38+
And add `require 'cucumber/wire'` in your support code. If you do not have support
39+
code yet, create a new one. For example `features/support/wire.rb`.
40+
41+
```ruby
42+
# features/support/wire.rb
43+
require 'cucumber/wire'
44+
```
45+
46+
The wire protocol will be installed, and no deprecation message will be shown anymore.

lib/cucumber/glue/dsl.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def AfterConfiguration(&proc)
113113
Dsl.register_rb_hook('after_configuration', [], proc)
114114
end
115115

116+
# Registers a proc that will run after Cucumber is configured in order to install an external plugin.
117+
def InstallPlugin(&proc)
118+
Dsl.register_rb_hook('install_plugin', [], proc)
119+
end
120+
116121
# Registers a new Ruby StepDefinition. This method is aliased
117122
# to <tt>Given</tt>, <tt>When</tt> and <tt>Then</tt>, and
118123
# also to the i18n translations whenever a feature of a

lib/cucumber/glue/registry_and_more.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def after_configuration(configuration)
140140
end
141141
end
142142

143+
def install_plugin(configuration, registry)
144+
hooks[:install_plugin].each do |hook|
145+
hook.invoke('InstallPlugin', [configuration, registry])
146+
end
147+
end
148+
143149
def add_hook(phase, hook)
144150
hooks[phase.to_sym] << hook
145151
hook
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Cucumber
4+
module Glue
5+
##
6+
# This class wraps some internals methods to expose them to external plugins.
7+
class RegistryWrapper
8+
def initialize(registry)
9+
@registry = registry
10+
end
11+
12+
##
13+
# Creates a new CucumberExpression from the given +string_or_regexp+.
14+
#
15+
# If +string_or_regexp+ is a string, it will return a new CucumberExpression::CucumberExpression
16+
#
17+
# If +string_or_regexp+ is a regexp, it will return a new CucumberExpressions::RegularExpression
18+
#
19+
# An ArgumentError is raised if +string_or_regexp+ is not a string or a regexp
20+
def create_expression(string_or_regexp)
21+
@registry.create_expression(string_or_regexp)
22+
end
23+
24+
##
25+
# Return the current execution environment - AKA an isntance of World
26+
def current_world
27+
@registry.current_world
28+
end
29+
end
30+
end
31+
end

lib/cucumber/runtime.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
require 'fileutils'
44
require 'cucumber/configuration'
55
require 'cucumber/create_meta'
6+
require 'cucumber/deprecate'
67
require 'cucumber/load_path'
78
require 'cucumber/formatter/duration'
89
require 'cucumber/file_specs'
910
require 'cucumber/filters'
1011
require 'cucumber/formatter/fanout'
1112
require 'cucumber/gherkin/i18n'
13+
require 'cucumber/glue/registry_wrapper'
1214
require 'cucumber/step_match_search'
1315
require 'cucumber/messages'
1416
require 'sys/uname'
@@ -70,8 +72,9 @@ def run!
7072
)
7173

7274
load_step_definitions
73-
install_wire_plugin
7475
fire_after_configuration_hook
76+
fire_install_plugin_hook
77+
install_wire_plugin
7578
# TODO: can we remove this state?
7679
self.visitor = report
7780

@@ -112,6 +115,10 @@ def fire_after_configuration_hook #:nodoc:
112115
@support_code.fire_hook(:after_configuration, @configuration)
113116
end
114117

118+
def fire_install_plugin_hook #:nodoc:
119+
@support_code.fire_hook(:install_plugin, @configuration, registry_wrapper)
120+
end
121+
115122
require 'cucumber/core/gherkin/document'
116123
def features
117124
@features ||= feature_files.map do |path|
@@ -261,7 +268,19 @@ def load_step_definitions
261268
end
262269

263270
def install_wire_plugin
264-
Cucumber::Wire::Plugin.new(@configuration, @support_code.registry).install if @configuration.all_files_to_load.any? { |f| f =~ /\.wire$/ }
271+
return if Cucumber::Wire::Plugin.installed?
272+
return unless @configuration.all_files_to_load.any? { |f| f =~ /\.wire$/ }
273+
274+
Cucumber::Wire::Plugin.new(@configuration, registry_wrapper).install
275+
Cucumber.deprecate(
276+
'See https://github.com/cucumber/cucumber-ruby/blob/main/UPGRADING.md#upgrading-to-710 for more info',
277+
' built-in usage of the wire protocol',
278+
'8.0.0'
279+
)
280+
end
281+
282+
def registry_wrapper
283+
Cucumber::Glue::RegistryWrapper.new(@support_code.registry)
265284
end
266285

267286
def log

spec/cucumber/runtime_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,26 @@ module Cucumber
2020
expect(subject.doc_string('Text')).to eq 'Text'
2121
end
2222
end
23+
24+
describe '#install_wire_plugin' do
25+
it 'informs the user it is deprecated' do
26+
stub_const('Cucumber::Deprecate::STRATEGY', Cucumber::Deprecate::ForUsers)
27+
allow(STDERR).to receive(:puts)
28+
allow_any_instance_of(Configuration).to receive(:all_files_to_load).and_return(['file.wire'])
29+
30+
begin
31+
subject.run!
32+
rescue NoMethodError
33+
# this is actually expected
34+
end
35+
36+
expect(STDERR).to have_received(:puts).with(
37+
a_string_including([
38+
'WARNING: # built-in usage of the wire protocol is deprecated and will be removed after version 8.0.0.',
39+
'See https://github.com/cucumber/cucumber-ruby/blob/main/UPGRADING.md#upgrading-to-710 for more info.'
40+
].join(' '))
41+
)
42+
end
43+
end
2344
end
2445
end

0 commit comments

Comments
 (0)