Class: Spec::Matchers::ThrowSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/throw_symbol.rb

Overview

:nodoc:

Instance Method Summary collapse

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

#descriptionObject



39
40
41
# File 'lib/spec/matchers/throw_symbol.rb', line 39

def description
  "throw #{expected}"
end

#failure_messageObject



23
24
25
26
27
28
29
# File 'lib/spec/matchers/throw_symbol.rb', line 23

def failure_message
  if @actual
    "expected #{expected}, got #{@actual.inspect}"
  else
    "expected #{expected} but nothing was thrown"
  end
end

#matches?(proc) ⇒ Boolean

Returns:

  • (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_messageObject



31
32
33
34
35
36
37
# File 'lib/spec/matchers/throw_symbol.rb', line 31

def negative_failure_message
  if @expected
    "expected #{expected} not to be thrown"
  else
    "expected no Symbol, got :#{@actual}"
  end
end