Class: DaVinciPlanNetTestKit::Generator::ReadTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/davinci_plan_net_test_kit/generator/read_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, base_output_dir) ⇒ ReadTestGenerator

Returns a new instance of ReadTestGenerator.



22
23
24
25
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 22

def initialize(, base_output_dir)
  self. = 
  self.base_output_dir = base_output_dir
end

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



20
21
22
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 20

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



20
21
22
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 20

def 
  @group_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



8
9
10
11
12
13
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 8

def generate(, base_output_dir)
  .groups
    .reject { |group| SpecialCases.exclude_group? group }
    .select { |group| read_interaction(group).present? }
    .each { |group| new(group, base_output_dir).generate }
end

.read_interaction(group_metadata) ⇒ Object



15
16
17
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 15

def read_interaction()
  .interactions.find { |interaction| interaction[:code] == 'read' }
end

Instance Method Details

#base_output_file_nameObject



35
36
37
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 35

def base_output_file_name
  "#{class_name.underscore}.rb"
end

#class_nameObject



59
60
61
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 59

def class_name
  "#{Naming.upper_camel_case_for_profile()}ReadTest"
end

#conformance_expectationObject



71
72
73
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 71

def conformance_expectation
  read_interaction[:expectation]
end

#generateObject



75
76
77
78
79
80
81
82
83
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 75

def generate
  FileUtils.mkdir_p(output_file_directory)
  File.open(output_file_name, 'w') { |f| f.write(output) }

  .add_test(
    id: test_id,
    file_name: base_output_file_name
  )
end

#module_nameObject



63
64
65
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 63

def module_name
  "DaVinciPlanNet#{.reformatted_version.upcase}"
end

#outputObject



31
32
33
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 31

def output
  @output ||= ERB.new(template).result(binding)
end

#output_file_directoryObject



39
40
41
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 39

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



43
44
45
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 43

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



51
52
53
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 51

def profile_identifier
  Naming.snake_case_for_profile()
end

#read_interactionObject



47
48
49
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 47

def read_interaction
  self.class.read_interaction()
end

#resource_typeObject



67
68
69
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 67

def resource_type
  .resource
end

#templateObject



27
28
29
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 27

def template
  @template ||= File.read(File.join(__dir__, 'templates', 'read.rb.erb'))
end

#test_idObject



55
56
57
# File 'lib/davinci_plan_net_test_kit/generator/read_test_generator.rb', line 55

def test_id
  "davinci_plan_net_#{.reformatted_version}_#{profile_identifier}_read_test"
end