Sha256: e3eaaf451d04050e48ba35f31e4ebce5b2da9d67ac2878e4b09aa25a1014c548

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

Spec::Matchers.define :contain do |item|
  match do |arry|
    arry.include?(item)
  end
end

class ResponseContainsErrors
  def initialize(exception_class = nil)
    @exception_class = exception_class
  end

  def matches?(response)
    @response = response
    @exception = @response.template.controller.instance_variable_get("@exception")
    if !@exception_class
      !@exception.nil?
    else
      @exception.kind_of?(@exception_class)
    end
  end

  def failure_message_for_should
    expected_to("contain", @exception_class) + ", found " + found_instead
  end

  def failure_message_for_should_not
    expected_to("not contain", @exception_class) + ", found " + found_instead
  end

  private
  def expected_to(what, which)
    "Expected response to #{what}" + (which ? " (#{which})" : " an error")
  end

  def found_instead
    @exception ? "#{@exception.class.to_s} <#{@exception.message}>" : "none"
  end
end

def contain_errors(expected = nil)
  ResponseContainsErrors.new(expected)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rtml-2.0.4 spec/support/rspec/matchers.rb