rutema 1.3.0 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +204 -194
- data/Manifest.txt +15 -48
- data/README.md +55 -61
- data/bin/rutema +7 -7
- data/lib/rutema/application.rb +61 -0
- data/lib/rutema/core/configuration.rb +195 -0
- data/lib/rutema/core/engine.rb +186 -0
- data/lib/rutema/core/framework.rb +28 -0
- data/lib/rutema/{objectmodel.rb → core/objectmodel.rb} +43 -48
- data/lib/rutema/core/parser.rb +35 -0
- data/lib/rutema/core/reporter.rb +105 -0
- data/lib/rutema/core/runner.rb +83 -0
- data/lib/rutema/elements/minimal.rb +47 -44
- data/lib/rutema/parsers/xml.rb +154 -186
- data/lib/rutema/version.rb +9 -0
- metadata +39 -108
- data/README.txt +0 -44
- data/Rakefile +0 -30
- data/examples/README.md +0 -17
- data/examples/config/database.rutema +0 -17
- data/examples/config/full.rutema +0 -27
- data/examples/config/minimal.rutema +0 -10
- data/examples/specs/T001.spec +0 -8
- data/examples/specs/T002.spec +0 -8
- data/examples/specs/T003.spec +0 -8
- data/examples/specs/T004.spec +0 -8
- data/examples/specs/T005.spec +0 -10
- data/examples/specs/T006.spec +0 -9
- data/examples/specs/check.spec +0 -8
- data/examples/specs/fail.spec +0 -9
- data/examples/specs/include.scenario +0 -5
- data/examples/specs/rutema.spec +0 -10
- data/examples/specs/setup.spec +0 -8
- data/examples/specs/teardown.spec +0 -8
- data/lib/rutema/configuration.rb +0 -173
- data/lib/rutema/models/activerecord.rb +0 -159
- data/lib/rutema/models/base.rb +0 -5
- data/lib/rutema/parsers/base.rb +0 -45
- data/lib/rutema/rake.rb +0 -62
- data/lib/rutema/reporters/activerecord.rb +0 -82
- data/lib/rutema/reporters/base.rb +0 -23
- data/lib/rutema/reporters/email.rb +0 -84
- data/lib/rutema/reporters/text.rb +0 -77
- data/lib/rutema/runners/default.rb +0 -157
- data/lib/rutema/runners/step.rb +0 -23
- data/lib/rutema/system.rb +0 -302
- data/test/data/duplicate_name.spec +0 -8
- data/test/data/no_title.spec +0 -5
- data/test/data/sample.spec +0 -8
- data/test/data/test_identifiers.rutema +0 -7
- data/test/test_activerecord.rb +0 -0
- data/test/test_configuration.rb +0 -43
- data/test/test_objectmodel.rb +0 -82
- data/test/test_parsers.rb +0 -131
- data/test/test_reporters.rb +0 -115
- data/test/test_runners.rb +0 -70
- data/test/test_system.rb +0 -45
data/README.md
CHANGED
@@ -1,62 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
*
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
* [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
1
|
+
##rutema
|
2
|
+
[![Build Status](https://secure.travis-ci.org/damphyr/rutema.png)](http://travis-ci.org/damphyr/rutema) [![Coverage Status](https://coveralls.io/repos/damphyr/rutema/badge.svg)](https://coveralls.io/r/damphyr/rutema) [![Code Climate](https://codeclimate.com/github/damphyr/rutema.png)](https://codeclimate.com/github/damphyr/rutema)
|
3
|
+
|
4
|
+
rutema [http://github.com/damphyr/rutema](http://github.com/damphyr/rutema)
|
5
|
+
|
6
|
+
rutema is a test execution tool and a framework for organizing and managing test execution across different tools.
|
7
|
+
|
8
|
+
It enables the combination of different test tools while it takes care of logging, reporting, archiving of results and formalizes execution of automated and manual tests.
|
9
|
+
|
10
|
+
It's purpose is to make testing in heterogeneous environments easier.
|
11
|
+
|
12
|
+
###Why?
|
13
|
+
Require consistency, repeatability and reliability from your test infrastructure while gathering data on every run.
|
14
|
+
|
15
|
+
Whether running through a checklist of manual steps, or executing a sequence of fully automated commands we always want to know if a test has failed, where it failed and what was the state of the system at that time.
|
16
|
+
|
17
|
+
rutema will gather all logs, timestamp them, store them and report on them.
|
18
|
+
|
19
|
+
Rutema core provides a reference implementation of a parser for a simple but extensible XML test specification format which works well out of the box but the framework provides clearly defined interfaces so you can write the parser for your own format and add reporters that log wherever is needed.
|
20
|
+
|
21
|
+
###The dry stuff
|
22
|
+
* Unified test execution environment for automated and manual tests
|
23
|
+
* Extensible reports and notifications in various formats (email, rss, pdf, html etc.)
|
24
|
+
* A well defined way to create a project specific test specification format
|
25
|
+
|
26
|
+
## Installation:
|
27
|
+
* gem install rutema
|
28
|
+
|
29
|
+
## Dependencies
|
30
|
+
The core functionality of rutema depends on the following gems:
|
31
|
+
* [patir](http://github.com/damphyr/patir)
|
32
|
+
* [highline](http://highline.rubyforge.org/)
|
33
|
+
|
34
|
+
## License:
|
35
|
+
(The MIT License)
|
36
|
+
|
37
|
+
Copyright (c) 2007-2015 Vassilis Rizopoulos
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
56
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/rutema
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Copyright (c) 2007-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
# Copyright (c) 2007-2015 Vassilis Rizopoulos. All rights reserved.
|
2
|
+
require 'rutema/application'
|
3
|
+
begin
|
4
|
+
Rutema::App.new(ARGV)
|
5
|
+
rescue Rutema::RutemaError
|
6
|
+
puts $!.message
|
7
|
+
exit 1
|
8
8
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require_relative "core/configuration"
|
3
|
+
require_relative "core/engine"
|
4
|
+
|
5
|
+
module Rutema
|
6
|
+
#Parses the commandline, sets up the configuration and launches Rutema::Engine
|
7
|
+
class App
|
8
|
+
def initialize command_line_args
|
9
|
+
parse_command_line(command_line_args)
|
10
|
+
@configuration=Rutema::Configuration.new(@config_file)
|
11
|
+
@configuration.context||={}
|
12
|
+
@configuration.context[:config_file]=File.basename(@config_file)
|
13
|
+
@configuration.reporters||={}
|
14
|
+
@configuration.reporters[Rutema::Reporters::Console]||={:class=>Rutema::Reporters::Console, "silent"=>@silent} unless @bare
|
15
|
+
@configuration.reporters[Rutema::Reporters::Summary]||={:class=>Rutema::Reporters::Summary, "silent"=>(@silent||@bare)}
|
16
|
+
Dir.chdir(File.dirname(@config_file)) do
|
17
|
+
@engine=Rutema::Engine.new(@configuration)
|
18
|
+
application_flow
|
19
|
+
end
|
20
|
+
end
|
21
|
+
private
|
22
|
+
def parse_command_line args
|
23
|
+
args.options do |opt|
|
24
|
+
opt.on("rutema v#{Version::STRING}")
|
25
|
+
opt.on("Options:")
|
26
|
+
opt.on("--config FILE", "-c FILE",String,"Loads the configuration from FILE") { |config_file| @config_file=config_file}
|
27
|
+
opt.on("--check","Runs just the check test"){@check=true}
|
28
|
+
#opt.on("--step","Runs test cases step by step"){@step=true}
|
29
|
+
opt.on("--silent","Suppresses console output (only for the default reporters)") { @silent=true}
|
30
|
+
opt.on("--bare","No default reporters whatsoever") { @bare=true}
|
31
|
+
#opt.on("--color","Adds color to the Console reporter") { @color=true}
|
32
|
+
opt.on("-v", "--version","Displays the version") { $stdout.puts("rutema v#{Version::STRING}");exit 0 }
|
33
|
+
opt.on("--help", "-h", "-?", "This text") { $stdout.puts opt; exit 0 }
|
34
|
+
opt.on("You can provide a specification filename in order to run a single test")
|
35
|
+
opt.parse!
|
36
|
+
#and now the rest
|
37
|
+
unless @config_file
|
38
|
+
puts "No configuration file defined!\n"
|
39
|
+
$stdout.puts opt
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
if !args.empty?
|
43
|
+
@test_identifier=args.shift
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def application_flow
|
48
|
+
if @check
|
49
|
+
#run just the check test
|
50
|
+
if @configuration.check
|
51
|
+
exit @engine.run(@configuration.check)
|
52
|
+
else
|
53
|
+
raise Rutema::RutemaError,"There is no check test defined in the configuration."
|
54
|
+
end
|
55
|
+
else
|
56
|
+
#run everything
|
57
|
+
exit @engine.run(@test_identifier)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# Copyright (c) 2007-2015 Vassilis Rizopoulos. All rights reserved.
|
2
|
+
require 'ostruct'
|
3
|
+
require_relative 'parser'
|
4
|
+
require_relative 'reporter'
|
5
|
+
module Rutema
|
6
|
+
#This module defines the "configuration directives" used in the configuration of Rutema
|
7
|
+
#
|
8
|
+
#Example
|
9
|
+
#A configuration file needs as a minimum to define which parser to use and which tests to run.
|
10
|
+
#
|
11
|
+
#Since rutema configuration files are valid Ruby code, you can use the full power of the Ruby language including require directives
|
12
|
+
#
|
13
|
+
# require 'rake'
|
14
|
+
# configuration.parser={:class=>Rutema::MinimalXMLParser}
|
15
|
+
# configuration.tests=FileList['all/of/the/tests/**/*.*']
|
16
|
+
module ConfigurationDirectives
|
17
|
+
attr_reader :parser,:runner,:tools,:paths,:tests,:context,:check,:setup,:teardown
|
18
|
+
attr_accessor :reporters
|
19
|
+
#Adds a hash of values to the tools hash of the configuration
|
20
|
+
#
|
21
|
+
#This hash is then accessible in the parser and reporters as a property of the configuration instance
|
22
|
+
#
|
23
|
+
#Required keys:
|
24
|
+
# :name - the name to use for accessing the path in code
|
25
|
+
#Example:
|
26
|
+
# configure do |cfg|
|
27
|
+
# cfg.tool={:name=>"nunit",:path=>"/bin/nunit",:configuration=>{:important=>"info"}}
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
#The path to nunit can then be accessed in the parser as
|
31
|
+
# @configuration.tools.nunit[:path]
|
32
|
+
#
|
33
|
+
#This way you can pass configuration information for the tools you use
|
34
|
+
def tool= definition
|
35
|
+
raise ConfigurationException,"required key :name is missing from #{definition}" unless definition[:name]
|
36
|
+
@tools[definition[:name]]=definition
|
37
|
+
end
|
38
|
+
#Adds a path to the paths hash of the configuration
|
39
|
+
#
|
40
|
+
#Required keys:
|
41
|
+
# :name - the name to use for accessing the path in code
|
42
|
+
# :path - the path
|
43
|
+
#Example:
|
44
|
+
# cfg.path={:name=>"sources",:path=>"/src"}
|
45
|
+
def path= definition
|
46
|
+
raise ConfigurationException,"required key :name is missing from #{definition}" unless definition[:name]
|
47
|
+
raise ConfigurationException,"required key :path is missing from #{definition}" unless definition[:path]
|
48
|
+
@paths[definition[:name]]=definition[:path]
|
49
|
+
end
|
50
|
+
|
51
|
+
#Path to the setup specification. (optional)
|
52
|
+
#
|
53
|
+
#The setup test runs before every test.
|
54
|
+
def setup= path
|
55
|
+
@setup=check_path(path)
|
56
|
+
end
|
57
|
+
|
58
|
+
#Path to the teardown specification. (optional)
|
59
|
+
#
|
60
|
+
#The teardown test runs after every test.
|
61
|
+
def teardown= path
|
62
|
+
@teardown=check_path(path)
|
63
|
+
end
|
64
|
+
|
65
|
+
#Path to the check specification. (optional)
|
66
|
+
#
|
67
|
+
#The check test runs once in the beginning before all the tests.
|
68
|
+
#
|
69
|
+
#If it fails no tests are run.
|
70
|
+
def check= path
|
71
|
+
@check=check_path(path)
|
72
|
+
end
|
73
|
+
|
74
|
+
#Hash values for passing data to the system. It's supposed to be used in the reporters and contain
|
75
|
+
#values such as version numbers, tester names etc.
|
76
|
+
def context= definition
|
77
|
+
@context||=Hash.new
|
78
|
+
raise ConfigurationException,"Only accepting hash values as context_data" unless definition.kind_of?(Hash)
|
79
|
+
@context.merge!(definition)
|
80
|
+
end
|
81
|
+
|
82
|
+
#Adds the specification identifiers available to this instance of Rutema
|
83
|
+
#
|
84
|
+
#These will usually be files, but they can be anything.
|
85
|
+
#Essentially this is an Array of strings that mean something to your parser
|
86
|
+
def tests= array_of_identifiers
|
87
|
+
@tests+=array_of_identifiers.map{|f| full_path(f)}
|
88
|
+
end
|
89
|
+
|
90
|
+
#A hash defining the parser to use.
|
91
|
+
#
|
92
|
+
#The hash is passed as is to the parser constructor and each parser should define the necessary configuration keys.
|
93
|
+
#
|
94
|
+
#The only required key from the configurator's point fo view is :class which should be set to the fully qualified name of the class to use.
|
95
|
+
#
|
96
|
+
#Example:
|
97
|
+
# cfg.parser={:class=>Rutema::MinimalXMLParser}
|
98
|
+
def parser= definition
|
99
|
+
raise ConfigurationException,"required key :class is missing from #{definition}" unless definition[:class]
|
100
|
+
@parser=definition
|
101
|
+
end
|
102
|
+
|
103
|
+
#Adds a reporter to the configuration.
|
104
|
+
#
|
105
|
+
#As with the parser, the only required configuration key is :class and the definition hash is passed to the class' constructor.
|
106
|
+
#
|
107
|
+
#Unlike the parser, you can define multiple reporters.
|
108
|
+
def reporter= definition
|
109
|
+
raise ConfigurationException,"required key :class is missing from #{definition}" unless definition[:class]
|
110
|
+
@reporters[definition[:class]]=definition
|
111
|
+
end
|
112
|
+
|
113
|
+
def init
|
114
|
+
@reporters={}
|
115
|
+
@context={}
|
116
|
+
@tests=[]
|
117
|
+
@tools=OpenStruct.new
|
118
|
+
@paths=OpenStruct.new
|
119
|
+
end
|
120
|
+
private
|
121
|
+
#Checks if a path exists and raises a ConfigurationException if not
|
122
|
+
def check_path path
|
123
|
+
path=File.expand_path(path)
|
124
|
+
raise ConfigurationException,"#{path} does not exist" unless File.exists?(path)
|
125
|
+
return path
|
126
|
+
end
|
127
|
+
#Gives back a string of key=value,key=value for a hash
|
128
|
+
def definition_string definition
|
129
|
+
msg=Array.new
|
130
|
+
definition.each{|k,v| msg<<"#{k}=#{v}"}
|
131
|
+
return msg.join(",")
|
132
|
+
end
|
133
|
+
|
134
|
+
def full_path filename
|
135
|
+
return File.expand_path(filename) if File.exists?(filename)
|
136
|
+
return filename
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class ConfigurationException<RuntimeError
|
141
|
+
end
|
142
|
+
|
143
|
+
class Configuration
|
144
|
+
include ConfigurationDirectives
|
145
|
+
attr_reader :filename
|
146
|
+
def initialize config_file
|
147
|
+
@filename=config_file
|
148
|
+
init
|
149
|
+
load_configuration(@filename)
|
150
|
+
end
|
151
|
+
|
152
|
+
def configure
|
153
|
+
if block_given?
|
154
|
+
yield self
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
#Loads the configuration from a file
|
159
|
+
#
|
160
|
+
#Use this to chain configuration files together
|
161
|
+
#==Example
|
162
|
+
#Say you have on configuration file "first.rutema" that contains all the generic directives and several others that change only one or two things.
|
163
|
+
#
|
164
|
+
#You can import the first.rutema file in the other configurations with
|
165
|
+
# import("first.rutema")
|
166
|
+
def import filename
|
167
|
+
fnm = File.expand_path(filename)
|
168
|
+
if File.exists?(fnm)
|
169
|
+
load_configuration(fnm)
|
170
|
+
else
|
171
|
+
raise ConfigurationException, "Import error: Can't find #{fnm}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
private
|
175
|
+
def load_configuration filename
|
176
|
+
begin
|
177
|
+
cfg_txt=File.read(filename)
|
178
|
+
cwd=File.expand_path(File.dirname(filename))
|
179
|
+
#evaluate in the working directory to enable relative paths in configuration
|
180
|
+
Dir.chdir(cwd){eval(cfg_txt,binding(),filename,__LINE__)}
|
181
|
+
rescue ConfigurationException
|
182
|
+
#pass it on, do not wrap again
|
183
|
+
raise
|
184
|
+
rescue SyntaxError
|
185
|
+
#Just wrap the exception so we can differentiate
|
186
|
+
raise ConfigurationException.new,"Syntax error in the configuration file '#{filename}':\n#{$!.message}"
|
187
|
+
rescue NoMethodError
|
188
|
+
raise ConfigurationException.new,"Encountered an unknown directive in configuration file '#{filename}':\n#{$!.message}"
|
189
|
+
rescue
|
190
|
+
#Just wrap the exception so we can differentiate
|
191
|
+
raise ConfigurationException.new,"#{$!.message}"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# Copyright (c) 2007-2015 Vassilis Rizopoulos. All rights reserved.
|
2
|
+
require 'thread'
|
3
|
+
require_relative 'parser'
|
4
|
+
require_relative 'reporter'
|
5
|
+
require_relative 'runner'
|
6
|
+
require_relative '../version'
|
7
|
+
|
8
|
+
module Rutema
|
9
|
+
class Engine
|
10
|
+
include Messaging
|
11
|
+
def initialize configuration
|
12
|
+
@queue=Queue.new
|
13
|
+
@parser=instantiate_class(configuration.parser,configuration) if configuration.parser
|
14
|
+
if configuration.runner
|
15
|
+
@runner=instantiate_class(configuration.runner,configuration)
|
16
|
+
else
|
17
|
+
@runner=Rutema::Runners::Default.new(configuration.context,@queue)
|
18
|
+
end
|
19
|
+
raise RutemaError,"Could not instantiate parser" unless @parser
|
20
|
+
@dispatcher=Dispatcher.new(@queue,configuration)
|
21
|
+
@configuration=configuration
|
22
|
+
end
|
23
|
+
def run test_identifier=nil
|
24
|
+
@dispatcher.run!
|
25
|
+
#start
|
26
|
+
message("start")
|
27
|
+
check,setup,teardown,tests=*parse(test_identifier)
|
28
|
+
if tests.empty?
|
29
|
+
error(test_identifier,"Did not parse any tests succesfully")
|
30
|
+
@dispatcher.exit
|
31
|
+
raise RutemaError,"Did not parse any tests succesfully"
|
32
|
+
else
|
33
|
+
@runner.setup=setup
|
34
|
+
@runner.teardown=teardown
|
35
|
+
#running - at this point we've done any and all checks and we're stepping on the gas
|
36
|
+
message("running")
|
37
|
+
run_scenarios(tests,check)
|
38
|
+
end
|
39
|
+
message("end")
|
40
|
+
@dispatcher.exit
|
41
|
+
@dispatcher.report(tests)
|
42
|
+
end
|
43
|
+
def parse test_identifier=nil
|
44
|
+
specs=[]
|
45
|
+
#so, while we are parsing, we have a list of tests
|
46
|
+
#we're either parsing all of the tests, or just one
|
47
|
+
#make sure the one test is on the list
|
48
|
+
if test_identifier
|
49
|
+
if @configuration.tests.include?(File.expand_path(test_identifier))
|
50
|
+
specs<<parse_specification(File.expand_path(test_identifier))
|
51
|
+
else
|
52
|
+
error(test_identifier,"Does not exist in the configuration")
|
53
|
+
end
|
54
|
+
else
|
55
|
+
specs=parse_specifications(@configuration.tests)
|
56
|
+
end
|
57
|
+
check,setup,teardown=parse_specials(@configuration)
|
58
|
+
return [check,setup,teardown,specs]
|
59
|
+
end
|
60
|
+
private
|
61
|
+
def parse_specifications tests
|
62
|
+
tests.map{|t| parse_specification(t)}.compact
|
63
|
+
end
|
64
|
+
def parse_specification spec_identifier
|
65
|
+
begin
|
66
|
+
@parser.parse_specification(spec_identifier)
|
67
|
+
rescue Rutema::ParserError
|
68
|
+
error(spec_identifier,$!.message)
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
def parse_specials configuration
|
73
|
+
check=nil
|
74
|
+
setup=nil
|
75
|
+
teardown=nil
|
76
|
+
if configuration.check
|
77
|
+
check=parse_specification(configuration.check)
|
78
|
+
end
|
79
|
+
if configuration.setup
|
80
|
+
setup=parse_specification(configuration.setup)
|
81
|
+
end
|
82
|
+
if configuration.teardown
|
83
|
+
teardown=parse_specification(configuration.teardown)
|
84
|
+
end
|
85
|
+
return check,setup,teardown
|
86
|
+
end
|
87
|
+
def run_scenarios specs,check
|
88
|
+
if specs.empty?
|
89
|
+
error(nil,"No tests to run")
|
90
|
+
else
|
91
|
+
if check
|
92
|
+
if run_test(check)==:success
|
93
|
+
specs.each{|s| run_test(s)}
|
94
|
+
else
|
95
|
+
error(nil,"Check test failed")
|
96
|
+
end
|
97
|
+
else
|
98
|
+
specs.each{|spec| run_test(spec)}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
def run_test specification
|
103
|
+
if specification.scenario
|
104
|
+
status=@runner.run(specification)["status"]
|
105
|
+
else
|
106
|
+
status=:not_executed
|
107
|
+
message(:test=>specification.name,:message=>"No scenario", :status=>status)
|
108
|
+
end
|
109
|
+
return status
|
110
|
+
end
|
111
|
+
def instantiate_class definition,configuration
|
112
|
+
if definition[:class]
|
113
|
+
klass=definition[:class]
|
114
|
+
return klass.new(configuration)
|
115
|
+
end
|
116
|
+
return nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
class Dispatcher
|
120
|
+
INTERVAL=0.01
|
121
|
+
def initialize queue,configuration
|
122
|
+
@queue = queue
|
123
|
+
@queues = {}
|
124
|
+
@streaming_reporters=[]
|
125
|
+
@block_reporters=[]
|
126
|
+
@collector=Rutema::Reporters::Collector.new(nil,self)
|
127
|
+
if configuration.reporters
|
128
|
+
instances=configuration.reporters.values.map{|v| instantiate_reporter(v,configuration) if v[:class] != Reporters::Summary}.compact
|
129
|
+
@streaming_reporters,_=instances.partition{|rep| rep.respond_to?(:update)}
|
130
|
+
@block_reporters,_=instances.partition{|rep| rep.respond_to?(:report)}
|
131
|
+
end
|
132
|
+
@streaming_reporters<<@collector
|
133
|
+
@configuration=configuration
|
134
|
+
end
|
135
|
+
def subscribe identifier
|
136
|
+
@queues[identifier]=Queue.new
|
137
|
+
return @queues[identifier]
|
138
|
+
end
|
139
|
+
|
140
|
+
def run!
|
141
|
+
@streaming_reporters.each {|r| r.run!}
|
142
|
+
@thread=Thread.new do
|
143
|
+
while true do
|
144
|
+
dispatch()
|
145
|
+
sleep INTERVAL
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def report specs
|
151
|
+
@block_reporters.each do |r|
|
152
|
+
r.report(specs,@collector.states,@collector.errors)
|
153
|
+
end
|
154
|
+
Reporters::Summary.new(@configuration,self).report(specs,@collector.states,@collector.errors)
|
155
|
+
end
|
156
|
+
def exit
|
157
|
+
if @thread
|
158
|
+
flush
|
159
|
+
@streaming_reporters.each {|r| r.exit}
|
160
|
+
Thread.kill(@thread)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
private
|
164
|
+
def flush
|
165
|
+
if @thread
|
166
|
+
while @queue.size>0 do
|
167
|
+
dispatch()
|
168
|
+
sleep INTERVAL
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
def instantiate_reporter definition,configuration
|
173
|
+
if definition[:class]
|
174
|
+
klass=definition[:class]
|
175
|
+
return klass.new(configuration,self)
|
176
|
+
end
|
177
|
+
return nil
|
178
|
+
end
|
179
|
+
def dispatch
|
180
|
+
if @queue.size>0
|
181
|
+
data=@queue.pop
|
182
|
+
@queues.each{ |i,q| q.push(data) } if data
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|