rutema 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +0 -2
- data/lib/rutema/reporters/activerecord.rb +37 -8
- data/lib/rutema/specification.rb +4 -0
- data/lib/rutema/system.rb +8 -3
- data/test/distro_test/config/database.rutema +1 -1
- data/test/distro_test/config/full.rutema +1 -1
- data/test/rutema.rutema +1 -1
- data/test/test_reporter.rb +0 -0
- metadata +2 -4
- data/lib/rutema/db.rb +0 -128
- data/test/distro_test/config/jruby.rutema +0 -10
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 1.0.8 / 2009-11-13
|
2
|
+
* ActiveRecordReporter now accepts all activerecord adapter parameters - you can now connect to DBs other than sqlite3
|
3
|
+
* Reporter delegation now more robust (rutemax will exit gracefully and log if one reporter bombs)
|
4
|
+
* The old db connection code was removed. Explicit dependencies to adapters are also absent - you have to now have the appropriate gems for the ActiveRecordReporter to work properly
|
1
5
|
== 1.0.7 / 2009-09-11
|
2
6
|
* Steps now include the commandline (if there) in their name - makes the logs more readable
|
3
7
|
* Added a check for nil states to ensure reporters always get valid data
|
data/Manifest.txt
CHANGED
@@ -7,7 +7,6 @@ bin/rutemax
|
|
7
7
|
bin/rutema_upgrader
|
8
8
|
distro_test.sh
|
9
9
|
lib/rutema/configuration.rb
|
10
|
-
lib/rutema/db.rb
|
11
10
|
lib/rutema/gems.rb
|
12
11
|
lib/rutema/model.rb
|
13
12
|
lib/rutema/reporter.rb
|
@@ -21,7 +20,6 @@ selftest.sh
|
|
21
20
|
test/data/sample09.db
|
22
21
|
test/distro_test/config/database.rutema
|
23
22
|
test/distro_test/config/full.rutema
|
24
|
-
test/distro_test/config/jruby.rutema
|
25
23
|
test/distro_test/config/minimal.rutema
|
26
24
|
test/distro_test/specs/T001.spec
|
27
25
|
test/distro_test/specs/T002.spec
|
@@ -3,13 +3,45 @@ $:.unshift File.join(File.dirname(__FILE__),"..","..")
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'rutema/reporter'
|
5
5
|
require 'rutema/model'
|
6
|
-
require 'rutema/db'
|
7
6
|
|
8
7
|
module Rutema
|
8
|
+
#Exception occuring when connecting to a database
|
9
|
+
class ConnectionError<RuntimeError
|
10
|
+
end
|
11
|
+
|
12
|
+
module ActiveRecordConnections
|
13
|
+
#Establishes an ActiveRecord connection
|
14
|
+
def connect_to_active_record cfg,logger
|
15
|
+
conn=connect(cfg,logger)
|
16
|
+
Rutema::Model::Schema.migrate(:up) if perform_migration?(cfg)
|
17
|
+
end
|
18
|
+
private
|
19
|
+
#Establishes an active record connection using the cfg hash
|
20
|
+
#There is only a rudimentary check to ensure the integrity of cfg
|
21
|
+
def connect cfg,logger
|
22
|
+
if cfg[:adapter] && cfg[:database]
|
23
|
+
logger.debug("Connecting to #{cfg[:database]}")
|
24
|
+
return ActiveRecord::Base.establish_connection(cfg)
|
25
|
+
else
|
26
|
+
raise ConnectionError,"Erroneous database configuration. Missing :adapter and/or :database"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def perform_migration? cfg
|
31
|
+
return true if cfg[:migrate]
|
32
|
+
#special case for sqlite3
|
33
|
+
if cfg[:adapter]=="sqlite3" && !File.exists?(cfg[:database])
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
9
40
|
#The ActiveRecordReporter will store the results of a test run in a database using ActiveRecord.
|
10
41
|
#
|
11
42
|
#The DBMSs supported are dependent on the platform: either SQLite3 (MRI) or h2 (jruby)
|
12
43
|
class ActiveRecordReporter
|
44
|
+
include ActiveRecordConnections
|
13
45
|
#The required keys in this reporter's configuration are:
|
14
46
|
# :db - the database configuration. A Hash with the DB adapter information
|
15
47
|
# :db=>{:database=>"sample.rb"}
|
@@ -18,12 +50,7 @@ module Rutema
|
|
18
50
|
@logger||=Patir.setup_logger
|
19
51
|
database_configuration = definition[:db]
|
20
52
|
raise "No database configuration defined, missing :db configuration key." unless database_configuration
|
21
|
-
|
22
|
-
@dbfile=File.expand_path(database_configuration[:database])
|
23
|
-
else
|
24
|
-
@dbfile=database_configuration[:database]
|
25
|
-
end
|
26
|
-
Rutema.connect_to_ar(@dbfile,@logger)
|
53
|
+
connect_to_active_record(database_configuration,@logger)
|
27
54
|
@logger.info("Reporter #{self.to_s} registered")
|
28
55
|
end
|
29
56
|
|
@@ -90,5 +117,7 @@ module Rutema
|
|
90
117
|
return text.gsub("\000","") if text
|
91
118
|
return ""
|
92
119
|
end
|
93
|
-
|
120
|
+
|
121
|
+
end
|
122
|
+
|
94
123
|
end
|
data/lib/rutema/specification.rb
CHANGED
data/lib/rutema/system.rb
CHANGED
@@ -13,7 +13,7 @@ module Rutema
|
|
13
13
|
module Version
|
14
14
|
MAJOR=1
|
15
15
|
MINOR=0
|
16
|
-
TINY=
|
16
|
+
TINY=8
|
17
17
|
STRING=[ MAJOR, MINOR, TINY ].join( "." )
|
18
18
|
end
|
19
19
|
#The Elements module provides the namespace for the various modules adding parser functionality
|
@@ -348,7 +348,12 @@ module Rutema
|
|
348
348
|
#get the runner stati and the configuration and give it to the reporters
|
349
349
|
@reporters.each do |reporter|
|
350
350
|
threads<<Thread.new(reporter,@specifications,@test_states.values,@parse_errors,@configuration) do |reporter,specs,status,perrors,configuration|
|
351
|
-
|
351
|
+
begin
|
352
|
+
@logger.debug(reporter.report(specs,status,perrors,configuration))
|
353
|
+
rescue RuntimeError
|
354
|
+
@logger.error("Error in #{reporter.class}: #{$!.message}")
|
355
|
+
@logger.debug($!)
|
356
|
+
end
|
352
357
|
end
|
353
358
|
end
|
354
359
|
threads.each do |t|
|
@@ -433,7 +438,7 @@ module Rutema
|
|
433
438
|
@logger.info("Parsing check test '#{@configuration.check}'")
|
434
439
|
spec=parse_specification(@configuration.check)
|
435
440
|
if spec
|
436
|
-
@logger.info("Running check test '#{spec}'")
|
441
|
+
@logger.info("Running check test '#{spec.to_s}'")
|
437
442
|
if run_test(spec,false).success?
|
438
443
|
specs.each{|s| run_test(s)}
|
439
444
|
else
|
@@ -3,7 +3,7 @@ configuration.parser={:class=>Rutema::MinimalXMLParser}
|
|
3
3
|
#Use the AR-Reporter.
|
4
4
|
#In case of reporters the whole Hash is passed to the reporter initializer, so any keys are dependent on the reporter to use
|
5
5
|
#Check the appropriate RDoc entries
|
6
|
-
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:database=>"sample.db"}}
|
6
|
+
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:adpater=>"sqlite3",:database=>"sample.db"}}
|
7
7
|
configuration.tests=[
|
8
8
|
"../specs/T001.spec",
|
9
9
|
"../specs/T002.spec",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
configuration.parser={:class=>Rutema::MinimalXMLParser}
|
2
|
-
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:database=>"sample.db"}}
|
2
|
+
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:adapter=>"sqlite3",:database=>"sample.db"}}
|
3
3
|
configuration.tests=[
|
4
4
|
"../specs/T001.spec",
|
5
5
|
"../specs/T002.spec",
|
data/test/rutema.rutema
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
configuration.parser={:class=>Rutema::MinimalXMLParser}
|
2
|
-
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:database=>"rutema.db"}}
|
2
|
+
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:adapter=>"sqlite3",:database=>"rutema.db"}}
|
3
3
|
configuration.tests=["rutema.spec","migration.spec"]
|
data/test/test_reporter.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rutema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vassilis Rizopoulos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-13 00:00:00 +01:00
|
13
13
|
default_executable: rutemax
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -129,7 +129,6 @@ files:
|
|
129
129
|
- bin/rutema_upgrader
|
130
130
|
- distro_test.sh
|
131
131
|
- lib/rutema/configuration.rb
|
132
|
-
- lib/rutema/db.rb
|
133
132
|
- lib/rutema/gems.rb
|
134
133
|
- lib/rutema/model.rb
|
135
134
|
- lib/rutema/reporter.rb
|
@@ -143,7 +142,6 @@ files:
|
|
143
142
|
- test/data/sample09.db
|
144
143
|
- test/distro_test/config/database.rutema
|
145
144
|
- test/distro_test/config/full.rutema
|
146
|
-
- test/distro_test/config/jruby.rutema
|
147
145
|
- test/distro_test/config/minimal.rutema
|
148
146
|
- test/distro_test/specs/T001.spec
|
149
147
|
- test/distro_test/specs/T002.spec
|
data/lib/rutema/db.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Vassilis Rizopoulos, Markus Barchfeld. All rights reserved.
|
2
|
-
$:.unshift File.join(File.dirname(__FILE__),"..")
|
3
|
-
|
4
|
-
module Rutema
|
5
|
-
|
6
|
-
class SQLiteConnection
|
7
|
-
def initialize logger, database
|
8
|
-
@logger=logger
|
9
|
-
@database=database
|
10
|
-
end
|
11
|
-
|
12
|
-
def adapter
|
13
|
-
"sqlite3"
|
14
|
-
end
|
15
|
-
|
16
|
-
def connected?
|
17
|
-
result = ActiveRecord::Base.connected?
|
18
|
-
@logger.debug "Connected " + result.to_s
|
19
|
-
return result
|
20
|
-
end
|
21
|
-
|
22
|
-
def connect
|
23
|
-
ActiveRecord::Base.establish_connection(:adapter=>adapter, :database=>@database )
|
24
|
-
@logger.warn("'#{@database}' does not exist") if !(File.exists?(@database)) && @database!=":memory:"
|
25
|
-
connected?
|
26
|
-
end
|
27
|
-
|
28
|
-
def migrate
|
29
|
-
return if File.exists?(@database)
|
30
|
-
@logger.info "Migrating DB"
|
31
|
-
Model::Schema.migrate(:up)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class H2Connection
|
36
|
-
def initialize logger, database
|
37
|
-
@logger=logger
|
38
|
-
@database=database
|
39
|
-
end
|
40
|
-
|
41
|
-
def adapter
|
42
|
-
"jdbch2"
|
43
|
-
end
|
44
|
-
def port
|
45
|
-
7098
|
46
|
-
end
|
47
|
-
def base_dir
|
48
|
-
"/"
|
49
|
-
end
|
50
|
-
def connected?
|
51
|
-
begin
|
52
|
-
ActiveRecord::Base.retrieve_connection
|
53
|
-
rescue RuntimeError
|
54
|
-
end
|
55
|
-
result = ActiveRecord::Base.connected?
|
56
|
-
@logger.debug "Connected " + result.to_s
|
57
|
-
result
|
58
|
-
end
|
59
|
-
|
60
|
-
def connect
|
61
|
-
connect_server
|
62
|
-
if not connected?
|
63
|
-
start_server
|
64
|
-
connect_server
|
65
|
-
end
|
66
|
-
connected?
|
67
|
-
end
|
68
|
-
|
69
|
-
def connect_server
|
70
|
-
url = server_url
|
71
|
-
@logger.info "Connecting to " + server_url
|
72
|
-
ActiveRecord::Base.establish_connection(:adapter=>adapter,
|
73
|
-
:driver => 'org.h2.Driver',
|
74
|
-
:url=> server_url)
|
75
|
-
end
|
76
|
-
|
77
|
-
def server_url
|
78
|
-
# database is supposed to be an absolute path
|
79
|
-
"jdbc:h2:tcp://localhost:" + port.to_s + @database
|
80
|
-
end
|
81
|
-
|
82
|
-
# Start a h2 server to allow mixed mode accessing.
|
83
|
-
def start_server
|
84
|
-
args = ["-tcpPort", port.to_s, "-baseDir", base_dir]
|
85
|
-
@logger.info "Starting H2 server using arguments " + args.join(" ")
|
86
|
-
require 'jdbc/h2'
|
87
|
-
Rutema.includeJava
|
88
|
-
org.h2.tools.Server.createTcpServer(args.to_java(:string)).start()
|
89
|
-
end
|
90
|
-
|
91
|
-
def migrate
|
92
|
-
return if File.exists?("#{@database}.data.db")
|
93
|
-
@logger.info "Migrating DB"
|
94
|
-
Model::Schema.migrate(:up)
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
#Exception occuring when connecting to a database
|
102
|
-
class ConnectionError<RuntimeError
|
103
|
-
end
|
104
|
-
#Establishes an ActiveRecord connection
|
105
|
-
def self.connect_to_ar database,logger,perform_migration=true
|
106
|
-
raise ConnectionError,"No database source defined in the configuration" unless database
|
107
|
-
logger.debug("Connecting to #{database}")
|
108
|
-
conn = connection(logger, database)
|
109
|
-
conn.connect
|
110
|
-
conn.migrate if perform_migration
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
@@connection=nil
|
116
|
-
|
117
|
-
def self.connection logger, database
|
118
|
-
if not @@connection
|
119
|
-
@@connection = RUBY_PLATFORM =~ /java/ ? H2Connection.new(logger, database) : SQLiteConnection.new(logger, database)
|
120
|
-
end
|
121
|
-
@@connection
|
122
|
-
end
|
123
|
-
|
124
|
-
def self.includeJava
|
125
|
-
# "undefined method 'include'" in instance method
|
126
|
-
include Java if RUBY_PLATFORM =~ /java/
|
127
|
-
end
|
128
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
configuration.parser={:class=>Rutema::MinimalXMLParser}
|
2
|
-
configuration.reporter={:class=>Rutema::ActiveRecordReporter, :db=>{:database=>"h2"}}
|
3
|
-
configuration.tests=[
|
4
|
-
"../specs/T001.spec",
|
5
|
-
"../specs/T002.spec",
|
6
|
-
"../specs/T003.spec",
|
7
|
-
"../specs/T004.spec",
|
8
|
-
"../specs/T005.spec",
|
9
|
-
"../specs/T006.spec"
|
10
|
-
]
|