module RSpec::PowerAssert

Constants

VERSION

Public Class Methods

example_assertion_alias(name) click to toggle source
# File lib/rspec/power_assert.rb, line 21
def self.example_assertion_alias(name)
  alias_method(name.to_sym, :is_asserted_by)
end
example_group_assertion_alias(name) click to toggle source
# File lib/rspec/power_assert.rb, line 25
def self.example_group_assertion_alias(name)
  PowerAssertExtensions.assertion_method_alias(name)
end
verbose_successful_report() click to toggle source
# File lib/rspec/power_assert.rb, line 13
def self.verbose_successful_report
  !!@verbose_successful_report
end
verbose_successful_report=(verbose) click to toggle source
# File lib/rspec/power_assert.rb, line 17
def self.verbose_successful_report=(verbose)
  @verbose_successful_report = verbose
end

Public Instance Methods

is_asserted_by(&blk) click to toggle source
# File lib/rspec/power_assert.rb, line 29
def is_asserted_by(&blk)
  result, msg = ::PowerAssert.start(blk, assertion_method: __callee__) do |tp|
    [tp.yield, tp.message_proc.call]
  end

  location = blk.source_location.join(":")
  handle_result_and_message(result, msg, __callee__, location)
end

Private Instance Methods

evaluate_example(method_name, &blk) click to toggle source
# File lib/rspec/power_assert.rb, line 40
def evaluate_example(method_name, &blk)
  # hack for context changing
  pr = -> { self.instance_exec(&blk) }

  result, msg = ::PowerAssert.start(pr, assertion_method: method_name) do |tp|
    [tp.yield, tp.message_proc.call]
  end

  location = blk.source_location.join(":")
  handle_result_and_message(result, msg, method_name, location)
end
handle_result_and_message(result, msg, method_name, location) click to toggle source
# File lib/rspec/power_assert.rb, line 52
def handle_result_and_message(result, msg, method_name, location)
  if result
    RSpec::Matchers.last_matcher = DummyAssertionMatcher.new(msg, method_name.to_s)

    if RSpec::Matchers.respond_to?(:last_should=)
      RSpec::Matchers.last_should = :should # for RSpec 2
    else
      RSpec::Matchers.last_expectation_handler = DummyExpectationHandler # for RSpec 3
    end
  else
    ex = RSpec::Expectations::ExpectationNotMetError.new(msg)

    if defined?(RSpec::Support) && RSpec::Support.respond_to?(:notify_failure)
      # for RSpec 3.3+
      RSpec::Support.notify_failure(ex)
    else
      # for RSpec 2, 3.0, 3.1, 3.2
      ex.set_backtrace(location)
      raise ex
    end
  end
end