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