Class: RaiseErrorMatcher
- Defined in:
- lib/extensions/rhospec/rhospec.rb,
lib/extensions/mspec/mspec/matchers/raise_error.rb
Instance Method Summary collapse
- #exception_class_and_message(exception_class, message) ⇒ Object
- #failure_message ⇒ Object
- #format_exception(exception) ⇒ Object
- #format_expected_exception ⇒ Object
-
#initialize(exception, message, &block) ⇒ RaiseErrorMatcher
constructor
A new instance of RaiseErrorMatcher.
- #matches?(proc) ⇒ Boolean
- #matching_exception?(exc) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(exception, message, &block) ⇒ RaiseErrorMatcher
Returns a new instance of RaiseErrorMatcher.
383 384 385 386 387 |
# File 'lib/extensions/rhospec/rhospec.rb', line 383 def initialize(exception, , &block) @exception = exception = @block = block end |
Instance Method Details
#exception_class_and_message(exception_class, message) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/extensions/mspec/mspec/matchers/raise_error.rb', line 38 def (exception_class, ) if "#{exception_class} (#{message})" else "#{exception_class}" end end |
#failure_message ⇒ Object
409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/extensions/rhospec/rhospec.rb', line 409 def = ["Expected #{@exception}#{%[ (#{@message})] if @message}"] if @actual then << "but got #{@actual.class}#{%[ (#{@actual.message})] if @actual.message}" else << "but no exception was raised" end end |
#format_exception(exception) ⇒ Object
50 51 52 |
# File 'lib/extensions/mspec/mspec/matchers/raise_error.rb', line 50 def format_exception(exception) (exception.class, exception.) end |
#format_expected_exception ⇒ Object
46 47 48 |
# File 'lib/extensions/mspec/mspec/matchers/raise_error.rb', line 46 def format_expected_exception (@exception, ) end |
#matches?(proc) ⇒ Boolean
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/extensions/rhospec/rhospec.rb', line 389 def matches?(proc) proc.call return false rescue Exception => err @actual = err return false unless @exception === @actual if then case when String then return false if != @actual. when Regexp then return false if !~ @actual. end end @block[@actual] if @block return true end |
#matching_exception?(exc) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/extensions/mspec/mspec/matchers/raise_error.rb', line 21 def matching_exception?(exc) return false unless @exception === exc if then case when String return false if != exc. when Regexp return false if !~ exc. end end # The block has its own expectations and will throw an exception if it fails @block[exc] if @block return true end |
#negative_failure_message ⇒ Object
421 422 423 |
# File 'lib/extensions/rhospec/rhospec.rb', line 421 def ["Expected to not get #{@exception}#{%[ (#{@message})] if @message}", ""] end |