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/DSTU2'
"#{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_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.



24
25
26
27
28
29
30
# File 'lib/tests/base_test.rb', line 24

def initialize(client, client2=nil)
  @client = client
  @client2 = client2
  @client.monitor_requests if @client
  @client2.monitor_requests if @client2
  @tags ||= []
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

#tests_subsetObject

Returns the value of attribute tests_subset.



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

def tests_subset
  @tests_subset
end

Instance Method Details

#authorObject



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

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

#descriptionObject



80
81
82
83
# File 'lib/tests/base_test.rb', line 80

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

#detailsObject



85
86
87
# File 'lib/tests/base_test.rb', line 85

def details
  {}
end

#executeObject



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

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



69
70
71
72
73
# File 'lib/tests/base_test.rb', line 69

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tests/base_test.rb', line 46

def execute_test_methods
  result = []
  begin
    setup if respond_to? :setup and not 
  rescue AssertionException => e
    @setup_failed = e
  end
  prefix = if  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
    puts "[#{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
  teardown if respond_to? :teardown and not 
  result
end

#idObject



89
90
91
92
# File 'lib/tests/base_test.rb', line 89

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

#multiserverObject



32
33
34
# File 'lib/tests/base_test.rb', line 32

def multiserver
  false
end

#requires_authorizationObject



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

def requires_authorization
  true
end

#tests(keys = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/tests/base_test.rb', line 94

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



107
108
109
110
111
112
113
# File 'lib/tests/base_test.rb', line 107

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