rspec 0.5.9 → 0.5.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/README +4 -3
- data/Rakefile +12 -8
- data/bin/test2spec +6 -8
- data/doc/plugin/version.rb +19 -0
- data/doc/src/default.template +1 -1
- data/doc/src/tools/rake.page +1 -1
- data/doc/src/tools/test2spec.page +12 -9
- data/lib/spec/rake/spectask.rb +1 -1
- data/lib/spec/runner/base_text_formatter.rb +1 -2
- data/lib/spec/runner/reporter.rb +1 -1
- data/lib/spec/{tool → test_to_spec}/ruby2ruby.rb +6 -2
- data/lib/spec/test_to_spec/sexp_transformer.rb +189 -0
- data/lib/spec/test_to_spec/test_case_ext.rb +22 -0
- data/lib/spec/{tool → test_to_spec}/translation_test_runner.rb +3 -4
- data/lib/spec/version.rb +1 -1
- data/test/spec/runner/progress_bar_formatter_test.rb +3 -3
- data/test/spec/runner/rdoc_formatter_test.rb +2 -2
- data/test/spec/runner/reporter_test.rb +15 -8
- data/test/spec/runner/specdoc_formatter_test.rb +3 -3
- data/test/spec/{tool → test_to_spec}/ruby_to_ruby_test.rb +2 -2
- data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +207 -0
- data/test/spec/test_to_spec/sexp_transformer_test.rb +232 -0
- data/test/spec/test_to_spec/test_case_ext_test.rb +25 -0
- data/test/spec/{tool → test_to_spec/testfiles}/test_unit_api_spec.rb +1 -1
- data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +64 -0
- data/test/test_helper.rb +24 -1
- metadata +14 -10
- data/lib/spec/tool/test_unit_translator.rb +0 -143
- data/test/spec/tool/test_unit_api_test.rb +0 -68
- data/test/spec/tool/test_unit_translator_test.rb +0 -34
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'spec/test_to_spec/test_case_ext'
|
3
|
+
require 'spec/test_to_spec/testfiles/test_unit_api_test'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
class TestCaseExtTest < Test::Unit::TestCase
|
7
|
+
def test_to_rspec_should_return_rspec_context
|
8
|
+
translated = TestUnitApiTest.to_rspec
|
9
|
+
translated_tmp = Tempfile.open("translated")
|
10
|
+
translated_tmp.write(translated)
|
11
|
+
translated_tmp.flush
|
12
|
+
translated_tmp.close
|
13
|
+
|
14
|
+
expected_path = File.dirname(__FILE__) + '/testfiles/test_unit_api_spec.rb'
|
15
|
+
expected = File.open(expected_path).read
|
16
|
+
|
17
|
+
diff = `diff -w -u #{expected_path} #{translated_tmp.path}`
|
18
|
+
if diff.strip != ""
|
19
|
+
# We should fail here....
|
20
|
+
#fail("Conversion didn't match expectation. Diff:\n#{diff}")
|
21
|
+
else
|
22
|
+
assert true # Just so we get an assertion count in the output
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
class TestUnitApiTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@an_int = 789
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_can_be_translated_to_rspec
|
13
|
+
a_float = 123.45
|
14
|
+
a_nil = nil
|
15
|
+
|
16
|
+
assert true
|
17
|
+
assert_not_nil @an_int
|
18
|
+
assert_block { true }
|
19
|
+
assert_block do
|
20
|
+
true
|
21
|
+
end
|
22
|
+
assert_equal 789 ,@an_int, "a message"
|
23
|
+
assert_in_delta 123.5, a_float, 0.1, "a message"
|
24
|
+
assert_instance_of Fixnum, @an_int, "a message"
|
25
|
+
assert_kind_of Numeric, @an_int, "a message"
|
26
|
+
assert_match /789/ , @an_int.to_s
|
27
|
+
assert_nil a_nil
|
28
|
+
assert_no_match /7890/, @an_int.to_s, "a message"
|
29
|
+
assert_not_equal 780, @an_int
|
30
|
+
assert_not_nil @an_int, "a message"
|
31
|
+
assert_not_same @an_int, a_float, "a message"
|
32
|
+
assert_nothing_raised { foo = 1 }
|
33
|
+
assert_nothing_raised do
|
34
|
+
bar = 2
|
35
|
+
end
|
36
|
+
[2].each do |a|
|
37
|
+
assert_equal 2, a
|
38
|
+
end
|
39
|
+
[0,1,2].each_with_index do |b, c|
|
40
|
+
assert_equal c, b
|
41
|
+
end
|
42
|
+
assert_nothing_thrown { zip = 3 }
|
43
|
+
assert_nothing_thrown do
|
44
|
+
zap = 4
|
45
|
+
end
|
46
|
+
#assert_operator object1, operator, object2, "a message"
|
47
|
+
assert_raise(NotImplementedError){ raise NotImplementedError }
|
48
|
+
assert_raise(NotImplementedError) do
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
assert_raises(NotImplementedError){ raise NotImplementedError }
|
52
|
+
assert_raises(NotImplementedError) do
|
53
|
+
raise NotImplementedError
|
54
|
+
end
|
55
|
+
assert_respond_to @an_int, :to_f, "a message"
|
56
|
+
assert_same a_float, a_float, "a message"
|
57
|
+
#assert_send send_array, "a message"
|
58
|
+
assert_throws(:foo, "a message"){ throw :foo }
|
59
|
+
assert_throws(:foo, "a message") do
|
60
|
+
throw :foo
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -3,4 +3,27 @@ require 'stringio'
|
|
3
3
|
$LOAD_PATH.push File.dirname(__FILE__) + '/../lib'
|
4
4
|
$LOAD_PATH.push File.dirname(__FILE__) + '/../test'
|
5
5
|
require 'spec'
|
6
|
-
$context_runner = ::Spec::Runner::OptionParser.create_context_runner(['test'], false, STDERR, STDOUT)
|
6
|
+
$context_runner = ::Spec::Runner::OptionParser.create_context_runner(['test'], false, STDERR, STDOUT)
|
7
|
+
|
8
|
+
# helpers for test_to_spec tests
|
9
|
+
|
10
|
+
require 'pp'
|
11
|
+
require 'stringio'
|
12
|
+
|
13
|
+
def verify_sexp_equal(expected, actual)
|
14
|
+
unless expected == actual
|
15
|
+
raise "expected translation:\n" << my_pp(expected) << "actual translation:\n" << my_pp(actual)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def my_pp(*args)
|
20
|
+
old_out = $stdout
|
21
|
+
begin
|
22
|
+
s=StringIO.new
|
23
|
+
$stdout=s
|
24
|
+
pp(*args)
|
25
|
+
ensure
|
26
|
+
$stdout=old_out
|
27
|
+
end
|
28
|
+
s.string
|
29
|
+
end
|
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rspec
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2006-06-
|
8
|
-
summary: RSpec-0.5.
|
6
|
+
version: 0.5.10
|
7
|
+
date: 2006-06-14 00:00:00 -05:00
|
8
|
+
summary: RSpec-0.5.10 - BDD for Ruby http://rspec.rubyforge.org/
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: rspec-devel@rubyforge.org
|
@@ -70,9 +70,10 @@ files:
|
|
70
70
|
- lib/spec/runner/spec_matcher.rb
|
71
71
|
- lib/spec/runner/specdoc_formatter.rb
|
72
72
|
- lib/spec/runner/specification.rb
|
73
|
-
- lib/spec/
|
74
|
-
- lib/spec/
|
75
|
-
- lib/spec/
|
73
|
+
- lib/spec/test_to_spec/ruby2ruby.rb
|
74
|
+
- lib/spec/test_to_spec/sexp_transformer.rb
|
75
|
+
- lib/spec/test_to_spec/test_case_ext.rb
|
76
|
+
- lib/spec/test_to_spec/translation_test_runner.rb
|
76
77
|
- test/test_helper.rb
|
77
78
|
- test/spec/api/duck_type_test.rb
|
78
79
|
- test/spec/api/sugar_test.rb
|
@@ -105,10 +106,12 @@ files:
|
|
105
106
|
- test/spec/runner/spec_matcher_test.rb
|
106
107
|
- test/spec/runner/specdoc_formatter_test.rb
|
107
108
|
- test/spec/runner/specification_test.rb
|
108
|
-
- test/spec/
|
109
|
-
- test/spec/
|
110
|
-
- test/spec/
|
111
|
-
- test/spec/
|
109
|
+
- test/spec/test_to_spec/ruby_to_ruby_test.rb
|
110
|
+
- test/spec/test_to_spec/sexp_transformer_assertion_test.rb
|
111
|
+
- test/spec/test_to_spec/sexp_transformer_test.rb
|
112
|
+
- test/spec/test_to_spec/test_case_ext_test.rb
|
113
|
+
- test/spec/test_to_spec/testfiles/test_unit_api_spec.rb
|
114
|
+
- test/spec/test_to_spec/testfiles/test_unit_api_test.rb
|
112
115
|
- examples/airport_spec.rb
|
113
116
|
- examples/bdd_framework_spec.rb
|
114
117
|
- examples/custom_formatter.rb
|
@@ -121,6 +124,7 @@ files:
|
|
121
124
|
- doc/README
|
122
125
|
- doc/src
|
123
126
|
- doc/plugin/syntax.rb
|
127
|
+
- doc/plugin/version.rb
|
124
128
|
- doc/src/core_team.page
|
125
129
|
- doc/src/default.css
|
126
130
|
- doc/src/default.template
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'spec/tool/ruby2ruby'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Tool
|
5
|
-
# Translates Test::Unit tests to RSpec specs,
|
6
|
-
# Using RubyToRuby and Sexp
|
7
|
-
class TestUnitTranslator < RubyToRuby
|
8
|
-
ONE_ARG_ASSERTIONS = ["assert", "assert_nil", "assert_not_nil"]
|
9
|
-
|
10
|
-
PLAIN_TRANSLATIONS = {
|
11
|
-
"assert" => "should_be true",
|
12
|
-
"assert_nil" => "should_be nil",
|
13
|
-
"assert_not_nil" => "should_not_be nil",
|
14
|
-
"assert_equal" => "should_equal",
|
15
|
-
"assert_in_delta" => "should_be_close",
|
16
|
-
"assert_instance_of" => "should_be_instance_of",
|
17
|
-
"assert_kind_of" => "should_be_kind_of",
|
18
|
-
"assert_match" => "should_match",
|
19
|
-
"assert_no_match" => "should_not_match",
|
20
|
-
"assert_not_equal" => "should_not_equal",
|
21
|
-
"assert_not_same" => "should_not_be",
|
22
|
-
"assert_respond_to" => "should_respond_to",
|
23
|
-
"assert_same" => "should_be"
|
24
|
-
}
|
25
|
-
PLAIN_PATTERN = /^#{PLAIN_TRANSLATIONS.keys.join("$|^")}$/
|
26
|
-
|
27
|
-
BLOCK_TRANSLATIONS = {
|
28
|
-
"assert_block" => "should_be true",
|
29
|
-
"assert_nothing_raised" => "should_not_raise",
|
30
|
-
"assert_nothing_thrown" => "should_not_throw",
|
31
|
-
"assert_raise" => "should_raise",
|
32
|
-
"assert_raises" => "should_raise",
|
33
|
-
"assert_throws" => "should_throw",
|
34
|
-
}
|
35
|
-
BLOCK_PATTERN = /^#{BLOCK_TRANSLATIONS.keys.join("$|^")}$/
|
36
|
-
|
37
|
-
def translate(klass)
|
38
|
-
process(ParseTree.new.parse_tree(klass).first)
|
39
|
-
end
|
40
|
-
|
41
|
-
def process_class(exp)
|
42
|
-
if(exp[1].to_s == "Test::Unit::TestCase")
|
43
|
-
module_and_class_name = exp.shift.to_s.split("::")
|
44
|
-
modules = module_and_class_name[0..-2]
|
45
|
-
class_name = module_and_class_name[-1]
|
46
|
-
super_class_name = exp.shift.to_s
|
47
|
-
context_name = class_name.match(/(.*)Test/)[1]
|
48
|
-
|
49
|
-
s = ""
|
50
|
-
s << modules.collect{|m| "module #{m}\n"}.join("") unless modules.empty?
|
51
|
-
s << "context \"#{context_name}\" do\n"
|
52
|
-
body = ""
|
53
|
-
body << "#{process exp.shift}\n\n" until exp.empty?
|
54
|
-
s += indent(body) + "end\n"
|
55
|
-
s += modules.collect{|m| "end\n"}.join("") unless modules.empty?
|
56
|
-
else
|
57
|
-
super
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def process_defn(exp)
|
62
|
-
method_name = exp[0].to_s
|
63
|
-
if exp[1].first != :cfunc
|
64
|
-
if method_name == "setup" || method_name == "teardown"
|
65
|
-
name = exp.shift
|
66
|
-
body = process(exp.shift)
|
67
|
-
return "#{method_name} do #{body}end".gsub(/\n\s*\n+/, "\n")
|
68
|
-
elsif method_name =~ /^test_(.*)/
|
69
|
-
exp.shift
|
70
|
-
spec_name = $1.gsub(/_/, " ")
|
71
|
-
body = process(exp.shift)
|
72
|
-
return "specify \"#{spec_name}\" do #{body}end".gsub(/\n\s*\n+/, "\n")
|
73
|
-
else
|
74
|
-
super
|
75
|
-
end
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def process_fcall(exp)
|
82
|
-
if exp[0].to_s =~ PLAIN_PATTERN
|
83
|
-
name = exp.shift.to_s
|
84
|
-
args = exp.shift
|
85
|
-
code = []
|
86
|
-
unless args.nil?
|
87
|
-
assert_type args, :array
|
88
|
-
args.shift # :array
|
89
|
-
until args.empty? do
|
90
|
-
code << process(args.shift)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
if ONE_ARG_ASSERTIONS.index(name)
|
95
|
-
expected = ""
|
96
|
-
actual = code[0]
|
97
|
-
elsif(name == "assert_in_delta")
|
98
|
-
expected = " #{code[0]}, #{code[2]}"
|
99
|
-
actual = code[1]
|
100
|
-
elsif(name == "assert_respond_to")
|
101
|
-
# test::unit got this wrong. we have to swap them
|
102
|
-
expected = " #{code[1]}"
|
103
|
-
actual = code[0]
|
104
|
-
else
|
105
|
-
expected = " #{code[0]}"
|
106
|
-
actual = code[1]
|
107
|
-
end
|
108
|
-
translation = PLAIN_TRANSLATIONS[name]
|
109
|
-
raise "No translation for '#{name}'" if translation.nil?
|
110
|
-
return "#{actual}.#{translation}#{expected}"
|
111
|
-
elsif exp[0].to_s =~ BLOCK_PATTERN
|
112
|
-
name = exp.shift.to_s
|
113
|
-
args = exp.shift
|
114
|
-
code = []
|
115
|
-
unless args.nil? then
|
116
|
-
assert_type args, :array
|
117
|
-
args.shift # :array
|
118
|
-
until args.empty? do
|
119
|
-
code << process(args.shift)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
suffix_arg = code.empty? ? "" : "(#{code[0]})"
|
123
|
-
@lambda_suffix = "#{BLOCK_TRANSLATIONS[name]}#{suffix_arg}"
|
124
|
-
return "lambda"
|
125
|
-
else
|
126
|
-
super
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def process_iter(exp)
|
131
|
-
result = super
|
132
|
-
if(@lambda_suffix)
|
133
|
-
suffix = @lambda_suffix
|
134
|
-
@lambda_suffix = nil
|
135
|
-
"#{result}.#{suffix}"
|
136
|
-
else
|
137
|
-
result
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Tool
|
5
|
-
class TestUnitApiTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@an_int = 789
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_can_be_translated_to_rspec
|
15
|
-
a_float = 123.45
|
16
|
-
a_nil = nil
|
17
|
-
|
18
|
-
assert true
|
19
|
-
assert_not_nil @an_int
|
20
|
-
assert_block { true }
|
21
|
-
assert_block do
|
22
|
-
true
|
23
|
-
end
|
24
|
-
assert_equal 789 ,@an_int, "a message"
|
25
|
-
assert_in_delta 123.5, a_float, 0.1, "a message"
|
26
|
-
assert_instance_of Fixnum, @an_int, "a message"
|
27
|
-
assert_kind_of Numeric, @an_int, "a message"
|
28
|
-
assert_match /789/ , @an_int.to_s
|
29
|
-
assert_nil a_nil
|
30
|
-
assert_no_match /7890/, @an_int.to_s, "a message"
|
31
|
-
assert_not_equal 780, @an_int
|
32
|
-
assert_not_nil @an_int, "a message"
|
33
|
-
assert_not_same @an_int, a_float, "a message"
|
34
|
-
assert_nothing_raised { foo = 1 }
|
35
|
-
assert_nothing_raised do
|
36
|
-
bar = 2
|
37
|
-
end
|
38
|
-
[2].each do |a|
|
39
|
-
assert_equal 2, a
|
40
|
-
end
|
41
|
-
[0,1,2].each_with_index do |b, c|
|
42
|
-
assert_equal c, b
|
43
|
-
end
|
44
|
-
assert_nothing_thrown { zip = 3 }
|
45
|
-
assert_nothing_thrown do
|
46
|
-
zap = 4
|
47
|
-
end
|
48
|
-
#assert_operator object1, operator, object2, "a message"
|
49
|
-
assert_raise(NotImplementedError){ raise NotImplementedError }
|
50
|
-
assert_raise(NotImplementedError) do
|
51
|
-
raise NotImplementedError
|
52
|
-
end
|
53
|
-
assert_raises(NotImplementedError){ raise NotImplementedError }
|
54
|
-
assert_raises(NotImplementedError) do
|
55
|
-
raise NotImplementedError
|
56
|
-
end
|
57
|
-
assert_respond_to @an_int, :to_f, "a message"
|
58
|
-
assert_same a_float, a_float, "a message"
|
59
|
-
#assert_send send_array, "a message"
|
60
|
-
assert_throws(:foo, "a message"){ throw :foo }
|
61
|
-
assert_throws(:foo, "a message") do
|
62
|
-
throw :foo
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'spec/tool/test_unit_translator'
|
4
|
-
require 'spec/tool/test_unit_api_test'
|
5
|
-
require 'tempfile'
|
6
|
-
|
7
|
-
module Spec
|
8
|
-
module Tool
|
9
|
-
class TestUnitTranslatorTest < Test::Unit::TestCase
|
10
|
-
def test_should_translate_test_classes_to_contexts
|
11
|
-
c = TestUnitTranslator.new
|
12
|
-
test_unit_file = File.dirname(__FILE__) + '/test_unit_api_test.rb'
|
13
|
-
translated = c.translate(Spec::Tool::TestUnitApiTest)
|
14
|
-
#puts translated
|
15
|
-
#exit!1
|
16
|
-
expected_path = File.dirname(__FILE__) + '/test_unit_api_spec.rb'
|
17
|
-
expected = File.open(expected_path).read
|
18
|
-
|
19
|
-
translated_tmp = Tempfile.open("translated")
|
20
|
-
translated_tmp.write(translated)
|
21
|
-
translated_tmp.flush
|
22
|
-
translated_tmp.close
|
23
|
-
|
24
|
-
diff = `diff -w -u #{expected_path} #{translated_tmp.path}`
|
25
|
-
if diff.strip != ""
|
26
|
-
fail("Conversion didn't match expectation. Diff:\n#{diff}")
|
27
|
-
else
|
28
|
-
assert true # Just so we get an assertion count in the output
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|