Sha256: 9fb5a4cdce7c4ca41e67cf6e14ff5458841879c0d9afb37005fbb24b8f9ea193

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

RSpec::Matchers.define :require_parameter do |expected|
  match do |klass|
    @actual = nil

    begin
      klass.new
    rescue => ex
      @actual = ex
    end

    @actual &&
      @actual.is_a?(ArgumentError) &&
      @actual.message.match(matcher_for(expected))
  end

  def matcher_for(param)
    Regexp.new("missing keywords: .*?\\b#{param}\\b")
  end

  def failure_message
    msg = "The constructor should require #{expected}"

    if @actual
      if @actual.is_a?(ArgumentError) &&
         @actual.message.start_with?("missing keywords: ")
        m = /missing keywords: (.*)$/.match(@actual.message)
        msg << ", actually requires #{m[1]}"
      else
        msg << ", actually failed with the message '#{@actual.message}'"
      end
    else
      msg << ", but does not require any parameters."
    end

    msg
  end

  def failure_message_for_should
    failure_message
  end

  def failure_message_when_negated
    msg  = "FFFFFFUUUUUUUUUUUUUUUUUUUUUUUUU Block should not have failed with #{expected[:klass]}, with message including '#{expected[:message]}'"
    msg << ", but did."

    msg
  end

  def failure_message_for_should_not
    failure_message_when_negated
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-caching-proxy-0.1.4 spec/support/matchers/require_parameter.rb