Skip to content

Commit

Permalink
Remove AfterConfiguration hook (#1591)
Browse files Browse the repository at this point in the history
* Remove AfterConfiguration hook

* Update CHANGELOG.md

* Fix some typos
  • Loading branch information
aurelien-reeves committed Dec 7, 2021
1 parent 830ff5b commit a7e6855
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 106 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Removed

- `AfterConfiguration` has been removed. Please use `InstallPlugin` or `BeforeAll` instead.
See the [UPGRADING.md](./UPGRADING.md#upgrading-to-800) to update your code accordingly.
([PR#1591](https://github.com/cucumber/cucumber-ruby/pull/1591))

- The built-in Wire protocol
The Wire protocol is still officially supported, but as an optional plugin rather
than a built-in feature. See the
Expand Down
26 changes: 26 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Upgrading to 8.0.0

## AfterConfiguration hook

`AfterConfiguration` hook has been removed in 8.0.0.

Use the `InstallPlugin` hook if you need the `configuration` parameter.

```ruby
InstallPlugin do |configuration, registry|
# configuration is an instance of Cucumber::Configuration defined in
# lib/cucumber/configuration.rb
#
# registry is an instance of Cucumber::Glue::RegistryWrapper defined in
# lib/cucumber/glue/registry_wrapper.rb
end
```

Use the `BeforeAll` hook if you don't need the `configuration` parameter.

```ruby
BeforeAll do
# snip
end
```

More information about hooks can be found in [features/docs/writing_support_code/hooks/README.md](./features/docs/writing_support_code/hooks/README.md).

## The wire protocol

The built-in wire protocol has been removed.
Expand Down
28 changes: 6 additions & 22 deletions features/docs/writing_support_code/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Hooks are part of your support code.

They are executed in the following order:

- [AfterConfiguration](#afterconfiguration-and-installplugin)
- [InstallPlugin](#afterconfiguration-and-installplugin)
- [InstallPlugin](#installplugin)
- [BeforeAll](#beforeall-and-afterall)
- Per scenario:
- [Around](#around)
Expand All @@ -26,28 +25,13 @@ Multiple hooks of the same type are executed in the order that they were defined
If you wish to control this order, use manual requires in `env.rb` - This file is
loaded first - or migrate them all to one `hooks.rb` file.

## AfterConfiguration and InstallPlugin
## InstallPlugin

[`AfterConfiguration`](#afterconfiguration) and [`InstallPlugin`](#installplugin)
hooks are dedicated to plugins and are meant to extend Cucumber. For example,
[`AfterConfiguration`](#afterconfiguration) allows you to dynamically change the
configuration before the execution of the tests, and [`InstallPlugin`](#installplugin)
allows to have some code that would have deeper impact on the execution.
[`InstallPlugin`](#installplugin) hook is dedicated to using plugins and is meant to
extend Cucumber. For example, it allows to dynamically change the configuration
before the execution of tests or to add some code that could impact the execution itself.

### AfterConfiguration

**Note:** this is a legacy hook. You may consider using [`InstallPlugin`](#installplugin) instead.

```ruby
AfterConfiguration do |configuration|
# configuration is an instance of Cucumber::Configuration defined in
# lib/cucumber/configuration.rb.
end
```

### InstallPlugin

In addition to the configuration, `InstallPlugin` also has access to some of Cucumber
In addition to the configuration, `InstallPlugin` has access to some of the Cucumber
internals through a `RegistryWrapper`, defined in
[lib/cucumber/glue/registry_wrapper.rb](../../../../lib/cucumber/glue/registry_wrapper.rb).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: BeforeAll Hooks
BeforeAll hooks can be used if you have some set-up to be done before all
scenarios are executed.

BeforeAll hooks are not aware of your configuration. Use AfterConfiguration if
BeforeAll hooks are not aware of your configuration. Use InstallPlugin if
you need it.

Scenario: A single BeforeAll hook
Expand Down

This file was deleted.

8 changes: 0 additions & 8 deletions lib/cucumber/glue/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ def if_nil(value, default)
value.nil? ? default : value
end

# Registers a proc that will run after Cucumber is configured. You can register as
# as you want (typically from ruby scripts under <tt>support/hooks.rb</tt>).
#
# DEPRECATED: please use InstallPlugin or BeforeAll instead
def AfterConfiguration(&proc)
Dsl.register_rb_hook('after_configuration', [], proc)
end

# Registers a proc that will run after Cucumber is configured in order to install an external plugin.
def InstallPlugin(&proc)
Dsl.register_rb_hook('install_plugin', [], proc)
Expand Down
16 changes: 0 additions & 16 deletions lib/cucumber/glue/registry_and_more.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ def end_scenario
@current_world = nil
end

def after_configuration(configuration)
deprecate_after_configuration_hook if hooks[:after_configuration].any?

hooks[:after_configuration].each do |hook|
hook.invoke('AfterConfiguration', configuration)
end
end

def install_plugin(configuration, registry)
hooks[:install_plugin].each do |hook|
hook.invoke('InstallPlugin', [configuration, registry])
Expand Down Expand Up @@ -230,14 +222,6 @@ def invoked_step_definition_hash
def hooks
@hooks ||= Hash.new { |h, k| h[k] = [] }
end

def deprecate_after_configuration_hook
Cucumber.deprecate(
'See https://github.com/cucumber/cucumber-ruby/blob/main/UPGRADING.md#upgrading-to-710 for more info',
' AfterConfiguration hook',
'8.0.0'
)
end
end

def self.backtrace_line(proc, name)
Expand Down
5 changes: 0 additions & 5 deletions lib/cucumber/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def run!
)

load_step_definitions
fire_after_configuration_hook
fire_install_plugin_hook
fire_before_all_hook unless dry_run?
# TODO: can we remove this state?
Expand Down Expand Up @@ -113,10 +112,6 @@ def doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0

private

def fire_after_configuration_hook # :nodoc:
@support_code.fire_hook(:after_configuration, @configuration)
end

def fire_install_plugin_hook # :nodoc:
@support_code.fire_hook(:install_plugin, @configuration, registry_wrapper)
end
Expand Down
16 changes: 0 additions & 16 deletions spec/cucumber/glue/registry_and_more_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,6 @@ class << registry.current_world
expect(scenario).to receive(:accept_hook?).with(b) { false }
expect(registry.hooks_for(:around, scenario)).to eq [a]
end

it 'shows a deprecation warning for after_configuration hooks' do
stub_const('Cucumber::Deprecate::STRATEGY', Cucumber::Deprecate::ForUsers)
allow($stdout).to receive(:puts)

dsl.AfterConfiguration() {}

registry.after_configuration(nil)

expect($stdout).to have_received(:puts).with(
a_string_including([
'WARNING: # AfterConfiguration hook is deprecated and will be removed after version 8.0.0.',
'See https://github.com/cucumber/cucumber-ruby/blob/main/UPGRADING.md#upgrading-to-710 for more info.'
].join(' '))
)
end
end
end
end
Expand Down

0 comments on commit a7e6855

Please sign in to comment.