moto 0.0.51 → 0.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cli.rb +1 -1
- data/lib/config.rb +32 -12
- data/lib/parser.rb +8 -9
- data/lib/runner/test_generator.rb +29 -34
- data/lib/runner/test_provider.rb +2 -3
- data/lib/runner/test_runner.rb +2 -3
- data/lib/test/base.rb +9 -15
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bbd84180b2d5e25940cef303e4ab4cfdd7091fb
|
4
|
+
data.tar.gz: ac51475dc79d42081e765e8d5853e2d3214fa579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb7e64acf369eb46c571d31786b57000913237068980446035639b06749e93cdfb185ed5f17758ebf9677b3d23998a1e41ad2f8af393f35a631c0bf8b275c80
|
7
|
+
data.tar.gz: 2d78a9427e12f49c5f6e750203d2756c5d4675dbb8a64e90159176f2825743fbc17de04876a60909ca9e50ad1d63693715138d1d6c29f98e2ed6abc36033b311
|
data/lib/cli.rb
CHANGED
@@ -77,7 +77,7 @@ module Moto
|
|
77
77
|
|
78
78
|
test_reporter = Moto::Reporting::TestReporter.new(argv[:listeners], argv[:name])
|
79
79
|
|
80
|
-
runner = Moto::Runner::TestRunner.new(test_paths_absolute,
|
80
|
+
runner = Moto::Runner::TestRunner.new(test_paths_absolute, test_reporter)
|
81
81
|
runner.run
|
82
82
|
end
|
83
83
|
|
data/lib/config.rb
CHANGED
@@ -1,16 +1,41 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
1
3
|
module Moto
|
2
4
|
module Lib
|
3
5
|
class Config
|
4
6
|
|
7
|
+
# @return [String] String representing the name of the current environment
|
8
|
+
def self.environment
|
9
|
+
@@environment
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [String] environment Sets a string that will represent environment in configuration, on which
|
13
|
+
# various settings will depend, for example env. constants
|
14
|
+
def self.environment=(environment)
|
15
|
+
@@environment = environment
|
16
|
+
end
|
17
|
+
|
18
|
+
# Loads configuration for whole test run and files responsible for environmental constants.
|
5
19
|
def self.load_configuration
|
6
20
|
if File.exists? "#{MotoApp::DIR}/config/moto.rb"
|
7
21
|
@@moto = eval(File.read("#{MotoApp::DIR}/config/moto.rb"))
|
8
22
|
|
9
|
-
|
10
|
-
|
11
|
-
|
23
|
+
# Try reading constants that are common for all environments
|
24
|
+
begin
|
25
|
+
common_constants = eval(File.read('config/environments/common.rb'))
|
26
|
+
rescue
|
27
|
+
common_constants = {}
|
12
28
|
end
|
13
29
|
|
30
|
+
# Try reading constants specific to current environment
|
31
|
+
begin
|
32
|
+
environment_constants = eval(File.read("config/environments/#{@@environment}.rb"))
|
33
|
+
rescue
|
34
|
+
environment_constants = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
@@env_consts = common_constants.deep_merge(environment_constants)
|
38
|
+
|
14
39
|
else
|
15
40
|
raise "Config file (config/moto.rb) not present.\nDoes current working directory contain Moto application?"
|
16
41
|
end
|
@@ -26,23 +51,18 @@ module Moto
|
|
26
51
|
# @return [String] Value of the key
|
27
52
|
def self.environment_const(key)
|
28
53
|
key = key.to_s
|
29
|
-
env = Thread.current['test_environment']
|
30
|
-
|
31
|
-
if env != :__default
|
32
|
-
key = "#{env.to_s}.#{key}"
|
33
|
-
end
|
34
54
|
|
35
55
|
code = if key.include? '.'
|
36
|
-
"@@env_consts#{key.split('.').map { |a| "[
|
56
|
+
"@@env_consts#{key.split('.').map { |a| "[:#{a}]" }.join('')}"
|
37
57
|
else
|
38
|
-
"@@env_consts[
|
58
|
+
"@@env_consts[:#{key}]"
|
39
59
|
end
|
40
60
|
|
41
61
|
begin
|
42
|
-
value = eval
|
62
|
+
value = eval(code)
|
43
63
|
raise if value.nil?
|
44
64
|
rescue
|
45
|
-
raise "There is no const defined for key: #{key}.
|
65
|
+
raise "There is no const defined for key: #{key}."
|
46
66
|
end
|
47
67
|
|
48
68
|
value
|
data/lib/parser.rb
CHANGED
@@ -28,17 +28,12 @@ module Moto
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.run_parse(argv)
|
31
|
-
|
32
|
-
Moto::Lib::Config.load_configuration
|
33
|
-
|
34
31
|
require 'bundler/setup'
|
35
32
|
Bundler.require
|
36
33
|
|
37
34
|
# Default options
|
38
35
|
options = {}
|
39
36
|
options[:listeners] = []
|
40
|
-
# TODO Mandatory env var in app config
|
41
|
-
options[:environments] = []
|
42
37
|
options[:name] = ''
|
43
38
|
|
44
39
|
# Parse arguments
|
@@ -46,7 +41,7 @@ module Moto
|
|
46
41
|
opts.on('-t', '--tests Tests', Array) { |v| options[:tests ] = v }
|
47
42
|
opts.on('-g', '--tags Tags', Array) { |v| options[:tags ] = v }
|
48
43
|
opts.on('-l', '--listeners Listeners', Array) { |v| options[:listeners] = v }
|
49
|
-
opts.on('-e', '--
|
44
|
+
opts.on('-e', '--environment Environment') { |v| options[:environment] = v }
|
50
45
|
opts.on('-n', '--name Name') { |v| options[:name] = v }
|
51
46
|
# opts.on('-f', '--config Config') { |v| options[:config].deep_merge!( eval( File.read(v) ) ) }
|
52
47
|
end.parse!
|
@@ -55,11 +50,15 @@ module Moto
|
|
55
50
|
options[:name] = evaluate_name(options[:tags], options[:tests])
|
56
51
|
end
|
57
52
|
|
58
|
-
if
|
59
|
-
puts 'Environment is mandatory
|
53
|
+
if !options[:environment]
|
54
|
+
puts 'ERROR: Environment is mandatory.'
|
60
55
|
exit 1
|
56
|
+
else
|
57
|
+
Moto::Lib::Config.environment = options[:environment]
|
58
|
+
Moto::Lib::Config.load_configuration
|
61
59
|
end
|
62
60
|
|
61
|
+
|
63
62
|
return options
|
64
63
|
end
|
65
64
|
|
@@ -105,7 +104,7 @@ module Moto
|
|
105
104
|
For eg. Tests\Failure\Failure.rb should be passed as Tests::Failure
|
106
105
|
-l, --listeners = Reporters to be used.
|
107
106
|
Defaults are Moto::Listeners::ConsoleDots, Moto::Listeners::JunitXml
|
108
|
-
-e, --environment
|
107
|
+
-e, --environment Mandatory environment. Environment constants and tests parametrized in certain way depend on this.
|
109
108
|
|
110
109
|
|
111
110
|
moto generate:
|
@@ -7,9 +7,8 @@ module Moto
|
|
7
7
|
module Runner
|
8
8
|
class TestGenerator
|
9
9
|
|
10
|
-
def initialize
|
10
|
+
def initialize
|
11
11
|
@internal_counter = 0
|
12
|
-
@environments = environments
|
13
12
|
end
|
14
13
|
|
15
14
|
# Method returns an array of test instances that represent all variants (parameter sets from test's config).
|
@@ -23,7 +22,7 @@ module Moto
|
|
23
22
|
test_path_absolute ? variantize(test_path_absolute) : nil
|
24
23
|
end
|
25
24
|
|
26
|
-
# Converts test's path to an array of Moto::Base::Test instances that represent all test variants (params
|
25
|
+
# Converts test's path to an array of Moto::Base::Test instances that represent all test variants (params)
|
27
26
|
#
|
28
27
|
# *IMPORTANT*
|
29
28
|
# Config files with ruby code will be evaluated thus if you use any classes in them
|
@@ -34,45 +33,41 @@ module Moto
|
|
34
33
|
def variantize(test_path_absolute)
|
35
34
|
variants = []
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
params_error = e.message
|
46
|
-
params_all = [{}]
|
47
|
-
end
|
48
|
-
else
|
36
|
+
params_path = test_path_absolute.sub(/\.rb\z/, '')
|
37
|
+
|
38
|
+
if File.exists?(params_path)
|
39
|
+
begin
|
40
|
+
params_all = eval(File.read(params_path))
|
41
|
+
rescue Exception => e
|
42
|
+
# Error will be injected into test.run after test is created
|
43
|
+
params_error = e.message
|
49
44
|
params_all = [{}]
|
50
45
|
end
|
46
|
+
else
|
47
|
+
params_all = [{}]
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
# Filtering out param sets that are specific to certain envs
|
55
|
-
unless params['__env'].nil?
|
56
|
-
allowed_envs = params['__env'].is_a?(String) ? [params['__env']] : params['__env']
|
57
|
-
next unless allowed_envs.include? env
|
58
|
-
end
|
50
|
+
params_all.each_with_index do |params, params_index|
|
59
51
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
# Filtering out param sets that are specific to certain envs
|
53
|
+
unless params['__env'].nil?
|
54
|
+
allowed_envs = params['__env'].is_a?(String) ? [params['__env']] : params['__env']
|
55
|
+
next unless allowed_envs.include?(Moto::Lib::Config.environment)
|
56
|
+
end
|
64
57
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
inject_error_to_test(test, error_message)
|
70
|
-
end
|
58
|
+
test = generate(test_path_absolute)
|
59
|
+
test.init(params, params_index, @internal_counter)
|
60
|
+
test.log_path = "#{test.dir}/logs/#{test.name.gsub(/[^0-9A-Za-z.\-]/, '_')}.log"
|
61
|
+
@internal_counter += 1
|
71
62
|
|
72
|
-
|
63
|
+
# Error handling, test.run() contents will be swapped with raised exception
|
64
|
+
# so there is an indication in reporters/logs that something went wrong
|
65
|
+
if params_error
|
66
|
+
error_message = "ERROR: Invalid parameters file: #{test.dir}.\n\tMESSAGE: #{params_error}"
|
67
|
+
inject_error_to_test(test, error_message)
|
73
68
|
end
|
74
69
|
|
75
|
-
|
70
|
+
variants << test
|
76
71
|
end
|
77
72
|
|
78
73
|
variants
|
data/lib/runner/test_provider.rb
CHANGED
@@ -7,14 +7,13 @@ module Moto
|
|
7
7
|
class TestProvider
|
8
8
|
|
9
9
|
# @param [Array] test_paths_absolute
|
10
|
-
|
11
|
-
def initialize(test_paths_absolute, environments)
|
10
|
+
def initialize(test_paths_absolute)
|
12
11
|
super()
|
13
12
|
@test_repeats = Moto::Lib::Config.moto[:test_runner][:test_repeats]
|
14
13
|
@current_test_repeat = 1
|
15
14
|
@queue = Queue.new
|
16
15
|
@test_paths_absolute = test_paths_absolute
|
17
|
-
@test_generator = TestGenerator.new
|
16
|
+
@test_generator = TestGenerator.new
|
18
17
|
end
|
19
18
|
|
20
19
|
# Use this to retrieve tests safely in multithreaded environment
|
data/lib/runner/test_runner.rb
CHANGED
@@ -8,17 +8,16 @@ module Moto
|
|
8
8
|
attr_reader :logger
|
9
9
|
attr_reader :test_reporter
|
10
10
|
|
11
|
-
def initialize(test_paths_absolute,
|
11
|
+
def initialize(test_paths_absolute, test_reporter)
|
12
12
|
@test_paths_absolute = test_paths_absolute
|
13
13
|
@test_reporter = test_reporter
|
14
14
|
|
15
15
|
# TODO: initialize logger from config (yml or just ruby code)
|
16
16
|
@logger = Logger.new(File.open("#{MotoApp::DIR}/moto.log", File::WRONLY | File::APPEND | File::CREAT))
|
17
|
-
@environments = environments.empty? ? environments << :__default : environments
|
18
17
|
end
|
19
18
|
|
20
19
|
def run
|
21
|
-
test_provider = TestProvider.new(@test_paths_absolute
|
20
|
+
test_provider = TestProvider.new(@test_paths_absolute)
|
22
21
|
threads_max = Moto::Lib::Config.moto[:test_runner][:thread_count] || 1
|
23
22
|
|
24
23
|
# remove log/screenshot files from previous execution
|
data/lib/test/base.rb
CHANGED
@@ -27,15 +27,15 @@ module Moto
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Initializes test to be executed with specified params and environment
|
30
|
-
def init(
|
31
|
-
@env =
|
30
|
+
def init(params, params_index, global_index)
|
31
|
+
@env = Moto::Lib::Config.environment
|
32
32
|
@params = params
|
33
33
|
@name = generate_name(params_index, global_index)
|
34
34
|
|
35
35
|
@status = Moto::Test::Status.new
|
36
36
|
@status.name = @name
|
37
37
|
@status.test_class_name = self.class.name
|
38
|
-
@status.env =
|
38
|
+
@status.env = Moto::Lib::Config.environment
|
39
39
|
@status.params = @params
|
40
40
|
end
|
41
41
|
|
@@ -45,15 +45,9 @@ module Moto
|
|
45
45
|
def generate_name(params_index, global_index)
|
46
46
|
simple_class_name = self.class.to_s.demodulize
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return "#{simple_class_name}_P#{params_index}_#{global_index}" unless @params.key?(:__name)
|
52
|
-
else
|
53
|
-
return "#{simple_class_name}_#{@env}_##{global_index}" if @params.empty?
|
54
|
-
return "#{simple_class_name}_#{@env}_#{@params[:__name]}_#{global_index}" if @params.key?(:__name)
|
55
|
-
return "#{simple_class_name}_#{@env}_P#{params_index}_#{global_index}" unless @params.key?(:__name)
|
56
|
-
end
|
48
|
+
return "#{simple_class_name}_#{@env}_##{global_index}" if @params.empty?
|
49
|
+
return "#{simple_class_name}_#{@env}_#{@params[:__name]}_#{global_index}" if @params.key?(:__name)
|
50
|
+
return "#{simple_class_name}_#{@env}_P#{params_index}_#{global_index}" unless @params.key?(:__name)
|
57
51
|
|
58
52
|
self.class.to_s
|
59
53
|
end
|
@@ -156,9 +150,9 @@ module Moto
|
|
156
150
|
if !condition
|
157
151
|
if evaled
|
158
152
|
# -1 because of added method header in generated class
|
159
|
-
line_number = caller.select { |l| l.match(/\(eval\):\d*:in `run'/) }.first[/\d+/].to_i
|
153
|
+
line_number = caller.select { |l| l.match(/\(eval\):\d*:in `run'/) }.first[/\d+/].to_i
|
160
154
|
else
|
161
|
-
line_number = caller.select { |l| l.match(/#{static_path}:\d*:in `run'/) }.first[/\d+/].to_i
|
155
|
+
line_number = caller.select { |l| l.match(/#{static_path}:\d*:in `run'/) }.first[/\d+/].to_i
|
162
156
|
end
|
163
157
|
|
164
158
|
status.log_failure("ASSERTION FAILED in line #{line_number}: #{message}")
|
@@ -166,7 +160,7 @@ module Moto
|
|
166
160
|
end
|
167
161
|
end
|
168
162
|
|
169
|
-
# Read a constants value from
|
163
|
+
# Read a constants value from configuration files while taking the execution environment into the account.
|
170
164
|
# @param [String] key Key to be searched for.
|
171
165
|
# @return [String] Value of the key or nil if not found
|
172
166
|
def const(key)
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.60
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartek Wilczek
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|