Class: Crucible::Tests::BaseTest

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/tests/base_test.rb

Direct Known Subclasses

BaseSuite, BaseTestScript

Constant Summary collapse

'http://hl7.org/fhir/2017Jan'
"#{BASE_SPEC_LINK}/http.html"
JSON_FIELDS =

Base test fields, used in Crucible::Tests::Executor.list_all

['author','description','id','tests','title', 'multiserver', 'tags', 'details', 'category']
STATUS =
{
  pass: 'pass',
  fail: 'fail',
  error: 'error',
  skip: 'skip'
}
METADATA_FIELDS =
['links', 'requires', 'validates']

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert, #assert_bundle_entry_count, #assert_bundle_response, #assert_bundle_transactions_okay, #assert_equal, #assert_etag_present, #assert_last_modified_present, #assert_minimum, #assert_navigation_links, #assert_operator, #assert_resource_content_type, #assert_resource_type, #assert_response_bad, #assert_response_code, #assert_response_conflict, #assert_response_created, #assert_response_gone, #assert_response_not_found, #assert_response_ok, #assert_valid_content_location_present, #assert_valid_profile, #assert_valid_resource_content_type_present, #assertion_negated, #skip

Constructor Details

#initialize(client, client2 = nil) ⇒ BaseTest

Returns a new instance of BaseTest.



26
27
28
29
30
31
32
33
34
# File 'lib/tests/base_test.rb', line 26

def initialize(client, client2=nil)
  @client = client
  FHIR::Resource.new.client = client
  @client2 = client2
  @client.monitor_requests if @client
  @client2.monitor_requests if @client2
  @tags ||= []
  @warnings = []
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



13
14
15
# File 'lib/tests/base_test.rb', line 13

def category
  @category
end

#tagsObject

Returns the value of attribute tags.



12
13
14
# File 'lib/tests/base_test.rb', line 12

def tags
  @tags
end

#tests_subsetObject

Returns the value of attribute tests_subset.



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

def tests_subset
  @tests_subset
end

#warningsObject

Returns the value of attribute warnings.



14
15
16
# File 'lib/tests/base_test.rb', line 14

def warnings
  @warnings
end

Instance Method Details

#authorObject



82
83
84
85
# File 'lib/tests/base_test.rb', line 82

def author
  # String identifying test file author
  self.class.name
end

#descriptionObject



87
88
89
90
# File 'lib/tests/base_test.rb', line 87

def description
  # String containing test file description
  self.class.name
end

#detailsObject



92
93
94
# File 'lib/tests/base_test.rb', line 92

def details
  {}
end

#executeObject



40
41
42
43
44
# File 'lib/tests/base_test.rb', line 40

def execute
  @client.use_format_param = false if @client
  @client2.use_format_param = false if @client2
  {id => execute_test_methods}
end

#execute_test_method(test_method) ⇒ Object



76
77
78
79
80
# File 'lib/tests/base_test.rb', line 76

def execute_test_method(test_method)
  response = self.method(test_method).call().to_hash.merge!({:test_method => test_method })
  response.merge!({:requests => @client.requests.map { |r| r.to_hash } }) if @client
  response
end

#execute_test_methodsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tests/base_test.rb', line 50

def execute_test_methods
  result = []
  begin
    setup if respond_to? :setup and not @metadata_only
  rescue AssertionException => e
    @setup_failed = e
  end
  prefix = if @metadata_only then 'generating metadata' else 'executing' end
  methods = tests
  methods = tests & @tests_subset unless @tests_subset.blank?
  methods.each do |test_method|
    @client.requests = [] if @client
    FHIR.logger.info "[#{title}#{('_' + @resource_class.name.demodulize) if @resource_class}] #{prefix}: #{test_method}..."
    begin
      result << execute_test_method(test_method)
    rescue => e
      result << TestResult.new('ERROR', "Error #{prefix} #{test_method}", STATUS[:error], "#{test_method} failed, fatal error: #{e.message}", e.backtrace.join("\n")).to_hash.merge!({:test_method => test_method})
    end
  end
  begin
    teardown if respond_to? :teardown and not @metadata_only
  rescue
  end
  result
end

#idObject



96
97
98
99
# File 'lib/tests/base_test.rb', line 96

def id
  # String used to order test files for execution
  self.object_id.to_s
end

#ignore_client_exceptionObject



122
123
124
125
126
127
# File 'lib/tests/base_test.rb', line 122

def ignore_client_exception
  begin
    yield
  rescue ClientException
  end
end

#multiserverObject



36
37
38
# File 'lib/tests/base_test.rb', line 36

def multiserver
  false
end

#requires_authorizationObject



46
47
48
# File 'lib/tests/base_test.rb', line 46

def requires_authorization
  true
end

#tests(keys = nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/tests/base_test.rb', line 101

def tests(keys=nil)
  # Array of test methods within test file
  methods = self.methods.grep(/_test$/)
  if keys
    matches = []
    keys.each do |key|
      matches << methods.grep(/^#{key}/i)
    end
    methods = matches.flatten
  end
  methods
end

#warningObject



114
115
116
117
118
119
120
# File 'lib/tests/base_test.rb', line 114

def warning
  begin
    yield
  rescue AssertionException => e
    @warnings << e.message
  end
end