rspec-terraform 0.1.0.pre.9 → 0.1.0.pre.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9201cae0c0d9e4823bc90ce3159757ed2171fd2a440d1a1179d37bd2482c9237
4
- data.tar.gz: 385dba92ea4a772cdb897db40483451c624506d74cfeb87fd1eb5a2f9e657c79
3
+ metadata.gz: f8c0ef1824e2c32907a06a34ab775ab0004a9ddf57ab22c5b2baeb40812eb4df
4
+ data.tar.gz: af62f1d916db8ea95f186bb44903bd52641787c270b6c0e1fa7bf6073482204e
5
5
  SHA512:
6
- metadata.gz: 93b16c7d3c5eeeed2ffee8dd91cf0ff8ea7ff5cc8eef4bb1ab549d2dfa78f1deb2d3ad7708cc5f090f25e1c10613f34c23af447ea190583d60e35d023dcee174
7
- data.tar.gz: 07ac2b1aaa4a98e87766f7de30307011811717627ed96879a7c12d3fe13de9f422e64291011ffc972bf0fdb8309cff04f5429fdc3c92de33f004896a66a5d0ee
6
+ metadata.gz: 3a2638bb48081a61c55f716459873c66e7bb3e730e80561ddff0605bcbbd48e67cc56498ce7a343747d08d80bdccd6536203b53728163562fd272ca0d4debc37
7
+ data.tar.gz: 26e7621f75e736abc0e0ba5a036513c4f6d32b2ae3cfd16ba357fe3c956b566773b2756963fba41cae6c57e9537b6af4d124db93beb5f6c3f4971d2e213e8fae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.9)
4
+ rspec-terraform (0.1.0.pre.10)
5
5
  rspec (>= 3.0)
6
6
  ruby-terraform (= 1.7.0.pre.5)
7
7
 
@@ -12,7 +12,7 @@ module RSpec
12
12
  class IncludeResourceChange
13
13
  include RSpec::Matchers::BuiltIn::CountExpectation
14
14
 
15
- attr_reader :definition, :plan
15
+ attr_reader :definition, :attributes, :plan
16
16
 
17
17
  def initialize(definition = {})
18
18
  @definition = definition
@@ -40,9 +40,7 @@ module RSpec
40
40
 
41
41
  def failure_message
42
42
  "\nexpected: #{positive_expected_line}" \
43
- "\n got: #{positive_got_line}" \
44
- "\n available resource changes are:" \
45
- "\n#{resource_change_lines}"
43
+ "\n got: #{positive_got_line}"
46
44
  end
47
45
 
48
46
  def failure_message_when_negated
@@ -86,19 +84,38 @@ module RSpec
86
84
  end
87
85
 
88
86
  def positive_expected_line
87
+ maybe_with_expected_attributes(
88
+ maybe_with_definition(
89
+ positive_plan_line
90
+ )
91
+ )
92
+ end
93
+
94
+ def positive_plan_line
89
95
  cardinality = cardinality_fragment
90
96
  plurality = expected_count.nil? || expected_count == 1 ? '' : 's'
91
- expected_line =
92
- "a plan including #{cardinality} resource change#{plurality}"
93
97
 
98
+ "a plan including #{cardinality} resource change#{plurality}"
99
+ end
100
+
101
+ def maybe_with_definition(expected_line)
94
102
  unless @definition.empty?
95
103
  expected_line =
96
104
  "#{expected_line} matching definition:\n#{definition_lines}"
97
105
  end
106
+ expected_line
107
+ end
98
108
 
109
+ def maybe_with_expected_attributes(expected_line)
110
+ unless @attributes.empty?
111
+ expected_line =
112
+ "#{expected_line}\n with attribute values after " \
113
+ "the resource change is applied of:\n#{expected_attribute_lines}"
114
+ end
99
115
  expected_line
100
116
  end
101
117
 
118
+ # rubocop:disable Metrics/MethodLength
102
119
  def positive_got_line
103
120
  if plan.resource_changes.empty?
104
121
  'a plan including no resource changes.'
@@ -106,9 +123,21 @@ module RSpec
106
123
  count = attribute_matches(plan).count
107
124
  amount = count.zero? ? 'no' : cardinality_amount(count)
108
125
  plurality = count == 1 ? '' : 's'
109
- "a plan including #{amount} matching resource change#{plurality}."
126
+ got_line =
127
+ "a plan including #{amount} matching " \
128
+ "resource change#{plurality}."
129
+
130
+ unless attributes.empty?
131
+ got_line =
132
+ "#{got_line}\n relevant resource changes are:" \
133
+ "\n#{relevant_resource_change_lines}"
134
+ end
135
+
136
+ "#{got_line}\n available resource changes are:" \
137
+ "\n#{available_resource_change_lines}"
110
138
  end
111
139
  end
140
+ # rubocop:enable Metrics/MethodLength
112
141
 
113
142
  def cardinality_fragment
114
143
  qualifier = cardinality_qualifier
@@ -136,21 +165,50 @@ module RSpec
136
165
  end
137
166
 
138
167
  def definition_lines
168
+ indent = ' '
139
169
  definition
140
- .collect { |k, v| " #{k}: #{v}" }
170
+ .collect { |k, v| "#{indent}#{k} = #{v.inspect}" }
141
171
  .join("\n")
142
172
  end
143
173
 
144
- def resource_change_lines
145
- plan.resource_changes
146
- .collect do |rc|
147
- address = rc.address
148
- actions = rc.change.actions.join(', ')
149
- " - #{address} (#{actions})"
174
+ def expected_attribute_lines
175
+ indent = ' '
176
+ attribute_fragments = attributes.collect do |a|
177
+ "#{indent}#{render(a[:path])} = #{a[:value].inspect}"
178
+ end
179
+ attribute_fragments.join("\n")
180
+ end
181
+
182
+ # rubocop:disable Metrics/MethodLength
183
+ def relevant_resource_change_lines
184
+ relevant_lines = definition_matches(plan).collect do |rc|
185
+ address = rc.address
186
+ actions = rc.change.actions.join(', ')
187
+ attributes = rc.change.after_object
188
+ attribute_lines = attributes.collect do |key, value|
189
+ " #{key} = #{value.inspect}"
150
190
  end
151
- .join("\n")
191
+ attribute_lines = attribute_lines.join("\n")
192
+ " - #{address} (#{actions})\n#{attribute_lines}"
193
+ end
194
+ relevant_lines.join("\n")
195
+ end
196
+ # rubocop:enable Metrics/MethodLength
197
+
198
+ def available_resource_change_lines
199
+ available_lines = plan.resource_changes.collect do |rc|
200
+ address = rc.address
201
+ actions = rc.change.actions.join(', ')
202
+ " - #{address} (#{actions})"
203
+ end
204
+ available_lines.join("\n")
205
+ end
206
+
207
+ def render(path)
208
+ path.collect { |elem| elem.to_s }.join(',')
152
209
  end
153
210
  end
211
+
154
212
  # rubocop:enable Metrics/ClassLength
155
213
  end
156
214
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.9'
5
+ VERSION = '0.1.0.pre.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.9
4
+ version: 0.1.0.pre.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-18 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec