Class: Hypercuke::Context
- Inherits:
-
Object
- Object
- Hypercuke::Context
- Extended by:
- Forwardable
- Defined in:
- lib/hypercuke/context.rb
Overview
I provide a way of passing state around between tests that isn’t instance variables.
This is handy even in plain old Cucumber-land (where if you typo an instance variable, you just get nil), and essential in a set of mostly-independent step adapter objects, each with their own private state.
Instance Method Summary collapse
-
#fetch_or_default(key, &block) ⇒ Object
-
And a variant of fetch that, if the key is not found, sets it for the next caller.
-
-
#initialize ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
12 13 14 |
# File 'lib/hypercuke/context.rb', line 12 def initialize @hash = {} end |
Instance Method Details
#fetch_or_default(key, &block) ⇒ Object
-
And a variant of fetch that, if the key is not found, sets it for the next caller.
This behavior is in the spirit of the ||= operator, except that it won’t short-circuit and call the default value if the key is present, but set to nil or false.
32 33 34 |
# File 'lib/hypercuke/context.rb', line 32 def fetch_or_default(key, &block) @hash[key] = @hash.fetch(key, &block) end |