Object
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 5 5: def initialize(expected_symbol = nil, expected_arg=nil) 6: @expected_symbol = expected_symbol 7: @expected_arg = expected_arg 8: @caught_symbol = @caught_arg = nil 9: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 63 63: def description 64: "throw #{expected}" 65: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 55 55: def failure_message_for_should 56: "expected #{expected} to be thrown, got #{caught}" 57: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 59 59: def failure_message_for_should_not 60: "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, got #{caught}" 61: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 11 11: def matches?(given_proc) 12: begin 13: if @expected_symbol.nil? 14: given_proc.call 15: else 16: @caught_arg = catch :proc_did_not_throw_anything do 17: catch @expected_symbol do 18: given_proc.call 19: throw :proc_did_not_throw_anything, :nothing_thrown 20: end 21: end 22: 23: if @caught_arg == :nothing_thrown 24: @caught_arg = nil 25: else 26: @caught_symbol = @expected_symbol 27: end 28: end 29: 30: # Ruby 1.8 uses NameError with `symbol' 31: # Ruby 1.9 uses ArgumentError with :symbol 32: rescue NameError, ArgumentError => e 33: unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/ 34: other_exception = e 35: raise 36: end 37: @caught_symbol = $2.to_sym 38: rescue => other_exception 39: raise 40: ensure 41: unless other_exception 42: if @expected_symbol.nil? 43: return !@caught_symbol.nil? 44: else 45: if @expected_arg.nil? 46: return @caught_symbol == @expected_symbol 47: else 48: return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg) 49: end 50: end 51: end 52: end 53: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 73 73: def caught 74: throw_description(@caught_symbol || 'nothing', @caught_arg) 75: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 69 69: def expected(symbol_desc = 'a Symbol') 70: throw_description(@expected_symbol || symbol_desc, @expected_arg) 71: end
# File lib/rspec/matchers/built_in/throw_symbol.rb, line 77 77: def throw_description(symbol, arg) 78: symbol_description = symbol.is_a?(String) ? symbol : symbol.inspect 79: 80: arg_description = if arg 81: " with #{arg.inspect}" 82: elsif @expected_arg && @caught_symbol == @expected_symbol 83: " with no argument" 84: else 85: "" 86: end 87: 88: symbol_description + arg_description 89: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.