moto 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,27 +54,24 @@ module Moto
54
54
  test_object = nil
55
55
 
56
56
  # Checking if it's possible to create test based on provided path. In case something is wrong with
57
- # modules structure in class itself Moto::Test will be instantized with raise injected into its run()
57
+ # modules structure in class itself Moto::Test::Base will be instantized with raise injected into its run()
58
58
  # so we can have proper reporting and summary even if the test doesn't execute.
59
59
  begin
60
60
  class_name = test_path_absolute.gsub("#{MotoApp::DIR}/",'moto_app/').camelize.chomp('.rb').constantize
61
61
  test_object = class_name.new
62
62
  rescue NameError
63
- class_name = Moto::Test
63
+ class_name = Moto::Test::Base
64
64
  test_object = class_name.new
65
65
 
66
66
  class << test_object
67
67
  attr_accessor :custom_name
68
- end
69
-
70
- test_object.custom_name = test_path_absolute.gsub("#{MotoApp::DIR}/",'moto_app/').camelize.chomp('.rb')
71
68
 
72
- class << test_object
73
69
  def run
74
70
  raise "ERROR: Invalid module structure: #{custom_name}"
75
71
  end
76
72
  end
77
73
 
74
+ test_object.custom_name = test_path_absolute.gsub("#{MotoApp::DIR}/",'moto_app/').camelize.chomp('.rb')
78
75
  end
79
76
 
80
77
  test_object.static_path = test_path_absolute
@@ -83,7 +80,7 @@ module Moto
83
80
  end
84
81
 
85
82
  def generate_for_run_body(test_path_absolute, method_body)
86
- base = Moto::Test
83
+ base = Moto::Test::Base
87
84
  base_class_string = method_body.match( /^#\s*BASE_CLASS:\s(\S+)/ )
88
85
  unless base_class_string.nil?
89
86
  base_class_string = base_class_string[1].strip
@@ -6,14 +6,15 @@ module Moto
6
6
  # all resources specific for single thread will be initialized here. E.g. browser session
7
7
  attr_reader :runner
8
8
  attr_reader :logger
9
- # attr_reader :log_path
10
9
  attr_reader :current_test
11
10
 
12
- def initialize(runner, test)
11
+ def initialize(runner, test, test_reporter)
13
12
  @runner = runner
14
13
  @test = test
15
14
  @clients = {}
16
15
  @test.context = self
16
+ @test_reporter = test_reporter
17
+
17
18
  #TODO temporary fix
18
19
  Thread.current['context']= self
19
20
 
@@ -65,10 +66,10 @@ module Moto
65
66
  key = key.to_s
66
67
  key = "#{@current_test.env.to_s}.#{key}" if @current_test.env != :__default
67
68
  code = if key.include? '.'
68
- "@config#{key.split('.').map{|a| "['#{a}']" }.join('')}"
69
- else
70
- "@config['#{key}']"
71
- end
69
+ "@config#{key.split('.').map { |a| "['#{a}']" }.join('')}"
70
+ else
71
+ "@config['#{key}']"
72
+ end
72
73
  begin
73
74
  v = eval code
74
75
  raise if v.nil?
@@ -80,59 +81,77 @@ module Moto
80
81
 
81
82
  def run
82
83
  # remove log/screenshot files from previous execution
83
- Dir.glob("#{@test.dir}/*.{log,png}").each {|f| File.delete f }
84
+ Dir.glob("#{@test.dir}/*.{log,png}").each { |f| File.delete f }
84
85
  max_attempts = @runner.my_config[:max_attempts] || 1
85
86
  sleep_time = @runner.my_config[:sleep_before_attempt] || 0
87
+
86
88
  @runner.environments.each do |env|
87
89
  params_all = [{}]
88
90
 
89
- # YAML config files
90
- #params_path = "#{@test.dir}/#{@test.filename}_params.yml"
91
- #params_all = YAML.load(ERB.new(File.read(params_path)).result) if File.exists?(params_path)
92
-
93
91
  # RB Config files
94
92
  params_path = "#{@test.dir}/#{@test.filename}"
95
93
  params_all = eval(File.read(params_path)) if File.exists?(params_path)
96
94
 
97
95
  params_all.each_with_index do |params, params_index|
96
+
98
97
  # Filtering out param sets that are specific to certain envs
99
98
  unless params['__env'].nil?
100
- allowed_envs = params['__env'].is_a?(String) ? [params['__env']] : params['__env']
99
+ allowed_envs = params['__env'].is_a?(String) ? [params['__env']] : params['__env']
101
100
  next unless allowed_envs.include? env
102
101
  end
102
+
103
+ @test.init(env, params, params_index)
104
+ @test.log_path = "#{@test.dir}/#{@test.name.gsub(/\s+/, '_').gsub(':', '_').gsub('::', '_').gsub('/', '_')}.log"
105
+ # TODO: log path might be specified (to some extent) by the configuration
106
+ @logger = Logger.new(File.open(@test.log_path, File::WRONLY | File::TRUNC | File::CREAT))
107
+ @logger.level = @runner.my_config[:log_level] || Logger::DEBUG
108
+ @current_test = @test
109
+
103
110
  (1..max_attempts).each do |attempt|
104
- @test.init(env, params, params_index)
105
- # TODO: log path might be specified (to some extent) by the configuration
106
- #@test.log_path = "#{@test.dir}/#{@test.name.gsub(/\s+/, '_').gsub(':', '_').gsub('::', '_').gsub('/', '_')}.log"
107
- @test.log_path = "#{@test.dir}/#{@test.name.demodulize.gsub('/', '_')}.log"
108
- @logger = Logger.new(File.open(@test.log_path, File::WRONLY | File::TRUNC | File::CREAT))
109
- @logger.level = @runner.my_config[:log_level] || Logger::DEBUG
110
- @current_test = @test
111
- @runner.listeners.each { |l| l.start_test(@test) }
111
+
112
+ # Reporting: start_test
113
+ if attempt == 1
114
+ @test_reporter.report_start_test(@test.status)
115
+ end
116
+
112
117
  @clients.each_value { |c| c.start_test(@test) }
113
118
  @test.before
114
119
  @logger.info "Start: #{@test.name} attempt #{attempt}/#{max_attempts}"
120
+
115
121
  begin
116
- @test.run
117
- rescue Exceptions::TestForcedPassed, Exceptions::TestForcedFailure, Exceptions::TestSkipped => e
118
- logger.info(e.message)
119
- @runner.result.add_error(@test, e)
122
+ @test.run_test
123
+ rescue Exceptions::TestForcedPassed, Exceptions::TestForcedFailure, Exceptions::TestSkipped => e
124
+ @logger.info(e.message)
120
125
  rescue Exception => e
121
126
  @logger.error("#{e.class.name}: #{e.message}")
122
127
  @logger.error(e.backtrace.join("\n"))
123
128
  @clients.each_value { |c| c.handle_test_exception(@test, e) }
124
- @runner.result.add_error(@test, e)
125
129
  end
130
+
126
131
  @test.after
127
132
  @clients.each_value { |c| c.end_test(@test) }
128
- # HAX: running end_test on results now, on other listeners after logger is closed
129
- @runner.listeners.first.end_test(@test)
130
- @logger.info("Result: #{@test.result}")
131
- @logger.close
132
- @runner.listeners[1..-1].each { |l| l.end_test(@test) }
133
- break unless [Result::FAILURE, Result::ERROR].include? @test.result
134
- sleep sleep_time unless attempt.equal? max_attempts
135
- end # RETRY
133
+
134
+ @logger.info("Result: #{@test.status.results.last.code}")
135
+
136
+ # test should have another attempt only in case of an error
137
+ # pass, skip and fail statuses end attempts
138
+ if @test.status.results.last.code != Moto::Test::Result::ERROR
139
+ break
140
+ end
141
+
142
+ # don't go to sleep in the last attempt
143
+ if attempt < max_attempts
144
+ sleep sleep_time
145
+ end
146
+
147
+ end # Make another attempt
148
+
149
+ # Close and flush stream to file
150
+ @logger.close
151
+
152
+ # Reporting: end_test
153
+ @test_reporter.report_end_test(@test.status)
154
+
136
155
  end
137
156
  end
138
157
  @clients.each_value { |c| c.end_run }
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Moto
2
- VERSION = '0.0.31'
2
+ VERSION = '0.0.32'
3
3
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartek Wilczek
8
8
  - Maciej Stark
9
9
  - Radosław Sporny
10
+ - Michał Kujawski
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2016-03-21 00:00:00.000000000 Z
14
+ date: 2016-03-30 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: activesupport
@@ -76,6 +77,7 @@ email:
76
77
  - bwilczek@gmail.com
77
78
  - stark.maciej@gmail.com
78
79
  - r.sporny@gmail.com
80
+ - michal.kujawski@gmail.com
79
81
  executables:
80
82
  - moto
81
83
  extensions: []
@@ -83,7 +85,6 @@ extra_rdoc_files: []
83
85
  files:
84
86
  - bin/moto
85
87
  - lib/app_generator.rb
86
- - lib/assert.rb
87
88
  - lib/cli.rb
88
89
  - lib/clients/base.rb
89
90
  - lib/clients/website.rb
@@ -94,17 +95,20 @@ files:
94
95
  - lib/exceptions/test_skipped.rb
95
96
  - lib/forward_context_methods.rb
96
97
  - lib/initializer.rb
97
- - lib/listeners/base.rb
98
- - lib/listeners/console.rb
99
- - lib/listeners/console_dots.rb
100
- - lib/listeners/junit_xml.rb
101
- - lib/listeners/webui.rb
102
98
  - lib/page.rb
103
99
  - lib/parser.rb
104
- - lib/result.rb
100
+ - lib/reporting/listeners/base.rb
101
+ - lib/reporting/listeners/console.rb
102
+ - lib/reporting/listeners/console_dots.rb
103
+ - lib/reporting/listeners/junit_xml.rb
104
+ - lib/reporting/listeners/webui.rb
105
+ - lib/reporting/run_status.rb
106
+ - lib/reporting/test_reporter.rb
105
107
  - lib/runner.rb
106
108
  - lib/runner_logging.rb
107
- - lib/test.rb
109
+ - lib/test/base.rb
110
+ - lib/test/result.rb
111
+ - lib/test/status.rb
108
112
  - lib/test_generator.rb
109
113
  - lib/test_logging.rb
110
114
  - lib/thread_context.rb
data/lib/assert.rb DELETED
@@ -1,32 +0,0 @@
1
- module Moto
2
- module Assert
3
-
4
- def assert_equal(a, b)
5
- assert(a==b, "Arguments should be equal: #{a} != #{b}.")
6
- end
7
-
8
- def assert_true(b)
9
- assert(b, "Logical condition not met, expecting true, given false.")
10
- end
11
-
12
- def assert_false(b)
13
- assert(!b, "Logical condition not met, expecting false, given true.")
14
- end
15
-
16
- def assert(condition, message)
17
- unless condition
18
-
19
- line_number = if @context.current_test.evaled
20
- caller.select{ |l| l.match(/\(eval\):\d*:in `run'/) }.first[/\d+/].to_i - 1 # -1 because of added method header in generated class
21
- else
22
- line_number = caller.select{ |l| l.match(/#{@context.current_test.static_path}:\d*:in `run'/) }.first[/\d+/].to_i - 1
23
- end
24
-
25
- full_message = "ASSERTION FAILED in line #{line_number}: #{message}"
26
- @context.runner.result.add_failure(self, full_message)
27
- logger.error(full_message)
28
- end
29
- end
30
-
31
- end
32
- end
@@ -1,26 +0,0 @@
1
- module Moto
2
- module Listeners
3
- class Base
4
-
5
- def initialize(runner)
6
- @runner=runner
7
- end
8
-
9
- def start_run
10
- # abstract
11
- end
12
-
13
- def end_run
14
- # abstract
15
- end
16
-
17
- def start_test(test)
18
- # abstract
19
- end
20
-
21
- def end_test(test)
22
- # abstract
23
- end
24
- end
25
- end
26
- end
@@ -1,29 +0,0 @@
1
- module Moto
2
- module Listeners
3
- class Console < Base
4
-
5
- def start_run
6
- puts "START"
7
- end
8
-
9
- def end_run
10
- puts ""
11
- puts "FINISHED: #{@runner.result.summary[:result]}, duration: #{Time.at(@runner.result.summary[:duration]).utc.strftime("%H:%M:%S")}"
12
- puts "Tests executed: #{@runner.result.summary[:cnt_all]}"
13
- puts " Passed: #{@runner.result.summary[:cnt_passed]}"
14
- puts " Failure: #{@runner.result.summary[:cnt_failure]}"
15
- puts " Error: #{@runner.result.summary[:cnt_error]}"
16
- puts " Skipped: #{@runner.result.summary[:cnt_skipped]}"
17
- end
18
-
19
- def start_test(test)
20
- print test.name
21
- end
22
-
23
- def end_test(test)
24
- puts "\t#{@runner.result[test.name][:result]}"
25
- end
26
-
27
- end
28
- end
29
- end
@@ -1,63 +0,0 @@
1
- module Moto
2
- module Listeners
3
- class ConsoleDots < Base
4
-
5
- def start_run
6
- end
7
-
8
- def end_run
9
- puts ""
10
- puts ""
11
- puts "FINISHED: #{@runner.result.summary[:result]}, duration: #{Time.at(@runner.result.summary[:duration]).utc.strftime("%H:%M:%S")}"
12
- puts "Tests executed: #{@runner.result.summary[:cnt_all]}"
13
- puts " Passed: #{@runner.result.summary[:cnt_passed]}"
14
- puts " Failure: #{@runner.result.summary[:cnt_failure]}"
15
- puts " Error: #{@runner.result.summary[:cnt_error]}"
16
- puts " Skipped: #{@runner.result.summary[:cnt_skipped]}"
17
-
18
- if @runner.result.summary[:cnt_failure] > 0
19
- puts ""
20
- puts "FAILURES: "
21
- @runner.result.summary[:tests_failure].each do |test_name, data|
22
- puts test_name
23
- puts "\t#{data[:failures].join("\n\t")}"
24
- puts ""
25
- end
26
- end
27
-
28
- if @runner.result.summary[:cnt_error] > 0
29
- puts ""
30
- puts "ERRORS: "
31
- @runner.result.summary[:tests_error].each do |test_name, data|
32
- puts test_name
33
- puts "\t#{data[:error]}"
34
- puts ""
35
- end
36
- end
37
-
38
- if @runner.result.summary[:cnt_skipped] > 0
39
- puts ""
40
- puts "SKIPPED: "
41
- @runner.result.summary[:tests_skipped].each do |test_name, data|
42
- puts test_name
43
- puts "\t#{data[:error]}"
44
- puts ""
45
- end
46
- end
47
- end
48
-
49
- def start_test(test)
50
- end
51
-
52
- def end_test(test)
53
- print case @runner.result[test.name][:result]
54
- when :passed then "."
55
- when :failure then "F"
56
- when :error then "E"
57
- when :skipped then "s"
58
- end
59
- end
60
-
61
- end
62
- end
63
- end
@@ -1,37 +0,0 @@
1
- require 'nokogiri'
2
-
3
- module Moto
4
- module Listeners
5
- class JunitXml < Base
6
-
7
- def end_run
8
- path = @runner.my_config[:output_file]
9
-
10
- builder = Nokogiri::XML::Builder.new { |xml|
11
- xml.testsuite(
12
- errors: @runner.result.summary[:cnt_error],
13
- failures: @runner.result.summary[:cnt_failure],
14
- name: "Moto run",
15
- tests: @runner.result.summary[:cnt_all],
16
- time: @runner.result.summary[:duration],
17
- timestamp: Time.at(@runner.result.summary[:started_at])) do
18
- @runner.result.all.each do |test_name, data|
19
- xml.testcase(name: test_name, time: data[:duration], classname: data[:class].name, moto_result: data[:result]) do
20
- if !data[:error].nil?
21
- xml.error(message: data[:error].message)
22
- elsif data[:failures].count > 0
23
- data[:failures].each do |f|
24
- xml.failure(message: f)
25
- end
26
- end
27
- end
28
- end
29
- end
30
- }
31
-
32
- File.open(path, 'w') {|f| f.write(builder.to_xml) }
33
- end
34
-
35
- end
36
- end
37
- end
@@ -1,71 +0,0 @@
1
- require 'rest-client'
2
- require 'sys/uname'
3
-
4
- module Moto
5
- module Listeners
6
- class Webui < Base
7
-
8
- def start_run
9
- # POST http://sandbox.dev:3000/api/runs/create
10
- @url = @runner.my_config[:url]
11
- data = {
12
- name: @runner.name,
13
- result: Moto::Result::RUNNING,
14
- cnt_all: nil,
15
- cnt_passed: nil,
16
- cnt_failure: nil,
17
- cnt_error: nil,
18
- cnt_skipped: nil,
19
- user: Sys::Uname.sysname.downcase.include?('windows') ? ENV['USERNAME'] : ENV['LOGNAME'],
20
- host: Sys::Uname.nodename,
21
- pid: Process.pid
22
- }
23
- @run = JSON.parse( RestClient.post( "#{@url}/api/runs", data.to_json, :content_type => :json, :accept => :json ) )
24
- @tests = {}
25
- end
26
-
27
- def end_run
28
- # PUT http://sandbox.dev:3000/api/runs/1
29
- data = {
30
- result: @runner.result.summary[:result],
31
- cnt_all: @runner.result.summary[:cnt_all],
32
- cnt_passed: @runner.result.summary[:cnt_passed],
33
- cnt_failure: @runner.result.summary[:cnt_failure],
34
- cnt_error: @runner.result.summary[:cnt_error],
35
- cnt_skipped: @runner.result.summary[:cnt_skipped],
36
- duration: @runner.result.summary[:duration]
37
- }
38
- @run = JSON.parse( RestClient.put( "#{@url}/api/runs/#{@run['id']}", data.to_json, :content_type => :json, :accept => :json ) )
39
- end
40
-
41
- def start_test(test)
42
- # POST http://sandbox.dev:3000/api/tests/create
43
- data = {
44
- name: test.name,
45
- class_name: test.class.name,
46
- log: nil,
47
- run_id: @run['id'],
48
- env: test.env,
49
- parameters: test.params.to_s,
50
- result: Moto::Result::RUNNING,
51
- error: nil,
52
- failures: nil,
53
- }
54
- @tests[test.name] = JSON.parse( RestClient.post( "#{@url}/api/tests", data.to_json, :content_type => :json, :accept => :json ) )
55
- end
56
-
57
- def end_test(test)
58
- log = File.read(test.log_path)
59
- data = {
60
- log: log,
61
- result: @runner.result[test.name][:result],
62
- error: @runner.result[test.name][:error].nil? ? nil : @runner.result[test.name][:error].message,
63
- failures: @runner.result[test.name][:failures].join("\n\t"),
64
- duration: @runner.result[test.name][:duration]
65
- }
66
- @tests[test.name] = JSON.parse( RestClient.put( "#{@url}/api/tests/#{@tests[test.name]['id']}", data.to_json, :content_type => :json, :accept => :json ) )
67
- end
68
-
69
- end
70
- end
71
- end