class RSpec::Steps::StepList

Attributes

steps[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

+(other) click to toggle source
# File lib/rspec-steps/step-list.rb, line 41
def +(other)
  result = StepList.new
  result.steps = steps + other.steps
  result
end
<<(step)
Alias for: add
add(step) click to toggle source
# File lib/rspec-steps/step-list.rb, line 36
def add(step)
  @steps << step
end
Also aliased as: <<
add_let(name, block) click to toggle source
# File lib/rspec-steps/step-list.rb, line 20
def add_let(name, block)
  @let_blocks[name] = block
end
add_let_bang(name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rspec-steps/step-list.rb, line 47
def each(&block)
  @steps.each(&block)
end
let_memo(name, example) click to toggle source

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.

# File lib/rspec-steps/step-list.rb, line 28
def let_memo(name, example)
  @let_memos[example][name]
end
result_for(step) click to toggle source
# File lib/rspec-steps/step-list.rb, line 51
def result_for(step)
  @results[step]
end
run_only_once(context_example, running_example) click to toggle source
# 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