Module: Gold::Coverage
- Defined in:
- lib/gold/coverage.rb
Overview
Captures coverage on Statesman state machines. Include this module into the ‘Statesman::Machine` subclass that you want to record usage for. Results may be accessed with `#coverage` on that class (not the instances).
Defined Under Namespace
Modules: ClassMethods Classes: Results, Transition
Class Method Summary collapse
-
.covered=(covered) ⇒ Object
Set whether we are collecting coverage information currently.
-
.covered? ⇒ Boolean
Whether or not we are collecting coverage information currently.
-
.exclude_from_coverage ⇒ Object
Execute a block and don’t include it in the coverage results.
- .included(klass) ⇒ Object
Instance Method Summary collapse
-
#transition_to!(new_state, metadata = {}) ⇒ Object
Override ‘#transition_to!` to observe the current state and the new state.
Class Method Details
.covered=(covered) ⇒ Object
Set whether we are collecting coverage information currently.
23 24 25 |
# File 'lib/gold/coverage.rb', line 23 def self.covered=(covered) @covered = covered end |
.covered? ⇒ Boolean
Whether or not we are collecting coverage information currently.
18 19 20 |
# File 'lib/gold/coverage.rb', line 18 def self.covered? @covered = @covered.nil? || @covered end |
.exclude_from_coverage ⇒ Object
Execute a block and don’t include it in the coverage results.
28 29 30 31 32 33 34 |
# File 'lib/gold/coverage.rb', line 28 def self.exclude_from_coverage original = covered? self.covered = false result = yield self.covered = original result end |
.included(klass) ⇒ Object
6 7 8 |
# File 'lib/gold/coverage.rb', line 6 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#transition_to!(new_state, metadata = {}) ⇒ Object
Override ‘#transition_to!` to observe the current state and the new state. Statesman’s callbacks do not currently allow for this, hence the need to intercept here. ‘#transition_to` calls `#transition_to!`, so it is sufficient to tap into `Statesman::Machine` at this one point.
80 81 82 83 84 85 86 87 |
# File 'lib/gold/coverage.rb', line 80 def transition_to!(new_state, = {}) initial_state = current_state super(new_state, ) if Gold::Coverage.covered? self.class.coverage.cover(initial_state.to_s, new_state.to_s) end true end |