Class: Spec::Matchers::RaiseError
- Defined in:
- lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #eval_block ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected_error_or_message = Exception, expected_message = nil, &block) ⇒ RaiseError
constructor
A new instance of RaiseError.
- #matches?(given_proc) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #verify_message ⇒ Object
Constructor Details
#initialize(expected_error_or_message = Exception, expected_message = nil, &block) ⇒ RaiseError
Returns a new instance of RaiseError.
4 5 6 7 8 9 10 11 12 |
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb', line 4 def initialize(=Exception, =nil, &block) @block = block case when String, Regexp @expected_error, @expected_message = Exception, else @expected_error, @expected_message = , end end |
Instance Method Details
#description ⇒ Object
66 67 68 |
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb', line 66 def description "raise #{expected_error}" end |
#eval_block ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb', line 37 def eval_block @eval_block = true begin @block[@given_error] @eval_block_passed = true rescue Exception => err @given_error = err end end |
#failure_message ⇒ Object
58 59 60 |
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb', line 58 def @eval_block ? @given_error. : "expected #{expected_error}#{given_error}" end |
#matches?(given_proc) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb', line 14 def matches?(given_proc) @raised_expected_error = false @with_expected_message = false @eval_block = false @eval_block_passed = false begin given_proc.call rescue @expected_error => @given_error @raised_expected_error = true @with_expected_message = rescue Exception => @given_error # This clause should be empty, but rcov will not report it as covered # unless something (anything) is executed within the clause rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0" end unless negative_expectation? eval_block if @raised_expected_error && @with_expected_message && @block end ensure return (@raised_expected_error && @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false end |
#negative_failure_message ⇒ Object
62 63 64 |
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/raise_error.rb', line 62 def "expected no #{expected_error}#{given_error}" end |