Class: Moto::Test::Base
- Inherits:
-
Object
- Object
- Moto::Test::Base
- Defined in:
- lib/test/base.rb
Class Attribute Summary collapse
-
._path ⇒ Object
Returns the value of attribute _path.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#metadata ⇒ Moto::Test::Metadata
Contains information specified by user in Test headers, marked with appropriate tags.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#static_path ⇒ Object
Returns the value of attribute static_path.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #after ⇒ Object
-
#assert(condition, message) ⇒ Object
Checks if result of condition equals to True.
-
#assert_equal(a, b) ⇒ Object
Checks for equality of both arguments.
-
#assert_false(value) ⇒ Object
Checks if passed value is equal to False.
-
#assert_true(value) ⇒ Object
Checks if passed value is equal to True.
- #before ⇒ Object
-
#const(key) ⇒ String
Read a constants value from configuration files while taking the execution environment into the account.
- #fail(msg = nil) ⇒ Object
-
#init(params_path) ⇒ Object
Initializes test to be executed with specified params and environment.
-
#log_path ⇒ String
String with the path to the test’s log.
-
#log_path=(param) ⇒ Object
Setter for :log_path.
- #pass(msg = nil) ⇒ Object
- #path ⇒ Object
-
#run ⇒ Object
Only to be overwritten by final test execution Use :run_test in order to run test.
-
#run_test ⇒ Object
Use this to run test Initializes status, runs test, handles exceptions, finalizes status after run completion.
- #skip(msg = nil) ⇒ Object
Class Attribute Details
._path ⇒ Object
Returns the value of attribute _path.
18 19 20 |
# File 'lib/test/base.rb', line 18 def _path @_path end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
8 9 10 |
# File 'lib/test/base.rb', line 8 def env @env end |
#metadata ⇒ Moto::Test::Metadata
Contains information specified by user in Test headers, marked with appropriate tags
15 16 17 |
# File 'lib/test/base.rb', line 15 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/test/base.rb', line 7 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/test/base.rb', line 9 def params @params end |
#static_path ⇒ Object
Returns the value of attribute static_path.
10 11 12 |
# File 'lib/test/base.rb', line 10 def static_path @static_path end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/test/base.rb', line 11 def status @status end |
Class Method Details
.inherited(k) ⇒ Object
21 22 23 |
# File 'lib/test/base.rb', line 21 def self.inherited(k) k._path = caller.first.match(/(.+):\d+:in/)[1] end |
Instance Method Details
#after ⇒ Object
97 98 99 |
# File 'lib/test/base.rb', line 97 def after # abstract end |
#assert(condition, message) ⇒ Object
Checks if result of condition equals to True
140 141 142 143 144 145 146 147 |
# File 'lib/test/base.rb', line 140 def assert(condition, ) if !condition line_number = caller.select { |l| l.match(/#{static_path}:\d*:in `run'/) }.first[/\d+/].to_i status.log_failure("ASSERTION FAILED in line #{line_number}: #{message}") Thread.current['logger'].error() end end |
#assert_equal(a, b) ⇒ Object
Checks for equality of both arguments
125 126 127 |
# File 'lib/test/base.rb', line 125 def assert_equal(a, b) assert(a == b, "Arguments should be equal: #{a} != #{b}.") end |
#assert_false(value) ⇒ Object
Checks if passed value is equal to False
135 136 137 |
# File 'lib/test/base.rb', line 135 def assert_false(value) assert(!value, 'Logical condition not met, expecting false, given true.') end |
#assert_true(value) ⇒ Object
Checks if passed value is equal to True
130 131 132 |
# File 'lib/test/base.rb', line 130 def assert_true(value) assert(value, 'Logical condition not met, expecting true, given false.') end |
#before ⇒ Object
93 94 95 |
# File 'lib/test/base.rb', line 93 def before # abstract end |
#const(key) ⇒ String
Read a constants value from configuration files while taking the execution environment into the account.
152 153 154 |
# File 'lib/test/base.rb', line 152 def const(key) Moto::Lib::Config.environment_const(key) end |
#fail(msg = nil) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/test/base.rb', line 105 def fail(msg = nil) if msg.nil? msg = 'Test forcibly failed with no reason given.' else msg = "Forced failure: #{msg}" end raise Exceptions::TestForcedFailure.new msg end |
#init(params_path) ⇒ Object
Initializes test to be executed with specified params and environment
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/test/base.rb', line 30 def init(params_path) @env = Moto::Lib::Config.environment @params = [] @params_path = params_path @name = self.class.to_s.demodulize @name += "_#{@params_path.split('/')[-1].chomp('.param')}" if @params_path @status = Moto::Test::Status.new @status.name = @name @status.test_class_name = self.class.name @status.display_name = @status.test_class_name.split('::')[2..-2].join('::') @status.display_name += "_#{@params_path.split('/')[-1].chomp('.param')}" if @params_path @status.env = Moto::Lib::Config.environment end |
#log_path ⇒ String
Returns string with the path to the test’s log.
56 57 58 |
# File 'lib/test/base.rb', line 56 def log_path @log_path end |
#log_path=(param) ⇒ Object
Setter for :log_path
47 48 49 50 51 52 53 |
# File 'lib/test/base.rb', line 47 def log_path=(param) @log_path = param # I hate myself for doing this, but I have no other idea for now how to pass log to Listeners that # make use of it (for example WebUI) @status.log_path = param end |
#pass(msg = nil) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/test/base.rb', line 114 def pass(msg = nil) if msg.nil? msg = 'Test forcibly passed with no reason given.' else msg = "Forced passed: #{msg}" end raise Exceptions::TestForcedPassed.new msg end |
#path ⇒ Object
25 26 27 |
# File 'lib/test/base.rb', line 25 def path self.class._path end |
#run ⇒ Object
Only to be overwritten by final test execution Use :run_test in order to run test
89 90 91 |
# File 'lib/test/base.rb', line 89 def run # abstract end |
#run_test ⇒ Object
Use this to run test Initializes status, runs test, handles exceptions, finalizes status after run completion
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/test/base.rb', line 62 def run_test status.initialize_run #TODO Formatting/optimization begin @params = eval(File.read(@params_path)) if File.exists?(@params_path.to_s) @status.params = @params rescue Exception => exception status.log_exception(exception) raise "ERROR: Invalid parameters file: #{@params_path}.\n\tMESSAGE: #{exception.message}" ensure status.finalize_run end begin run rescue Exception => exception status.log_exception(exception) raise ensure status.finalize_run end end |
#skip(msg = nil) ⇒ Object
101 102 103 |
# File 'lib/test/base.rb', line 101 def skip(msg = nil) raise Exceptions::TestSkipped.new(msg.nil? ? 'Test skipped with no reason given.' : "Skipped: #{msg}") end |