Class: Spec::Matchers::ThrowSymbol
- Defined in:
- lib/spec/matchers/throw_symbol.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected = nil) ⇒ ThrowSymbol
constructor
A new instance of ThrowSymbol.
- #matches?(proc) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected = nil) ⇒ ThrowSymbol
Returns a new instance of ThrowSymbol.
5 6 7 |
# File 'lib/spec/matchers/throw_symbol.rb', line 5 def initialize(expected=nil) @expected = expected end |
Instance Method Details
#description ⇒ Object
39 40 41 |
# File 'lib/spec/matchers/throw_symbol.rb', line 39 def description "throw #{expected}" end |
#failure_message ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/spec/matchers/throw_symbol.rb', line 23 def if @actual "expected #{expected}, got #{@actual.inspect}" else "expected #{expected} but nothing was thrown" end end |
#matches?(proc) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spec/matchers/throw_symbol.rb', line 9 def matches?(proc) begin proc.call rescue NameError => e @actual = extract_sym_from_name_error(e) ensure if @expected.nil? return @actual.nil? ? false : true else return @actual == @expected end end end |
#negative_failure_message ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/spec/matchers/throw_symbol.rb', line 31 def if @expected "expected #{expected} not to be thrown" else "expected no Symbol, got :#{@actual}" end end |