Module: Turnip::RSpec::Execute

Includes:
Execute
Defined in:
lib/turnip/rspec.rb

Overview

This module provides an improved method to run steps inside RSpec, adding proper support for pending steps, as well as nicer backtraces.

Instance Method Summary collapse

Methods included from Execute

#step

Instance Method Details

#run_step(feature_file, step) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/turnip/rspec.rb', line 42

def run_step(feature_file, step)
  reporter = ::RSpec.current_example.reporter
  reporter.publish(:step_started, { step: step })

  begin
    instance_eval <<-EOS, feature_file, step.line
      step(step)
    EOS
  rescue Turnip::Pending => e
    reporter.publish(:step_pending, { step: step })

    example = ::RSpec.current_example
    example.[:line_number] = step.line
    example.[:location] = "#{example.[:file_path]}:#{step.line}"

    missing_step_message = "No such step: '#{e}' #{feature_file}:#{step.line}"
    if ::RSpec.configuration.raise_error_for_unimplemented_steps
      e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
      raise e, missing_step_message
    end

    skip(missing_step_message)
  rescue StandardError, ::RSpec::Expectations::ExpectationNotMetError => e
    reporter.publish(:step_failed, { step: step })

    e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
    raise e
  end

  reporter.publish(:step_passed, { step: step })
end