You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When namespaced Worlds are used, after the first scenario runs all namespaced worlds change from being a valid Object to being nil. This has no impact on pure methods, but stateful methods (e.g. attr_accessor) break in unclear ways. This is currently not caught by the worlds test suite (features/docs/writing_support_code/world.feature), as it does not test stateful methods, nor multi-scenario features.
To Reproduce
Steps to reproduce the behavior:
Create a step definition file containing the following definitions:
moduleModuleOneattr_accessor:statedefpure42endendWorld(module_one: ModuleOne)Then/^module one is not nil$/doexpect(module_one).not_tobenilendThen/^state can be set$/doexpect{module_one.state=42}.not_toraise_errorendThen/^pure method can be called$/doexpect{module_one.pure}.not_toraise_errorend
Create a feature file containing the following scenarios:
Feature: Multi-scenario namespaced worlds which keep state stateScenario: 1. All checks passThen module one is not nil
Then state can be set
Then pure method can be called
Scenario: 2. Namespaced world becomes nilThen module one is not nil
Scenario: 3. Stateful methods do not workThen state can be set
Scenario: 4. Pure methods still workThen pure method can be called
Run the tests, and observe the results for the following scenarios:
1. All checks pass passes
2. Namespaced world becomes nil fails with expected not #<NilClass:8> => nil got #<NilClass:8> => nil
3. Stateful methods do not work fails with expected no Exception, got #<FrozenError: can't modify frozen NilClass: nil>
4. Pure methods still work passes
Expected behavior
It is expected that all scenarios pass, regardless of execution order, as well as that namespaced worlds can maintain state per-scenario, via standard Ruby patterns such as attr_accessor.
Context & Motivation
Looking at using namespaced worlds to provide an up-front declaration of my test suites state, rather than relying on instance variables.
Additional context
This issue does not appear to be a problem with non-namespaced worlds, i.e. both scenarios would run if World(ModuleOne) was used, and the module_one. namespace dropped from the step definitions.
The behaviour can be resolved if all namespaced modules are explicitly undefined after each scenario (i.e. via an After hook). This was traced back to lib/cucumber/glue/proto_world.rb in add_namespaced_modules!, lines 189 - 193:
It can also be resolved if the conditional is replaced with just Object.new.
I believe that after the first scenario executes, the instance variable "@__#{namespace}_world" is set to nil alongside all other global state, but is not reinitialized to a new valid Object. The modules methods are then defined on nil, which causes stateful methods to fail since nil is frozen.
The text was updated successfully, but these errors were encountered:
* Add a reproducible example for #1595
* Make sure module is valid before extending the world with it
* Update CHANGELOG.md
* Simplify world.feature
* Extend the world only if modules.any?
…assed (#1606)
* Add a reproducible example for #1595
* Make sure module is valid before extending the world with it
* Update CHANGELOG.md
* Simplify world.feature
* Extend the world only if modules.any?
* Add reproducible example
* Add status of the run when emitting TestRunFinished
* Fix TestRunFinished.success message in the message builder
* Update CHANGELOG.md
* Update example to remove failing step actually not failing
* Add newline at the end of the feature file
* Make Runtime#failure? a real public method
Describe the bug
When namespaced Worlds are used, after the first scenario runs all namespaced worlds change from being a valid
Object
to beingnil
. This has no impact on pure methods, but stateful methods (e.g.attr_accessor
) break in unclear ways. This is currently not caught by the worlds test suite (features/docs/writing_support_code/world.feature
), as it does not test stateful methods, nor multi-scenario features.To Reproduce
Steps to reproduce the behavior:
1. All checks pass
passes2. Namespaced world becomes nil
fails withexpected not #<NilClass:8> => nil got #<NilClass:8> => nil
3. Stateful methods do not work
fails withexpected no Exception, got #<FrozenError: can't modify frozen NilClass: nil>
4. Pure methods still work
passesExpected behavior
It is expected that all scenarios pass, regardless of execution order, as well as that namespaced worlds can maintain state per-scenario, via standard Ruby patterns such as
attr_accessor
.Context & Motivation
Looking at using namespaced worlds to provide an up-front declaration of my test suites state, rather than relying on instance variables.
Screenshots
N/A
Your Environment
Additional context
This issue does not appear to be a problem with non-namespaced worlds, i.e. both scenarios would run if
World(ModuleOne)
was used, and themodule_one.
namespace dropped from the step definitions.The behaviour can be resolved if all namespaced modules are explicitly undefined after each scenario (i.e. via an
After
hook). This was traced back tolib/cucumber/glue/proto_world.rb
inadd_namespaced_modules!
, lines 189 - 193:It can also be resolved if the conditional is replaced with just
Object.new
.I believe that after the first scenario executes, the instance variable
"@__#{namespace}_world"
is set to nil alongside all other global state, but is not reinitialized to a new valid Object. The modules methods are then defined onnil
, which causes stateful methods to fail sincenil
is frozen.The text was updated successfully, but these errors were encountered: