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
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #matches?(func_obj) ⇒ Boolean
- #with_params(*params) ⇒ Object
Instance Method Details
#and_raise_error(error_or_message, message = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rspec-puppet/matchers/run.rb', line 65 def and_raise_error(, =nil) case when String, Regexp @expected_error, = Exception, else @expected_error, = , end if .is_a? Regexp @desc = "raise an #{@expected_error} with the message matching #{@expected_error_message.inspect}" else @desc = "raise an #{@expected_error}" unless .nil? @desc += "with the message #{@expected_error_message.inspect}" end end self end |
#and_return(value) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/rspec-puppet/matchers/run.rb', line 55 def and_return(value) @expected_return = value if value.is_a? Regexp @desc = "match #{value.inspect}" else @desc = "return #{value.inspect}" end self end |
#description ⇒ Object
92 93 94 |
# File 'lib/rspec-puppet/matchers/run.rb', line 92 def description "run #{func_name}(#{func_params}) and #{@desc}" end |
#failure_message ⇒ Object
84 85 86 |
# File 'lib/rspec-puppet/matchers/run.rb', line 84 def (:should, @func_obj) end |
#failure_message_when_negated ⇒ Object
88 89 90 |
# File 'lib/rspec-puppet/matchers/run.rb', line 88 def (: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 43 44 45 46 47 48 |
# File 'lib/rspec-puppet/matchers/run.rb', line 4 def matches?(func_obj) @func_obj = 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 when nil result = true when Regexp result = =~ e. else result = == e. end end end result else unless @expected_return.nil? @actual_return = @func.call case @expected_return when Regexp @actual_return =~ @expected_return else @actual_return == @expected_return end else begin @func.call rescue false end true end end end |
#with_params(*params) ⇒ Object
50 51 52 53 |
# File 'lib/rspec-puppet/matchers/run.rb', line 50 def with_params(*params) @params = params self end |