Class: Spec::Matchers::ThrowSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.11/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
8
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/throw_symbol.rb', line 5

def initialize(expected=nil)
  @expected = expected
  @actual = nil
end

Instance Method Details

#descriptionObject



41
42
43
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/throw_symbol.rb', line 41

def description
  "throw #{expected}"
end

#failure_messageObject



25
26
27
28
29
30
31
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/throw_symbol.rb', line 25

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

#matches?(given_proc) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/throw_symbol.rb', line 10

def matches?(given_proc)
  begin
    given_proc.call
  rescue NameError => e
    raise e unless e.message =~ /uncaught throw/
    @actual = e.name.to_sym
  ensure
    if @expected.nil?
      return @actual.nil? ? false : true
    else
      return @actual == @expected
    end
  end
end

#negative_failure_messageObject



33
34
35
36
37
38
39
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/throw_symbol.rb', line 33

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