cwninja-drunit 0.2 → 0.3
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.
- data/Rakefile +1 -1
- data/lib/drunit.rb +33 -24
- data/lib/drunit/remote_app.rb +3 -22
- data/lib/drunit/remote_error.rb +31 -0
- data/lib/drunit/remote_test.rb +26 -32
- data/test/unit/main_test.rb +6 -1
- metadata +4 -3
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ end
|
|
17
17
|
|
18
18
|
spec = Gem::Specification.new do |s|
|
19
19
|
s.name = %q{drunit}
|
20
|
-
s.version = "0.
|
20
|
+
s.version = "0.3"
|
21
21
|
s.summary = %q{A library for running tests across multiple applications from a single test case.}
|
22
22
|
s.description = %q{A library for running tests across multiple applications from a single test case.}
|
23
23
|
|
data/lib/drunit.rb
CHANGED
@@ -1,24 +1,6 @@
|
|
1
|
-
|
2
|
-
class RemoteError < RuntimeError
|
3
|
-
def self.name
|
4
|
-
@@name
|
5
|
-
end
|
6
|
-
|
7
|
-
def class
|
8
|
-
if type = look_up_exception
|
9
|
-
return type
|
10
|
-
else
|
11
|
-
@@name = @real_exception.to_s
|
12
|
-
super
|
13
|
-
end
|
14
|
-
end
|
1
|
+
require "rubygems"
|
15
2
|
|
16
|
-
|
17
|
-
@real_exception.split("::").inject(Object){|node, part|
|
18
|
-
node && node.const_defined?(part) && node.const_get(part)
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
3
|
+
module Drunit
|
22
4
|
|
23
5
|
module ClassMethods
|
24
6
|
def RemoteApp(name, *args)
|
@@ -27,21 +9,48 @@ module Drunit
|
|
27
9
|
end
|
28
10
|
|
29
11
|
def in_app(name, *args, &block)
|
30
|
-
file, line, method =
|
31
|
-
|
32
|
-
|
12
|
+
file, line, method = caller_file_and_method_for_block(&block)
|
13
|
+
test_case = remote_test_case_for(name)
|
14
|
+
test_case.define(block_to_source(method, &block), file, line)
|
15
|
+
test_case.run(method, *args)
|
16
|
+
rescue Exception => e
|
17
|
+
rewrite_backtrace(e, method, name) or raise
|
33
18
|
ensure
|
34
|
-
|
19
|
+
test_case.assertion_count.times{ add_assertion } rescue nil
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def rewrite_backtrace(e, method_name, app_name)
|
24
|
+
if first_remote_line = e.backtrace.grep(Regexp.new(method_name)).last
|
25
|
+
index = e.backtrace.index(first_remote_line)
|
26
|
+
raise e, e.message, e.backtrace[0..index] + ["in drunit_remote(#{app_name})"] + caller(0)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def block_to_source(method_name, &block)
|
31
|
+
m = Module.new
|
32
|
+
m.send(:define_method, method_name, &block)
|
33
|
+
Ruby2Ruby.translate(m, method_name)
|
35
34
|
end
|
36
35
|
|
37
36
|
def remote_app_for(name)
|
38
37
|
self.class.const_get("RemoteAppFor_#{name}")
|
39
38
|
end
|
40
39
|
|
40
|
+
def remote_test_case_for(name)
|
41
|
+
@remote_test_cases ||= {}
|
42
|
+
@remote_test_cases[name.to_sym] ||= remote_app_for(name).new_test_case
|
43
|
+
end
|
44
|
+
|
45
|
+
def caller_file_and_method_for_block(&block)
|
46
|
+
eval(%%caller(0)[0] =~ /in `(.*)'/; [__FILE__, __LINE__, $1 || 'unknown_method']%, block.binding)
|
47
|
+
end
|
48
|
+
|
41
49
|
def self.included(other)
|
42
50
|
other.send(:extend, ClassMethods)
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
46
54
|
require File.join(File.dirname(__FILE__), *%w[drunit remote_app])
|
55
|
+
require File.join(File.dirname(__FILE__), *%w[drunit remote_error])
|
47
56
|
|
data/lib/drunit/remote_app.rb
CHANGED
@@ -11,28 +11,15 @@ module Drunit
|
|
11
11
|
@remote_object = nil
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def last_assertion_count
|
19
|
-
app.last_assertion_count
|
14
|
+
def new_test_case
|
15
|
+
app.new_test_case
|
20
16
|
end
|
21
17
|
|
22
18
|
private
|
23
|
-
def raise_or_return(e, method_name)
|
24
|
-
return e unless e.is_a? Exception
|
25
|
-
if first_remote_line = e.backtrace.grep(Regexp.new(method_name)).last
|
26
|
-
index = e.backtrace.index(first_remote_line)
|
27
|
-
raise e, e.message, e.backtrace[0..index] + ["RemoteApp<#{@name}>"] + caller(0)
|
28
|
-
end
|
29
|
-
raise e
|
30
|
-
end
|
31
|
-
|
32
19
|
def get_url(pipe)
|
33
20
|
pipe.each_line do |line|
|
34
21
|
return $1 if line =~ /^DRUNIT:URI (.*)$/
|
35
|
-
STDERR.puts "From drunit_remote>> #{line}"
|
22
|
+
STDERR.puts "From drunit_remote(#{@name})>> #{line}"
|
36
23
|
end
|
37
24
|
end
|
38
25
|
|
@@ -49,11 +36,5 @@ module Drunit
|
|
49
36
|
def app
|
50
37
|
@remote_object ||= start_app!
|
51
38
|
end
|
52
|
-
|
53
|
-
def block_to_source(method_name, &block)
|
54
|
-
m = Module.new
|
55
|
-
m.send(:define_method, method_name, &block)
|
56
|
-
Ruby2Ruby.translate(m, method_name)
|
57
|
-
end
|
58
39
|
end
|
59
40
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Drunit
|
2
|
+
class RemoteError < RuntimeError
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def name
|
6
|
+
@name || super
|
7
|
+
end
|
8
|
+
attr_writer :name
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(exception_name)
|
12
|
+
@exception_name = exception_name.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def class
|
16
|
+
type = look_up_exception
|
17
|
+
return type if type
|
18
|
+
super.name = @exception_name #Now we hope and prey that the name of the class is checked imidiately
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def look_up_exception
|
23
|
+
@exception_name.split("::").inject(Object){|node, part|
|
24
|
+
node && node.const_defined?(part) && node.const_get(part)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
data/lib/drunit/remote_test.rb
CHANGED
@@ -1,54 +1,48 @@
|
|
1
1
|
require 'drb'
|
2
2
|
require 'test/unit'
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[remote_error])
|
3
4
|
|
4
5
|
module Drunit
|
5
|
-
class RemoteError < RuntimeError
|
6
|
-
def initialize(real_exception)
|
7
|
-
@real_exception = real_exception
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
6
|
class RemoteTest
|
12
|
-
|
7
|
+
def new_test_case
|
8
|
+
TestCase.new
|
9
|
+
end
|
13
10
|
|
14
11
|
class TestCase
|
12
|
+
include DRb::DRbUndumped
|
15
13
|
include Test::Unit::Assertions
|
16
14
|
attr_reader :assertion_count
|
17
15
|
|
18
|
-
def initialize
|
16
|
+
def initialize
|
19
17
|
@assertion_count = 0
|
20
|
-
@method_name = method_name
|
21
|
-
instance_eval(code, source_file, source_line)
|
22
18
|
end
|
23
19
|
|
24
20
|
def add_assertion
|
25
21
|
@assertion_count += 1
|
26
22
|
end
|
27
23
|
|
28
|
-
def
|
29
|
-
|
24
|
+
def define(code, source_file, source_line)
|
25
|
+
instance_eval(code, source_file, source_line)
|
30
26
|
end
|
31
|
-
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
raise Drunit::RemoteError.new(e.class.name), e.message, e.backtrace
|
28
|
+
def run(method_name, *args)
|
29
|
+
rewrite_exceptions{ __send__(method_name, *args) }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
# We need to strip down and generalise the exceptions to prevent the integration project from having to know anything about anything.
|
34
|
+
def rewrite_exceptions
|
35
|
+
begin
|
36
|
+
return yield
|
37
|
+
rescue Test::Unit::AssertionFailedError
|
38
|
+
raise
|
39
|
+
rescue ArgumentError => e
|
40
|
+
raise e unless e.message =~ /Anonymous modules /
|
41
|
+
raise NameError, "Const Missing", e.backtrace[3..-1]
|
42
|
+
rescue Exception => e
|
43
|
+
raise Drunit::RemoteError.new(e.class.name), e.message, e.backtrace
|
44
|
+
end
|
45
|
+
end
|
52
46
|
end
|
53
47
|
end
|
54
48
|
end
|
data/test/unit/main_test.rb
CHANGED
@@ -26,7 +26,7 @@ class MainTest < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
def test_should_inject_the_fact_we_are_in_a_remote_app_into_the_backtrace
|
28
28
|
e = assert_raise(RuntimeError) { InApp{ raise "Fail" } }
|
29
|
-
assert_equal 1, e.backtrace.grep("
|
29
|
+
assert_equal 1, e.backtrace.grep("in drunit_remote(fake_app)").size, e.backtrace.join("\n")
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_should_raise_the_assertion_count_when_we_assert
|
@@ -38,4 +38,9 @@ class MainTest < Test::Unit::TestCase
|
|
38
38
|
def test_should_be_able_to_pass_in_simple_params
|
39
39
|
assert_equal 12, InApp(2,6){|a,b| SomeFoo.new.multiply(a, b)}
|
40
40
|
end
|
41
|
+
|
42
|
+
def test_consistant_remote_instance
|
43
|
+
InApp{ @foo = 1 }
|
44
|
+
InApp{ assert_equal 1, @foo }
|
45
|
+
end
|
41
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cwninja-drunit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lea
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-28 00:00:00 -07:00
|
13
13
|
default_executable: drunit_remote
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,9 +22,10 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.markdown
|
24
24
|
files:
|
25
|
-
- Rakefile
|
26
25
|
- README.markdown
|
26
|
+
- Rakefile
|
27
27
|
- lib/drunit/remote_app.rb
|
28
|
+
- lib/drunit/remote_error.rb
|
28
29
|
- lib/drunit/remote_test.rb
|
29
30
|
- lib/drunit.rb
|
30
31
|
- test/fake_app/fake_app.rb
|