Class: Inspec::ExpectationTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, &block) ⇒ ExpectationTarget

Returns a new instance of ExpectationTarget.



13
14
15
16
17
# File 'lib/inspec/rule.rb', line 13

def initialize(value, &block)
  @value = value
  @block = block
  @calls = []
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



12
13
14
# File 'lib/inspec/rule.rb', line 12

def block
  @block
end

#callsObject (readonly)

Returns the value of attribute calls.



12
13
14
# File 'lib/inspec/rule.rb', line 12

def calls
  @calls
end

#valueObject (readonly)

Returns the value of attribute value.



12
13
14
# File 'lib/inspec/rule.rb', line 12

def value
  @value
end

Instance Method Details

#example_groupObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/inspec/rule.rb', line 27

def example_group
  that = self

  opts = { 'caller' => calls[0][3] }
  if !calls[0][3].nil? && !calls[0][3].empty? &&
     (m = calls[0][3][0].match(/^([^:]*):(\d+):/))
    opts['file_path'] = m[0]
    opts['line_number'] = m[1]
  end

  RSpec::Core::ExampleGroup.describe(that.value, opts) do
    that.calls.each do |method, args, block, clr|
      it(nil, caller: clr) do
        x = expect(that.value, &that.block).method(method)
        x.call(*args, &block)
      end
    end
  end
end

#not_to(*args, &block) ⇒ Object



23
24
25
# File 'lib/inspec/rule.rb', line 23

def not_to(*args, &block)
  @calls.push([:not_to, args, block, caller])
end

#to(*args, &block) ⇒ Object



19
20
21
# File 'lib/inspec/rule.rb', line 19

def to(*args, &block)
  @calls.push([:to, args, block, caller])
end