Module: TDriver::TestObjectVerification

Defined in:
lib/tdriver/base/test_object/verification.rb

Constant Summary collapse

@@initialized =

defaults

false

Class Method Summary collapse

Class Method Details

.check_verify_always_reporting_settingsObject

TODO: Document me (TestObjectFactory::check_verify_always_reporting_settings)



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tdriver/base/test_object/verification.rb', line 10

def check_verify_always_reporting_settings

  @@reporter_attached = $parameters[ :report_attach_continuous_verification_to_reporter, 'false' ]

  @@rcv_raise_errors = $parameters[ :report_continuous_verification_raise_errors, 'true' ]

  @@rcv_fail_test_case = $parameters[ :report_continuous_verification_fail_test_case_on_error, 'true' ]

  @@rvc_capture_screen = $parameters[ :report_continuous_verification_capture_screen_on_error, 'true' ]

end

.initialize_settingsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tdriver/base/test_object/verification.rb', line 35

def initialize_settings

  # defaults
  @@global_reporter_attached = $parameters[ :report_attach_continuous_verification_to_reporter, 'false' ]

  @@rcv_global_raise_errors = $parameters[ :report_continuous_verification_raise_errors, 'true' ]

  @@rcv_global_fail_test_case = $parameters[ :report_continuous_verification_fail_test_case_on_error, 'true' ]

  @@rvc_global_capture_screen = $parameters[ :report_continuous_verification_capture_screen_on_error, 'true' ]

  @@inside_verify = false

  @@initialized = true

end

.restore_global_verify_always_reporting_settingsObject

TODO: Document me (TestObjectFactory::restore_verify_always_reporting_settings)



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tdriver/base/test_object/verification.rb', line 23

def restore_global_verify_always_reporting_settings

  @@reporter_attached = @@global_reporter_attached

  @@rcv_raise_errors = @@rcv_global_raise_errors

  @@rcv_fail_test_case = @@rcv_global_fail_test_case

  @@rvc_capture_screen = @@rvc_global_capture_screen

end

.verify_ui_dump(sut) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/tdriver/base/test_object/verification.rb', line 57

def self.verify_ui_dump( sut )

  initialize_settings unless @@initialized

  return if @@inside_verify

  begin

    @@inside_verify = true

    logging_enabled = $logger.enabled

    sut.verify_blocks.each do | verify |

      check_verify_always_reporting_settings()

      begin

        $logger.enabled = false

        begin
        
          result = verify.block.call( sut )

        rescue Exception => e

          if @@rcv_raise_errors == 'true' || @@reporter_attached == 'false'

            raise MobyBase::ContinuousVerificationError.new(
              "Verification failed as an exception was thrown when the verification block was executed. #{ verify.source }\nDetails: #{ ( verify.message || "none" ) }\nNested exception:\n#{ e.inspect }"
            )
            
          elsif @@reporter_attached == 'true' && @@rcv_raise_errors == 'false'

            TDriverReportAPI::tdriver_report_set_test_case_status('failed') if @@rcv_fail_test_case == 'true'

            if @@rvc_capture_screen == 'true'

              TDriverReportAPI::tdriver_capture_state

            else

              TDriverReportAPI::tdriver_capture_state( false )
              
            end

            TDriverReportAPI::tdriver_report_log("Verification failed as an exception was thrown when the verification block was executed. #{ verify.source }\nDetails: #{( verify.message || "none" ) }\nNested exception:\n#{ e.inspect }")

            TDriverReportAPI::tdriver_report_log("<hr />")
            
            $logger.enabled = logging_enabled
            $logger.behaviour "FAIL;Verification #{verify.message.nil? ? '' : '\"' << verify.message << '\" '}failed:#{e.to_s}.\n#{verify.timeout.nil? ? '' : ' using timeout ' + verify.timeout.to_s}.;#{sut.id.to_s+';sut'};{};verify_always;" << verify.expected.to_s

          end

        end

        unless result == verify.expected

          if @@rcv_raise_errors == 'true' || @@reporter_attached == 'false'
          
            raise MobyBase::ContinuousVerificationError.new(
              "Verification failed. #{ verify.source }\nDetails: #{ ( verify.message || "none" ) }\nThe block did not return #{ verify.expected.inspect }. It returned: #{ result.inspect }"
            )
            
          elsif @@reporter_attached == 'true' && @@rcv_raise_errors == 'false'
          
            TDriverReportAPI::tdriver_report_set_test_case_status('failed') if @@rcv_fail_test_case == 'true'
            
            if @@rvc_capture_screen == 'true'

              TDriverReportAPI::tdriver_capture_state

            else

              TDriverReportAPI::tdriver_capture_state( false )

            end
            
            TDriverReportAPI::tdriver_report_log(
              "Verification failed. #{ verify.source }\nDetails: #{ ( verify.message || "none" ) }\nThe block did not return #{ verify.expected.inspect }. It returned: #{ result.inspect } "
            )
            
            TDriverReportAPI::tdriver_report_log("<hr />")

            $logger.enabled = logging_enabled
            
            $logger.behaviour "FAIL;Verification #{verify.message.nil? ? '' : '\"' << verify.message << '\" '}failed:#{e.to_s}.\n#{verify.timeout.nil? ? '' : ' using timeout ' + verify.timeout.to_s}.;#{sut.id.to_s+';sut'};{};verify_always;" << verify.expected.to_s

          end
        
        end

      rescue Exception => e

        $logger.enabled = logging_enabled

        $logger.behaviour "FAIL;Verification #{verify.message.nil? ? '' : '\"' << verify.message << '\" '}failed:#{e.to_s}.\n#{verify.timeout.nil? ? '' : ' using timeout ' + verify.timeout.to_s}.;#{sut.id.to_s+';sut'};{};verify_always;" << verify.expected.to_s

        @@inside_verify = false

        raise e
      
      end

      # Do NOT report PASS cases, like other verify blocks do. This would clog the log with useless info.
      restore_global_verify_always_reporting_settings
    
    end

  ensure

    $logger.enabled = logging_enabled
    @@inside_verify = false      

  end
  
end