Class: Result
- Inherits:
-
Object
- Object
- Result
- Defined in:
- lib/Result.rb
Overview
The Result class wraps a HTTP Response object and provides some test framework-specific additional result tracking.
The ServiceAPI#do_request* methods returns this Result object for each test.
Instance Attribute Summary collapse
-
#abort_suite_run ⇒ Object
if true, framework will end test suite run immediately.
-
#allow_retry ⇒ Object
if false, do not retry test even if test file requests retries.
-
#is_ok ⇒ Object
readonly
Returns the value of attribute is_ok.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.abort_suite(message) ⇒ Object
——————————————————————————————————————- Constructs a Result object which tells the framework to abort the current test suite.
-
.fatal_error(message) ⇒ Object
——————————————————————————————————————- Fatal error factory.
Instance Method Summary collapse
-
#add_message(msg) ⇒ Object
——————————————————————————————————————- Adds a message sentence to the error message line.
-
#body ⇒ Object
——————————————————————————————————————- Returns the HTTP response body sent by server.
-
#code ⇒ Object
——————————————————————————————————————- Returns the HTTP response code sent by server (as a String).
-
#error(msg) ⇒ Object
——————————————————————————————————————- Flags this Result as erroneous.
-
#initialize(response) ⇒ Result
constructor
——————————————————————————————————————- Constructor.
Constructor Details
#initialize(response) ⇒ Result
Constructor.
19 20 21 22 23 24 |
# File 'lib/Result.rb', line 19 def initialize(response) @response = response @is_ok = true @allow_retry = true @message = "" end |
Instance Attribute Details
#abort_suite_run ⇒ Object
if true, framework will end test suite run immediately
14 15 16 |
# File 'lib/Result.rb', line 14 def abort_suite_run @abort_suite_run end |
#allow_retry ⇒ Object
if false, do not retry test even if test file requests retries
13 14 15 |
# File 'lib/Result.rb', line 13 def allow_retry @allow_retry end |
#is_ok ⇒ Object (readonly)
Returns the value of attribute is_ok.
11 12 13 |
# File 'lib/Result.rb', line 11 def is_ok @is_ok end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
12 13 14 |
# File 'lib/Result.rb', line 12 def @message end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/Result.rb', line 10 def response @response end |
Class Method Details
.abort_suite(message) ⇒ Object
Constructs a Result object which tells the framework to abort the current test suite.
A service module should generally never return this. Avoid it! Even if a particular misconfiguration is fatal for a certain subset of tests, it is possible the suite may have many other tests which can still run.
It is provided for cases where a service module detects a misconfiguration so fatal that there truly is no point in attempting to run any more tests because you know for sure they will all fail.
46 47 48 49 50 51 52 |
# File 'lib/Result.rb', line 46 def self.abort_suite() res = Result.new(nil) res.error() res.allow_retry = false res.abort_suite_run = true return res end |
.fatal_error(message) ⇒ Object
Fatal error factory. A service module should return a fatal_error when it encounters a problem which cannot change by re-trying the same test again. The most common case is if a required parameter is missing.
30 31 32 33 34 35 |
# File 'lib/Result.rb', line 30 def self.fatal_error() res = Result.new(nil) res.error() res.allow_retry = false return res end |
Instance Method Details
#add_message(msg) ⇒ Object
Adds a message sentence to the error message line. Typically callers should invoke error() above.
70 71 72 73 74 75 |
# File 'lib/Result.rb', line 70 def (msg) @message = @message + msg if (@message[-1,1] != " ") @message = @message + " " end end |
#body ⇒ Object
Returns the HTTP response body sent by server.
88 89 90 91 |
# File 'lib/Result.rb', line 88 def body return "" if @response == nil return @response.body end |
#code ⇒ Object
Returns the HTTP response code sent by server (as a String)
80 81 82 83 |
# File 'lib/Result.rb', line 80 def code return (-1) if @response == nil return @response.code end |
#error(msg) ⇒ Object
Flags this Result as erroneous. After one call to this method, is_ok will return false. A descriptive message string needs to be provided, explaining why the result is erroneous. This method can be invoked multiple times, if multiple errors are noticed on the response. The message(s) will be available via the message method.
61 62 63 64 |
# File 'lib/Result.rb', line 61 def error(msg) @is_ok = false (msg) end |