Class: RSpec::Terraform::Matchers::IncludeResourceChange

Inherits:
Object
  • Object
show all
Includes:
Matchers::BuiltIn::CountExpectation
Defined in:
lib/rspec/terraform/matchers/include_resource_change.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition = {}) ⇒ IncludeResourceChange

Returns a new instance of IncludeResourceChange.



20
21
22
23
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 20

def initialize(definition = {})
  @definition = definition
  @attributes = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



18
19
20
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 18

def attributes
  @attributes
end

#definitionObject (readonly)

Returns the value of attribute definition.



18
19
20
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 18

def definition
  @definition
end

#planObject (readonly)

Returns the value of attribute plan.



18
19
20
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 18

def plan
  @plan
end

Instance Method Details

#failure_messageObject



46
47
48
49
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 46

def failure_message
  "\nexpected: #{positive_expected_line}" \
    "\n     got: #{positive_got_line}"
end

#matches?(plan) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 25

def matches?(plan)
  @plan = plan
  matches = attribute_matches(plan)

  match_count = matches.count
  if has_expected_count?
    expected_count_matches?(match_count)
  else
    match_count.positive?
  end
end

#with_attribute_value(*args) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rspec/terraform/matchers/include_resource_change.rb', line 37

def with_attribute_value(*args)
  stage, path, value = args.count == 3 ? args : [:after, *args]
  path = [path] if path.is_a?(Symbol)
  path = RubyTerraform::Models::Path.new(path)
  value = maybe_box_value(value)
  @attributes << { stage: stage, path: path, value: value }
  self
end