Class: RSpec::Kwalify::HaveError
- Inherits:
-
Object
- Object
- RSpec::Kwalify::HaveError
- Defined in:
- lib/rspec-kwalify.rb
Overview
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object
-
#initialize(error, base_error = ::Kwalify::BaseError) ⇒ HaveError
constructor
A new instance of HaveError.
- #matches?(errors) ⇒ Boolean
Constructor Details
#initialize(error, base_error = ::Kwalify::BaseError) ⇒ HaveError
Returns a new instance of HaveError.
9 10 11 12 |
# File 'lib/rspec-kwalify.rb', line 9 def initialize(error, base_error=::Kwalify::BaseError) @error = error @base_error = base_error end |
Instance Method Details
#failure_message_for_should ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rspec-kwalify.rb', line 30 def msg = "expected errors to contain '%s' but was '%s'" if @error.nil? errors = @errors.map { |e| e.class.name }.uniq msg % [@base_error, errors.join(", ")] elsif @error.is_a?(Regexp) errors = @errors.map { |e| e. }.uniq msg % [@error.source, errors.join(", ")] elsif @error.is_a?(Fixnum) "expected #{@error} errors, found #{@errors.size}" end end |
#matches?(errors) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rspec-kwalify.rb', line 14 def matches?(errors) @errors = errors if @error.nil? @errors.any? { |error| error.is_a?(@base_error) } elsif @error.is_a?(Regexp) @errors.any? do |error| error.is_a?(@base_error) && error..match(@error) end elsif @error.is_a?(Fixnum) @errors.size == @error else raise ArgumentError, "don't know how to handle a #{@error.class}" end end |