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

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: 2cbb4df56947d1db97fd3a8dc56702f1a54549775d48a01c24aa2ca6d3466b44
4
- data.tar.gz: 9aae54a4a4e1f9d0586a3da995b1cd522bd1b49fdbd6ace31be7c3e145eba567
3
+ metadata.gz: 9201cae0c0d9e4823bc90ce3159757ed2171fd2a440d1a1179d37bd2482c9237
4
+ data.tar.gz: 385dba92ea4a772cdb897db40483451c624506d74cfeb87fd1eb5a2f9e657c79
5
5
  SHA512:
6
- metadata.gz: 1a383a45a80f7058b11c565e91bc783337d2b6f6a2e1d741492d9c159676f039a3e42cd25cb229939b93a82d174132da05810caa7be8310b2418675c79a0d445
7
- data.tar.gz: a30d834d32b46b724e4222dbb657a9151378ad775b6089cd40422d8844c328aad0c591078327ff8d5aef0c333988663bf2ec9e4b22e2e03773ab2bb850d70bb9
6
+ metadata.gz: 93b16c7d3c5eeeed2ffee8dd91cf0ff8ea7ff5cc8eef4bb1ab549d2dfa78f1deb2d3ad7708cc5f090f25e1c10613f34c23af447ea190583d60e35d023dcee174
7
+ data.tar.gz: 07ac2b1aaa4a98e87766f7de30307011811717627ed96879a7c12d3fe13de9f422e64291011ffc972bf0fdb8309cff04f5429fdc3c92de33f004896a66a5d0ee
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.6)
4
+ rspec-terraform (0.1.0.pre.9)
5
5
  rspec (>= 3.0)
6
- ruby-terraform (= 1.7.0.pre.3)
6
+ ruby-terraform (= 1.7.0.pre.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.3)
11
+ activesupport (7.0.3.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
@@ -30,7 +30,7 @@ GEM
30
30
  gem-release (2.2.2)
31
31
  hamster (3.0.0)
32
32
  concurrent-ruby (~> 1.0)
33
- i18n (1.10.0)
33
+ i18n (1.12.0)
34
34
  concurrent-ruby (~> 1.0)
35
35
  immutable-struct (2.4.1)
36
36
  json (2.6.2)
@@ -93,14 +93,14 @@ GEM
93
93
  rubocop-ast (>= 1.18.0, < 2.0)
94
94
  ruby-progressbar (~> 1.7)
95
95
  unicode-display_width (>= 1.4.0, < 3.0)
96
- rubocop-ast (1.18.0)
96
+ rubocop-ast (1.19.1)
97
97
  parser (>= 3.1.1.0)
98
98
  rubocop-rake (0.6.0)
99
99
  rubocop (~> 1.0)
100
100
  rubocop-rspec (2.12.1)
101
101
  rubocop (~> 1.31)
102
102
  ruby-progressbar (1.11.0)
103
- ruby-terraform (1.7.0.pre.3)
103
+ ruby-terraform (1.7.0.pre.5)
104
104
  immutable-struct (~> 2.4)
105
105
  lino (~> 3.0)
106
106
  ruby2_keywords (0.0.5)
data/Rakefile CHANGED
@@ -66,7 +66,7 @@ namespace :library do
66
66
  task check: [:rubocop]
67
67
 
68
68
  desc 'Attempt to automatically fix issues with the library'
69
- task fix: [:'rubocop:autocorrect']
69
+ task fix: [:'rubocop:autocorrect_all']
70
70
  end
71
71
 
72
72
  namespace :test do
@@ -8,10 +8,11 @@ require 'rspec/matchers/built_in/count_expectation'
8
8
  module RSpec
9
9
  module Terraform
10
10
  module Matchers
11
+ # rubocop:disable Metrics/ClassLength
11
12
  class IncludeResourceChange
12
13
  include RSpec::Matchers::BuiltIn::CountExpectation
13
14
 
14
- attr_reader :definition
15
+ attr_reader :definition, :plan
15
16
 
16
17
  def initialize(definition = {})
17
18
  @definition = definition
@@ -19,6 +20,7 @@ module RSpec
19
20
  end
20
21
 
21
22
  def matches?(plan)
23
+ @plan = plan
22
24
  matches = attribute_matches(plan)
23
25
 
24
26
  match_count = matches.count
@@ -36,6 +38,18 @@ module RSpec
36
38
  self
37
39
  end
38
40
 
41
+ def failure_message
42
+ "\nexpected: #{positive_expected_line}" \
43
+ "\n got: #{positive_got_line}" \
44
+ "\n available resource changes are:" \
45
+ "\n#{resource_change_lines}"
46
+ end
47
+
48
+ def failure_message_when_negated
49
+ "\nexpected: a plan including no resource changes" \
50
+ "\n got: a plan including at least one resource change"
51
+ end
52
+
39
53
  private
40
54
 
41
55
  def definition_matches(plan)
@@ -66,59 +80,78 @@ module RSpec
66
80
  def attribute_value(object, attribute)
67
81
  expected = attribute[:value]
68
82
  actual = object.dig(*attribute[:path])
69
- return actual&.value if expected.respond_to?(:matches?)
83
+ return actual&.unbox if expected.respond_to?(:matches?)
70
84
 
71
85
  actual
72
86
  end
87
+
88
+ def positive_expected_line
89
+ cardinality = cardinality_fragment
90
+ plurality = expected_count.nil? || expected_count == 1 ? '' : 's'
91
+ expected_line =
92
+ "a plan including #{cardinality} resource change#{plurality}"
93
+
94
+ unless @definition.empty?
95
+ expected_line =
96
+ "#{expected_line} matching definition:\n#{definition_lines}"
97
+ end
98
+
99
+ expected_line
100
+ end
101
+
102
+ def positive_got_line
103
+ if plan.resource_changes.empty?
104
+ 'a plan including no resource changes.'
105
+ else
106
+ count = attribute_matches(plan).count
107
+ amount = count.zero? ? 'no' : cardinality_amount(count)
108
+ plurality = count == 1 ? '' : 's'
109
+ "a plan including #{amount} matching resource change#{plurality}."
110
+ end
111
+ end
112
+
113
+ def cardinality_fragment
114
+ qualifier = cardinality_qualifier
115
+ amount = cardinality_amount(expected_count)
116
+ "#{qualifier} #{amount}"
117
+ end
118
+
119
+ def cardinality_qualifier
120
+ case count_expectation_type
121
+ when :<= then 'at most'
122
+ when nil, :>= then 'at least'
123
+ when :== then 'exactly'
124
+ when :<=> then 'between'
125
+ end
126
+ end
127
+
128
+ def cardinality_amount(count)
129
+ case count
130
+ when Range then "#{count.first} and #{count.last}"
131
+ when nil, 1 then 'one'
132
+ when 2 then 'two'
133
+ when 3 then 'three'
134
+ else count.to_s
135
+ end
136
+ end
137
+
138
+ def definition_lines
139
+ definition
140
+ .collect { |k, v| " #{k}: #{v}" }
141
+ .join("\n")
142
+ end
143
+
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})"
150
+ end
151
+ .join("\n")
152
+ end
73
153
  end
154
+ # rubocop:enable Metrics/ClassLength
74
155
  end
75
156
  end
76
157
  end
77
-
78
- # RSpec::Matchers.define :include_resource_creation do |type|
79
- # match do |plan|
80
- # resource_changes = plan.resource_changes_with_type(type)
81
- # resource_creations = resource_changes.filter(&:create?)
82
- #
83
- # return false if @count && resource_creations.length != @count
84
- # return false if resource_creations.empty?
85
- #
86
- # pp plan.to_h
87
- #
88
- # if @arguments
89
- # return resource_creations.any? do |resource_creation|
90
- # @arguments.all? do |name, value|
91
- # resource_creation.change.after[name] == value
92
- # end
93
- # end
94
- # end
95
- #
96
- # return true
97
- # end
98
- #
99
- # chain :count do |count|
100
- # @count = count
101
- # end
102
- #
103
- # chain :with_argument_value do |name, value|
104
- # @arguments = (@arguments || {}).merge(name => value)
105
- # end
106
- #
107
- # failure_message do |plan|
108
- # resource_creations = plan.resource_creations.map do |resource_creation|
109
- # "#{resource_creation.type}.#{resource_creation.name}"
110
- # end
111
- # "\nexpected: a plan with a resource creation for type: #{type}" \
112
- # "\n got: a plan with resource creations:" \
113
- # "\n - #{resource_creations.join("\n - ")}"
114
- # end
115
- #
116
- # failure_message_when_negated do |plan|
117
- # resource_creations = plan.resource_creations.map do |resource_creation|
118
- # "#{resource_creation.type}.#{resource_creation.name}"
119
- # end
120
- # "\nexpected: a plan without a resource creation for type: #{type}" \
121
- # "\n got: a plan with resource creations:" \
122
- # "\n - #{resource_creations.join("\n - ")}"
123
- # end
124
- # end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.6'
5
+ VERSION = '0.1.0.pre.9'
6
6
  end
7
7
  end
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.required_ruby_version = '>= 2.7'
39
39
 
40
40
  spec.add_dependency 'rspec', '>= 3.0'
41
- spec.add_dependency 'ruby-terraform', '1.7.0.pre.3'
41
+ spec.add_dependency 'ruby-terraform', '1.7.0.pre.5'
42
42
 
43
43
  spec.add_development_dependency 'bundler'
44
44
  spec.add_development_dependency 'faker'
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.6
4
+ version: 0.1.0.pre.9
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-17 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.7.0.pre.3
33
+ version: 1.7.0.pre.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.7.0.pre.3
40
+ version: 1.7.0.pre.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement