Class: Crucible::Tests::SuiteEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/tests/suites/suite_engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = nil, client2 = nil) ⇒ SuiteEngine

Returns a new instance of SuiteEngine.



5
6
7
8
9
# File 'lib/tests/suites/suite_engine.rb', line 5

def initialize(client=nil, client2=nil)
  @client = client
  @client2 = client2
  build_suites_map
end

Class Method Details

.generate_metadataObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tests/suites/suite_engine.rb', line 81

def self.
  @fhir_classes ||= Mongoid.models.select {|c| c.name.include? 'FHIR'}
   = {}
  puts "---"
  puts "BUILDING METADATA"
  puts "---"
  SuiteEngine.new.tests.each do |test|
    test_file = Crucible::Tests.const_get(test).new(nil)
    if test_file.respond_to? 'resource_class='
      @fhir_classes.each do |klass|
        if !klass.included_modules.find_index(FHIR::Resource).nil?
          test_file.resource_class = klass
          puts "---"
          puts "BUILDING METADATA - #{test}#{klass.name.demodulize}"
          puts "---"
          ["#{test}#{klass.name.demodulize}"] = test_file.(true)
        end
      end
    else
      puts "---"
      puts "BUILDING METADATA - #{test}"
      puts "---"
      [test] = test_file.(true)
    end
  end
  puts "---"
  puts "FINISHED METADATA"
  puts "---"
  
end

.list_all(metadata = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tests/suites/suite_engine.rb', line 23

def self.list_all(=false)
  list = {}
  # FIXME: Organize defaults between instance & class methods
  @fhir_classes ||= Mongoid.models.select {|c| c.name.include? 'FHIR'}
  SuiteEngine.new.tests.each do |test|
    test_class = test.class.name.demodulize
    #if t can set class
    if test.respond_to? 'resource_class='
      @fhir_classes.each do |klass|
        if !klass.included_modules.find_index(FHIR::Resource).nil?
          test.resource_class = klass
          list["#{test_class}#{klass.name.demodulize}"] = {}
          list["#{test_class}#{klass.name.demodulize}"]['resource_class'] = klass
          BaseTest::JSON_FIELDS.each {|field| list["#{test_class}#{klass.name.demodulize}"][field] = test.send(field)}
          if 
             = test.(true)
            BaseTest::.each do |field|
              field_hash = {}
              .each { |tm| field_hash[tm[:test_method]] = tm[field] }
              list["#{test_class}#{klass.name.demodulize}"][field] = field_hash
            end
          end
        end
      end
    else
      list[test.title] = {}
      BaseTest::JSON_FIELDS.each {|field| list[test.title][field] = test.send(field)}
      if 
         = test.(true)
        BaseTest::.each do |field|
          field_hash = {}
          .each { |tm| field_hash[tm[:test_method]] = tm[field] }
          list[test.title][field] = field_hash
        end
      end
    end
  end
  list
end

Instance Method Details

#build_suites_mapObject



74
75
76
77
78
79
# File 'lib/tests/suites/suite_engine.rb', line 74

def build_suites_map
  @suites = {}
  (Crucible::Tests.constants.grep(/Test$/) - [:BaseTest]).each do |suite|
    @suites[suite] = Crucible::Tests.const_get(suite)
  end
end

#find_test(key) ⇒ Object

Use the built test suites to find a given test suite



70
71
72
# File 'lib/tests/suites/suite_engine.rb', line 70

def find_test(key)
  @suites[key.to_sym].new(@client, @client2) if @suites.keys.include?(key.to_sym)
end

#metadata(test) ⇒ Object



11
12
13
# File 'lib/tests/suites/suite_engine.rb', line 11

def (test)
  Crucible::Tests.const_get(test).new(@client).
end

#metadata_allObject



15
16
17
18
19
20
21
# File 'lib/tests/suites/suite_engine.rb', line 15

def 
  results = []
  tests.each do |test|
    results = results.concat (test)
  end
  results
end

#testsObject

Build all the test suites if none exist, but only reference the class



64
65
66
67
# File 'lib/tests/suites/suite_engine.rb', line 64

def tests
  # return newly-initialized copies of the tests
  @suites.values.map {|suite| suite.new(@client, @client2)}
end