Sha256: 5bad8b3c8417e47e2c63f73895513c60998563bd0fba613b595def0b5da40a2d

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module UnitTests
  module Matchers
    extend RSpec::Matchers::DSL

    matcher :fail_with_message_including do |expected|
      def supports_block_expectations?
        true
      end

      match do |block|
        @actual = nil

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

        @actual && @actual.include?(expected)
      end

      def failure_message
        msg = "Expectation should have failed with message including '#{expected}'"

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

        msg
      end

      def failure_message_for_should
        failure_message
      end

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

        msg
      end

      def failure_message_for_should_not
        failure_message_when_negated
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/spec/support/unit/matchers/fail_with_message_including_matcher.rb
shoulda-matchers-2.8.0 spec/support/unit/matchers/fail_with_message_including_matcher.rb
shoulda-matchers-2.8.0.rc2 spec/support/unit/matchers/fail_with_message_including_matcher.rb
shoulda-matchers-2.8.0.rc1 spec/support/unit/matchers/fail_with_message_including_matcher.rb