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
# File 'lib/turnip/rspec.rb', line 42

def run_step(feature_file, step)
  begin
    instance_eval <<-EOS, feature_file, step.line
      step(step)
    EOS
  rescue Turnip::Pending => e
    # This is kind of a hack, but it will make RSpec throw way nicer exceptions
    example = Turnip::RSpec.fetch_current_example(self)
    example.[:line_number] = step.line
    example.[:location] = "#{example.[:file_path]}:#{step.line}"

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

    if ::RSpec::Version::STRING >= '2.99.0'
      skip("No such step: '#{e}'")
    else
      pending("No such step: '#{e}'")
    end
  rescue StandardError, ::RSpec::Expectations::ExpectationNotMetError => e
    e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
    raise e
  end
end