Class: RSpec::Stepwise::Builder
- Inherits:
-
Object
- Object
- RSpec::Stepwise::Builder
- Defined in:
- lib/rspec/stepwise.rb
Overview
Provides DSL for steps definition and builds execution context.
Instance Method Summary collapse
-
#after(&block) ⇒ Object
Runs after all steps finished.
-
#initialize(klass) ⇒ Builder
constructor
A new instance of Builder.
-
#on_fail(&block) ⇒ Object
Runs if any step failed.
-
#step(*args, &block) ⇒ Object
Defines new step in a series.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
99 100 101 102 103 104 105 |
# File 'lib/rspec/stepwise.rb', line 99 def method_missing(name, *args, &block) if @klass.respond_to?(name) @klass.public_send(name, *args, &block) else super end end |
Instance Method Details
#after(&block) ⇒ Object
Runs after all steps finished.
90 91 92 93 94 95 |
# File 'lib/rspec/stepwise.rb', line 90 def after(&block) steps_context = @steps_context @klass.after(:all) do steps_context.run(&block) end end |
#on_fail(&block) ⇒ Object
Runs if any step failed. Can be executed multiple times. Execution will happen in the same order as definition order.
78 79 80 |
# File 'lib/rspec/stepwise.rb', line 78 def on_fail(&block) @fail_callbacks << block end |
#step(*args, &block) ⇒ Object
Defines new step in a series. Supports the same arguments as ‘RSpec::Core::ExampleGroup.it`.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rspec/stepwise.rb', line 46 def step(*args, &block) # `it` defines method within `klass`, so Builder's # instance variable will not be visible there, # so we use local var. steps_context = @steps_context fail_callbacks = @fail_callbacks @klass.it(*args) do if steps_context.previous_failed? pending 'Previous step failed' fail else begin steps_context.run_step(&block) rescue fail_callbacks.each do |callback| steps_context.run(&callback) end raise end end end end |