Class: RSpec::Puppet::FunctionMatchers::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-puppet/matchers/run.rb

Instance Method Summary collapse

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(error_or_message, message=nil)
  case error_or_message
  when String, Regexp
    @expected_error, @expected_error_message = Exception, error_or_message
  else
    @expected_error, @expected_error_message = error_or_message, 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 failure_message_for_should(func_obj)
  failure_message_generic(: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 failure_message_for_should_not(func_obj)
  failure_message_generic(:should_not, func_obj)
end

#matches?(func_obj) ⇒ Boolean

Returns:

  • (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.message
        else
          result = @expected_error_message == e.message
        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