Class: Retrospec::Puppet::RspecDumperFull

Inherits:
RspecDumper
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb

Instance Attribute Summary

Attributes inherited from RspecDumper

#var_store

Instance Method Summary collapse

Methods inherited from RspecDumper

#add_var_to_store, #dump_Array, #dump_AssignmentExpression, #dump_BlockExpression, #dump_HostClassDefinition, #dump_LiteralInteger, #dump_Parameter, #dump_ResourceExpression, #dump_ResourceTypeDefinition, #dump_Resource_Relationship, #dump_VariableExpression, #dump_top_scope_vars, #dump_transform, #format, #format_r, #indent, #logger, #lookup_var, #method_missing, #normalize_key, #top_scope_vars

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Retrospec::Puppet::RspecDumper

Instance Method Details

#dump_AccessExpression(o) ⇒ Object

x prints as (slice x y)



139
140
141
142
143
144
145
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 139

def dump_AccessExpression o
  if o.keys.size <= 1
    ["slice", do_dump(o.left_expr), do_dump(o.keys[0])]
  else
    ["slice", do_dump(o.left_expr), do_dump(o.keys)]
  end
end

#dump_AndExpression(o) ⇒ Object



191
192
193
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 191

def dump_AndExpression o
  ["&&", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_Application(o) ⇒ Object



130
131
132
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 130

def dump_Application o
  ["application", o.name, do_dump(o.parameters), do_dump(o.body)]
end

#dump_ArithmeticExpression(o) ⇒ Object



134
135
136
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 134

def dump_ArithmeticExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_AttributeOperation(o) ⇒ Object

Produces (name => expr) or (name +> expr)



112
113
114
115
116
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 112

def dump_AttributeOperation o
  key = o.attribute_name
  value = do_dump(o.value_expr) || nil
  [key.inspect, o.operator, "#{value},"]
end

#dump_AttributesOperation(o) ⇒ Object



203
204
205
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 203

def dump_AttributesOperation o
  ['* =>', do_dump(o.expr)]
end

#dump_CallMethodExpression(o) ⇒ Object



98
99
100
101
102
103
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 98

def dump_CallMethodExpression o
  result = [o.rval_required ? "call-method" : "invoke-method", do_dump(o.functor_expr)]
  o.arguments.collect {|a| result << do_dump(a) }
  result << do_dump(o.lambda) if o.lambda
  result
end

#dump_CallNamedFunctionExpression(o) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 89

def dump_CallNamedFunctionExpression o
  func_name = dump o.functor_expr
  args = o.arguments.collect {|a| do_dump(a) }.join(',')
  # because rspec-puppet cannot check if functions are called within a manifest
  # I don't think we can build a good test case here like
  # we could also mock the function here as well
  ["it { is_expected.to call(#{func_name}).with(#{args})}"]
end

#dump_CapabilityMapping(o) ⇒ Object



301
302
303
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 301

def dump_CapabilityMapping o
  [o.kind, do_dump(o.component), o.capability, do_dump(o.mappings)]
end

#dump_CaseExpression(o) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 12

def dump_CaseExpression o
  expr_name = dump(o.test.expr)
  expr_value = dump(o.test)
  result = ["describe '#{expr_name}'",:do]
  result << ['let(:params)',:do]
  #TODO figure out if the expr_name is a param and than we can mock it here
  result << 'params.merge({})' # merge in the parent level params
  result << [:end]
  result << [:break,'let(:facts)', :do]
  result << [:end]
  o.options.each do |s|
    result << :break << do_dump(s)
  end
  result << :dedent
end

#dump_CaseOption(o) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 28

def dump_CaseOption o
  expr_name = dump(o.eContainer.test.expr)
  expr_value = dump(o.eContainer.test)
  result = []
  o.values.each do |x|
    test_name = do_dump(x)
    result << ["context #{test_name}", :do]
    result << [do_dump(o.then_expr)]
  end
  result << [:end]
  result
end

#dump_CollectExpression(o) ⇒ Object



151
152
153
154
155
156
157
158
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 151

def dump_CollectExpression o
  result = ["collect", do_dump(o.type_expr), :indent, :break, do_dump(o.query), :indent]
  o.operations do |ao|
    result << :break << do_dump(ao)
  end
  result += [:dedent, :dedent ]
  result
end

#dump_ComparisonExpression(o) ⇒ Object



187
188
189
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 187

def dump_ComparisonExpression o
  "#{dump(o.left_expr)} #{o.operator} #{dump o.right_expr}"
end

#dump_ConcatenatedString(o) ⇒ Object

Interpolated strings are shown as (cat seg0 seg1 … segN)



80
81
82
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 80

def dump_ConcatenatedString o
  o.segments.collect {|x| do_dump(x)}
end

#dump_EppExpression(o) ⇒ Object



160
161
162
163
164
165
166
167
168
169
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 160

def dump_EppExpression o
  result = ["epp"]
  #    result << ["parameters"] + o.parameters.collect {|p| do_dump(p) } if o.parameters.size() > 0
  if o.body
    result << do_dump(o.body)
  else
    result << []
  end
  result
end

#dump_ExportedQuery(o) ⇒ Object



171
172
173
174
175
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 171

def dump_ExportedQuery o
  result = ["<<| |>>"]
  result += dump_QueryExpression(o) unless is_nop?(o.expr)
  result
end

#dump_Factory(o) ⇒ Object



126
127
128
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 126

def dump_Factory o
  do_dump(o.current)
end

#dump_HeredocExpression(o) ⇒ Object



275
276
277
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 275

def dump_HeredocExpression(o)
  result = ["@(#{o.syntax})", :indent, :break, do_dump(o.text_expr), :dedent, :break]
end

#dump_IfExpression(o) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 61

def dump_IfExpression o
  # this should be a test becuase if its function
  #Puppet::Pops::Model::CallNamedFunctionExpression
  case o.test
  when ::Puppet::Pops::Model::ComparisonExpression
    test_name = dump(o.test)
  when ::Puppet::Pops::Model::CallNamedFunctionExpression
    test_name = "#{dump(o.test.functor_expr)}(#{o.test.arguments.collect { |a| dump(a.expr)}})"
  end
  result << ["context #{test_name}", :do]
  then_name = do_dump(o.then_expr)
  result << then_name
  else_name = do_dump(o.else_expr) unless is_nop? o.else_expr
  result << else_name
  result << [:end]
  result
end

#dump_InExpression(o) ⇒ Object



199
200
201
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 199

def dump_InExpression o
  ["in", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_KeyedEntry(o) ⇒ Object



216
217
218
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 216

def dump_KeyedEntry o
  [do_dump(o.key), do_dump(o.value)]
end

#dump_LambdaExpression(o) ⇒ Object



228
229
230
231
232
233
234
235
236
237
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 228

def dump_LambdaExpression o
  result = ["lambda"]
  result << ["parameters"] + o.parameters.collect {|p| do_dump(p) } if o.parameters.size > 0
  if o.body
    result << do_dump(o.body)
  else
    result << []
  end
  result
end

#dump_LiteralDefault(o) ⇒ Object



239
240
241
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 239

def dump_LiteralDefault o
  ":default"
end

#dump_LiteralFloat(o) ⇒ Object



118
119
120
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 118

def dump_LiteralFloat o
  o.value.to_s
end

#dump_LiteralHash(o) ⇒ Object



211
212
213
214
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 211

def dump_LiteralHash o
  data = o.entries.collect {|x| do_dump(x)}
  Hash[*data.flatten]
end

#dump_LiteralList(o) ⇒ Object



207
208
209
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 207

def dump_LiteralList o
  o.values.collect {|x| do_dump(x)}
end

#dump_LiteralRegularExpression(o) ⇒ Object



247
248
249
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 247

def dump_LiteralRegularExpression o
  "/#{o.value.source}/"
end

#dump_LiteralString(o) ⇒ Object



224
225
226
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 224

def dump_LiteralString o
  "'#{o.value}'"
end

#dump_LiteralUndef(o) ⇒ Object



243
244
245
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 243

def dump_LiteralUndef o
  ":undef"
end

#dump_LiteralValue(o) ⇒ Object



122
123
124
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 122

def dump_LiteralValue o
  o.value.to_s
end

#dump_MatchesExpression(o) ⇒ Object



147
148
149
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 147

def dump_MatchesExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_MatchExpression(o) ⇒ Object



220
221
222
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 220

def dump_MatchExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_NamedAccessExpression(o) ⇒ Object



255
256
257
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 255

def dump_NamedAccessExpression o
  [".", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_NilClass(o) ⇒ Object



259
260
261
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 259

def dump_NilClass o
  ":undef"
end

#dump_NodeDefinition(o) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 279

def dump_NodeDefinition o
  result = ["node"]
  result << ["matches"] + o.host_matches.collect {|m| do_dump(m) }
  result << ["parent", do_dump(o.parent)] if o.parent
  if o.body
    result << do_dump(o.body)
  else
    result << []
  end
  result
end

#dump_Nop(o) ⇒ Object



251
252
253
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 251

def dump_Nop o
  ":nop"
end

#dump_NotExpression(o) ⇒ Object



263
264
265
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 263

def dump_NotExpression o
  ['!', dump(o.expr)]
end

#dump_Object(o) ⇒ Object



341
342
343
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 341

def dump_Object o
  [o.class.to_s, o.to_s]
end

#dump_OrExpression(o) ⇒ Object



195
196
197
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 195

def dump_OrExpression o
  ["||", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_ParenthesizedExpression(o) ⇒ Object



319
320
321
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 319

def dump_ParenthesizedExpression o
  do_dump(o.expr)
end

#dump_Program(o) ⇒ Object

Hides that Program exists in the output (only its body is shown), the definitions are just references to contained classes, resource types, and nodes



325
326
327
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 325

def dump_Program(o)
  dump(o.body)
end

#dump_QueryExpression(o) ⇒ Object



183
184
185
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 183

def dump_QueryExpression o
  [do_dump(o.expr)]
end

#dump_RelationshipExpression(o) ⇒ Object

defines the resource expression and outputs -> when used this would be the place to insert relationsip matchers



107
108
109
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 107

def dump_RelationshipExpression o
  [do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_RenderExpression(o) ⇒ Object



353
354
355
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 353

def dump_RenderExpression o
  ["render", do_dump(o.expr)]
end

#dump_RenderStringExpression(o) ⇒ Object



349
350
351
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 349

def dump_RenderStringExpression o
  ["render-s", " '#{o.value}'"]
end

#dump_ReservedWord(o) ⇒ Object



315
316
317
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 315

def dump_ReservedWord o
  [ 'reserved', o.word ]
end

#dump_ResourceBody(o) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 41

def dump_ResourceBody o
  type_name = do_dump(o.eContainer.type_name).gsub('::', '__')
  title = do_dump(o.title).inspect
  #TODO remove the :: from the front of the title if exists
  result = ['it', :do, "is_expected.to contain_#{type_name}(#{title})"]
  # this determies if we should use the with() or not
  if o.operations.count > 0
    result << [ :indent, :break,'.with({', :indent, :break]
    o.operations.each do |p|
      result << [do_dump(p), :break]
    end
    unless [::Puppet::Pops::Model::CallNamedFunctionExpression, ::Puppet::Pops::Model::BlockExpression].include?(o.eContainer.eContainer.class)
      result << dump_Resource_Relationship(o)
    end
    result << [ :dedent, :break, '})', :indent, :dedent, :dedent]
  end
  result << [:end, :break]
  result
end

#dump_ResourceDefaultsExpression(o) ⇒ Object



357
358
359
360
361
362
363
364
365
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 357

def dump_ResourceDefaultsExpression o
  form = o.form == :regular ? '' : o.form.to_s + "-"
  result = [form+"resource-defaults", do_dump(o.type_ref), :indent]
  o.operations.each do |p|
    result << :break << do_dump(p)
  end
  result << :dedent
  result
end

#dump_ResourceOverrideExpression(o) ⇒ Object



305
306
307
308
309
310
311
312
313
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 305

def dump_ResourceOverrideExpression o
  form = o.form == :regular ? '' : o.form.to_s + "-"
  result = [form+"override", do_dump(o.resources), :indent]
  o.operations.each do |p|
    result << :break << do_dump(p)
  end
  result << :dedent
  result
end

#dump_SelectorEntry(o) ⇒ Object



333
334
335
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 333

def dump_SelectorEntry o
  [do_dump(o.matching_expr), "=>", do_dump(o.value_expr)]
end

#dump_SelectorExpression(o) ⇒ Object



329
330
331
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 329

def dump_SelectorExpression o
  ["?", do_dump(o.left_expr)] + o.selectors.collect {|x| do_dump(x) }
end

#dump_SiteDefinition(o) ⇒ Object



291
292
293
294
295
296
297
298
299
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 291

def dump_SiteDefinition o
  result = ["site"]
  if o.body
    result << do_dump(o.body)
  else
    result << []
  end
  result
end

#dump_SubLocatedExpression(o) ⇒ Object



337
338
339
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 337

def dump_SubLocatedExpression o
  ["sublocated", do_dump(o.expr)]
end

#dump_TextExpression(o) ⇒ Object

Interpolation (to string) shown as (str expr)



85
86
87
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 85

def dump_TextExpression o
  [do_dump(o.expr)]
end

#dump_UnaryMinusExpression(o) ⇒ Object



267
268
269
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 267

def dump_UnaryMinusExpression o
  ['-', do_dump(o.expr)]
end

#dump_UnfoldExpression(o) ⇒ Object



271
272
273
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 271

def dump_UnfoldExpression o
  ['unfold', do_dump(o.expr)]
end

#dump_UnlessExpression(o) ⇒ Object



367
368
369
370
371
372
373
374
375
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 367

def dump_UnlessExpression o
  result = ["unless", do_dump(o.test), :indent, :break,
    ["then", :indent, do_dump(o.then_expr), :dedent]]
    result +=
    [:break,
      ["else", :indent, do_dump(o.else_expr), :dedent],
      :dedent] unless is_nop? o.else_expr
  result
end

#dump_VirtualQuery(o) ⇒ Object



177
178
179
180
181
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 177

def dump_VirtualQuery o
  result = ["<| |>"]
  result += dump_QueryExpression(o) unless is_nop?(o.expr)
  result
end

#is_nop?(o) ⇒ Boolean

Returns:

  • (Boolean)


345
346
347
# File 'lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb', line 345

def is_nop? o
  o.nil? || o.is_a?(::Puppet::Pops::Model::Nop)
end