Sha256: 03f18d1bab28c8d46f841c7bc8b722b9eba9579203858ec8aeb0b834107bb088

Contents?: true

Size: 651 Bytes

Versions: 14

Compression:

Stored size: 651 Bytes

Contents

RSpec::Matchers.define :fail_with_message do |expected|
  match do |block|
    @actual = nil

    begin
      block.call
    rescue RSpec::Expectations::ExpectationNotMetError => ex
      @actual = ex.message
    end

    @actual && @actual == expected
  end

  failure_message_for_should do
    msg = "Expectation should have failed with message '#{expected}'"

    if @actual
      msg << ", actually failed with '#{@actual}'"
    else
      msg << ", but did not fail."
    end

    msg
  end

  failure_message_for_should_not do
    msg  = "Expectation should not have failed with message '#{expected}'"
    msg << ", but did."

    msg
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
shoulda-matchers-2.6.2 spec/support/fail_with_message_matcher.rb
mcmire-shoulda-matchers-2.6.2.docs.1 spec/support/fail_with_message_matcher.rb
mcmire-shoulda-matchers-2.6.1.docs.1 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.6.1 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.6.1.rc2 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.6.1.rc1 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.6.0 spec/support/fail_with_message_matcher.rb
mcmire-shoulda-matchers-2.5.0 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.5.0 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.4.0 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.4.0.rc1 spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.3.0 spec/support/fail_with_message_matcher.rb
challah-1.0.0 vendor/bundle/gems/shoulda-matchers-2.2.0/spec/support/fail_with_message_matcher.rb
shoulda-matchers-2.2.0 spec/support/fail_with_message_matcher.rb