Class: RSpec::Puppet::FunctionMatchers::Run
- Inherits:
-
Object
- Object
- RSpec::Puppet::FunctionMatchers::Run
- Defined in:
- lib/rspec-puppet/matchers/run.rb
Instance Method Summary collapse
- #and_raise_error(error_or_message, message = nil) ⇒ Object
- #and_return(value) ⇒ Object
- #failure_message_for_should(func_obj) ⇒ Object
- #failure_message_for_should_not(func_obj) ⇒ Object
- #matches?(func_obj) ⇒ Boolean
- #with_params(*params) ⇒ Object
Instance Method Details
#and_raise_error(error_or_message, message = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/rspec-puppet/matchers/run.rb', line 54 def and_raise_error(, =nil) case when String, Regexp @expected_error, @expected_error_message = Exception, else @expected_error, @expected_error_message = , end self end |
#and_return(value) ⇒ Object
49 50 51 52 |
# File 'lib/rspec-puppet/matchers/run.rb', line 49 def and_return(value) @expected_return = value self end |
#failure_message_for_should(func_obj) ⇒ Object
64 65 66 |
# File 'lib/rspec-puppet/matchers/run.rb', line 64 def (func_obj) (:should, func_obj) end |
#failure_message_for_should_not(func_obj) ⇒ Object
68 69 70 |
# File 'lib/rspec-puppet/matchers/run.rb', line 68 def (func_obj) (:should_not, func_obj) end |
#matches?(func_obj) ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rspec-puppet/matchers/run.rb', line 4 def matches?(func_obj) if @params @func = lambda { func_obj.call(@params) } else @func = lambda { func_obj.call } end unless @expected_error.nil? result = false begin @func.call rescue Exception => e @actual_error = e.class if e.is_a?(@expected_error) case @expected_error_message when nil result = true when Regexp result = @expected_error_message =~ e. else result = @expected_error_message == e. end end end result else unless @expected_return.nil? @actual_return = @func.call @actual_return == @expected_return else begin @func.call rescue false end true end end end |
#with_params(*params) ⇒ Object
44 45 46 47 |
# File 'lib/rspec-puppet/matchers/run.rb', line 44 def with_params(*params) @params = params self end |