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
-
#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_equal(value1, value2, failure_message = "Arguments should be equal: $1 != $2") ⇒ Object
Checks for equality of both values using operator ==.
-
#assert_false(value, failure_message = "Logical condition not met, expecting false, given $1") ⇒ Object
Checks if passed value is equal to False.
-
#assert_true(value, failure_message = "Logical condition not met, expecting true, given $1") ⇒ Object
(also: #assert)
Checks if passed value is equal to True.
- #before ⇒ Object
-
#env ⇒ Hash
Configuration for selected environment + current thread combination.
- #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.
- #logger ⇒ Logger
- #pass(msg = nil) ⇒ Object
- #path ⇒ Object
- #report_failed_assertion(failure_message) ⇒ 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
#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 @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/test/base.rb', line 8 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
96 97 98 |
# File 'lib/test/base.rb', line 96 def after # abstract end |
#assert_equal(value1, value2, failure_message = "Arguments should be equal: $1 != $2") ⇒ Object
Checks for equality of both values using operator ==
129 130 131 132 133 |
# File 'lib/test/base.rb', line 129 def assert_equal(value1, value2, = "Arguments should be equal: $1 != $2") if value1 != value2 report_failed_assertion(.gsub('$1', value1.to_s).gsub('$2', value2.to_s)) end end |
#assert_false(value, failure_message = "Logical condition not met, expecting false, given $1") ⇒ Object
Checks if passed value is equal to False
152 153 154 155 156 |
# File 'lib/test/base.rb', line 152 def assert_false(value, = "Logical condition not met, expecting false, given $1") if value report_failed_assertion(.gsub('$1', value.to_s)) end end |
#assert_true(value, failure_message = "Logical condition not met, expecting true, given $1") ⇒ Object Also known as: assert
Checks if passed value is equal to True
140 141 142 143 144 |
# File 'lib/test/base.rb', line 140 def assert_true(value, = "Logical condition not met, expecting true, given $1") if !value report_failed_assertion(.gsub('$1', value.to_s)) end end |
#before ⇒ Object
92 93 94 |
# File 'lib/test/base.rb', line 92 def before # abstract end |
#env ⇒ Hash
Returns Configuration for selected environment + current thread combination.
165 166 167 |
# File 'lib/test/base.rb', line 165 def env Moto::Config::Manager.config_environment end |
#fail(msg = nil) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/test/base.rb', line 104 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 |
# File 'lib/test/base.rb', line 30 def init(params_path) @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.display_name += "(#{.test_repeat})" if .test_repeat > 1 end |
#log_path ⇒ String
Returns string with the path to the test’s log.
55 56 57 |
# File 'lib/test/base.rb', line 55 def log_path @log_path end |
#log_path=(param) ⇒ Object
Setter for :log_path
46 47 48 49 50 51 52 |
# File 'lib/test/base.rb', line 46 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 |
#logger ⇒ Logger
170 171 172 |
# File 'lib/test/base.rb', line 170 def logger Thread.current['logger'] end |
#pass(msg = nil) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/test/base.rb', line 113 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 |
#report_failed_assertion(failure_message) ⇒ Object
158 159 160 161 162 |
# File 'lib/test/base.rb', line 158 def report_failed_assertion() 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}: #{}") logger.error() end |
#run ⇒ Object
Only to be overwritten by final test execution Use :run_test in order to run test
88 89 90 |
# File 'lib/test/base.rb', line 88 def run # abstract end |
#run_test ⇒ Object
Use this to run test Initializes status, runs test, handles exceptions, finalizes status after run completion
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/test/base.rb', line 61 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.}" 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
100 101 102 |
# File 'lib/test/base.rb', line 100 def skip(msg = nil) raise Exceptions::TestSkipped.new(msg.nil? ? 'Test skipped with no reason given.' : "Skipped: #{msg}") end |