Class: RSpec::Steps::StepList
- Inherits:
-
Object
- Object
- RSpec::Steps::StepList
- Includes:
- Enumerable
- Defined in:
- lib/rspec-steps/step-list.rb
Instance Attribute Summary collapse
-
#steps ⇒ Object
Returns the value of attribute steps.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #add(step) ⇒ Object (also: #<<)
- #add_let(name, block) ⇒ Object
- #add_let_bang(name) ⇒ Object
- #capture_result(step, context_example, running_example) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ StepList
constructor
A new instance of StepList.
-
#let_memo(name, example) ⇒ Object
In this case, we scope the caching of a let block to an example - which since the whole step list runs in a single example is fine.
- #result_for(step) ⇒ Object
- #run_only_once(context_example, running_example) ⇒ Object
Constructor Details
#initialize ⇒ StepList
Returns a new instance of StepList.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rspec-steps/step-list.rb', line 7 def initialize @steps = [] @let_bangs = [] @let_blocks = {} @let_memos = Hash.new do |h,example| h[example] = Hash.new do |h, let_name| h[let_name] = example.instance_eval(&@let_blocks.fetch(let_name)) end end @results = nil end |
Instance Attribute Details
#steps ⇒ Object
Returns the value of attribute steps.
18 19 20 |
# File 'lib/rspec-steps/step-list.rb', line 18 def steps @steps end |
Instance Method Details
#+(other) ⇒ Object
41 42 43 44 45 |
# File 'lib/rspec-steps/step-list.rb', line 41 def +(other) result = StepList.new result.steps = steps + other.steps result end |
#add(step) ⇒ Object Also known as: <<
36 37 38 |
# File 'lib/rspec-steps/step-list.rb', line 36 def add(step) @steps << step end |
#add_let(name, block) ⇒ Object
20 21 22 |
# File 'lib/rspec-steps/step-list.rb', line 20 def add_let(name, block) @let_blocks[name] = block end |
#add_let_bang(name) ⇒ Object
32 33 34 |
# File 'lib/rspec-steps/step-list.rb', line 32 def add_let_bang(name) @let_bangs << name end |
#capture_result(step, context_example, running_example) ⇒ Object
78 79 80 81 82 |
# File 'lib/rspec-steps/step-list.rb', line 78 def capture_result(step, context_example, running_example) StepResult.new(step, step.run_inside(context_example, running_example), nil, nil) rescue BasicObject => ex StepResult.new(step, nil, ex, nil) end |
#each(&block) ⇒ Object
47 48 49 |
# File 'lib/rspec-steps/step-list.rb', line 47 def each(&block) @steps.each(&block) end |
#let_memo(name, example) ⇒ Object
In this case, we scope the caching of a let block to an example - which since the whole step list runs in a single example is fine. It would be more correct to build a result-set and cache lets there.
28 29 30 |
# File 'lib/rspec-steps/step-list.rb', line 28 def let_memo(name, example) @let_memos[example][name] end |
#result_for(step) ⇒ Object
51 52 53 |
# File 'lib/rspec-steps/step-list.rb', line 51 def result_for(step) @results[step] end |
#run_only_once(context_example, running_example) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rspec-steps/step-list.rb', line 55 def run_only_once(context_example, running_example) return unless @results.nil? failed_step = nil @let_bangs.each do |let_name| context_example.__send__(let_name) end @results = Hash[ @steps.map do |step| [ step, if failed_step.nil? result = capture_result(step, context_example, running_example) if result.failed? failed_step = result end result else StepResult.new(step, nil, nil, failed_step) end ] end ] end |