rspec 0.5.7 → 0.5.8
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/CHANGES +9 -0
- data/Rakefile +7 -10
- data/bin/spec +1 -1
- data/bin/test2spec +93 -0
- data/doc/src/default.template +1 -1
- data/doc/src/documentation/index.page +37 -37
- data/doc/src/documentation/mocks.page +88 -60
- data/doc/src/tools/index.page +2 -2
- data/doc/src/tools/meta.info +1 -1
- data/doc/src/tools/test2spec.page +73 -0
- data/doc/src/tutorials/notes.txt +1 -1
- data/doc/src/tutorials/stack_01.page +4 -4
- data/doc/src/tutorials/stack_02.page +6 -6
- data/doc/src/tutorials/stack_03.page +8 -8
- data/doc/src/tutorials/stack_04.page +2 -2
- data/doc/src/tutorials/stack_05.page +1 -1
- data/lib/spec/api/sugar.rb +3 -3
- data/lib/spec/runner/base_text_formatter.rb +11 -5
- data/lib/spec/runner/option_parser.rb +1 -1
- data/lib/spec/runner/progress_bar_formatter.rb +1 -1
- data/lib/spec/runner/rdoc_formatter.rb +1 -1
- data/lib/spec/runner/reporter.rb +6 -3
- data/lib/spec/runner/specdoc_formatter.rb +1 -1
- data/lib/spec/runner/specification.rb +1 -0
- data/lib/spec/tool/ruby2ruby.rb +485 -0
- data/lib/spec/tool/test_unit_translator.rb +114 -83
- data/lib/spec/tool/translation_test_runner.rb +118 -0
- data/lib/spec/version.rb +1 -1
- data/test/spec/runner/context_test.rb +4 -0
- data/test/spec/runner/progress_bar_formatter_test.rb +1 -1
- data/test/spec/runner/rdoc_formatter_test.rb +1 -1
- data/test/spec/runner/reporter_test.rb +24 -7
- data/test/spec/runner/specdoc_formatter_test.rb +1 -1
- data/test/spec/runner/specification_test.rb +8 -0
- data/test/spec/tool/ruby_to_ruby_test.rb +79 -0
- data/test/spec/tool/test_unit_api_spec.rb +45 -31
- data/test/spec/tool/test_unit_api_test.rb +13 -6
- data/test/spec/tool/test_unit_translator_test.rb +6 -1
- metadata +11 -10
- data/bin/test2rspec +0 -35
- data/doc/src/tools/test2rspec.page +0 -13
- data/lib/spec/tool/command_line.rb +0 -39
- data/test/spec/tool/command_line_test.rb +0 -21
@@ -12,12 +12,14 @@ module Spec
|
|
12
12
|
self.should.not.be.instance_of Specification
|
13
13
|
self.should.be.instance_of ExecutionContext
|
14
14
|
end
|
15
|
+
@reporter.should.receive(:spec_started).with "should pass"
|
15
16
|
@reporter.should.receive(:spec_finished).with "should pass", nil, nil
|
16
17
|
spec.run @reporter
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_should_add_itself_to_reporter_when_passes
|
20
21
|
spec = Specification.new("spec") {}
|
22
|
+
@reporter.should.receive(:spec_started).with "spec"
|
21
23
|
@reporter.should.receive(:spec_finished).with "spec", nil, nil
|
22
24
|
spec.run(@reporter)
|
23
25
|
end
|
@@ -25,12 +27,14 @@ module Spec
|
|
25
27
|
def test_should_add_itself_to_reporter_when_fails
|
26
28
|
error = RuntimeError.new
|
27
29
|
spec = Specification.new("spec") { raise error }
|
30
|
+
@reporter.should.receive(:spec_started).with "spec"
|
28
31
|
@reporter.should.receive(:spec_finished).with "spec", error, "spec"
|
29
32
|
spec.run(@reporter)
|
30
33
|
end
|
31
34
|
|
32
35
|
def test_should_add_itself_to_reporter_when_calling_run_dry
|
33
36
|
spec = Specification.new("spec") {}
|
37
|
+
@reporter.should.receive(:spec_started).with "spec"
|
34
38
|
@reporter.should.receive(:spec_finished).with "spec"
|
35
39
|
spec.run(@reporter, nil, nil, true)
|
36
40
|
end
|
@@ -40,6 +44,7 @@ module Spec
|
|
40
44
|
mock = mock("a mock")
|
41
45
|
mock.should.receive(:poke)
|
42
46
|
end
|
47
|
+
@reporter.should.receive(:spec_started).with "spec"
|
43
48
|
@reporter.should.receive(:spec_finished) do |spec_name, error|
|
44
49
|
spec_name.should.equal "spec"
|
45
50
|
error.message.should.match /expected 'poke' once, but received it 0 times/
|
@@ -54,6 +59,7 @@ module Spec
|
|
54
59
|
teardown = lambda do
|
55
60
|
raise "in teardown"
|
56
61
|
end
|
62
|
+
@reporter.should.receive(:spec_started).with "spec"
|
57
63
|
@reporter.should.receive(:spec_finished) do |spec, error, location|
|
58
64
|
spec.should.equal "spec"
|
59
65
|
location.should.equal "spec"
|
@@ -68,6 +74,7 @@ module Spec
|
|
68
74
|
setup = lambda do
|
69
75
|
raise "in setup"
|
70
76
|
end
|
77
|
+
@reporter.should.receive(:spec_started).with "spec"
|
71
78
|
@reporter.should.receive(:spec_finished) do |name, error, location|
|
72
79
|
name.should.equal "spec"
|
73
80
|
error.message.should.equal "in setup"
|
@@ -82,6 +89,7 @@ module Spec
|
|
82
89
|
teardown = lambda do
|
83
90
|
raise "in teardown"
|
84
91
|
end
|
92
|
+
@reporter.should.receive(:spec_started).with "spec"
|
85
93
|
@reporter.should.receive(:spec_finished) do |name, error, location|
|
86
94
|
name.should.equal "spec"
|
87
95
|
error.message.should.equal "in teardown"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'spec/tool/ruby2ruby'
|
3
|
+
|
4
|
+
R2r2r = RubyToRuby.translate(RubyToRuby).sub("RubyToRuby","RubyToRubyToRuby")
|
5
|
+
eval R2r2r
|
6
|
+
|
7
|
+
class RubyToRubyToRuby
|
8
|
+
class<<self
|
9
|
+
eval RubyToRuby.translate(class<<RubyToRuby;self;end, :translate)
|
10
|
+
end
|
11
|
+
eval RubyToRuby.translate(RubyToRuby, :initialize)
|
12
|
+
end
|
13
|
+
|
14
|
+
class R2RTest < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def test_self_translation
|
17
|
+
r2r2r2 = RubyToRubyToRuby.translate(RubyToRuby).sub("RubyToRuby","RubyToRubyToRuby")
|
18
|
+
r2r2r2r = RubyToRubyToRuby.translate(RubyToRubyToRuby)
|
19
|
+
# File.open('1','w'){|f| f.write r2r2r}
|
20
|
+
# File.open('2','w'){|f| f.write r2r2r2}
|
21
|
+
# File.open('3','w'){|f| f.write r2r2r2r}
|
22
|
+
assert_equal(R2r2r,r2r2r2)
|
23
|
+
assert_equal(R2r2r,r2r2r2r)
|
24
|
+
end
|
25
|
+
|
26
|
+
def hairy_method(z,x=10,y=20*z.abs,&blok)
|
27
|
+
n = 1 + 2 * 40.0 / (z - 2)
|
28
|
+
retried = false
|
29
|
+
begin
|
30
|
+
raise ArgumentError, n if retried
|
31
|
+
n -= yield x,y,z,[z,x,y].map(&blok)
|
32
|
+
n /= 1.1 until n < 500
|
33
|
+
n = "hop hop #{"%.4f" % n}"
|
34
|
+
raise n
|
35
|
+
rescue RuntimeError => e
|
36
|
+
raise if n != e.message
|
37
|
+
n = lambda{|i|
|
38
|
+
lambda{|j| "#{i} #{z+2*2} #{j.message.reverse}"
|
39
|
+
}
|
40
|
+
}[n].call(e)
|
41
|
+
unless retried
|
42
|
+
retried = true
|
43
|
+
retry
|
44
|
+
end
|
45
|
+
rescue ArgumentError => e
|
46
|
+
e.message
|
47
|
+
rescue
|
48
|
+
end
|
49
|
+
ensure
|
50
|
+
x << "ensure a-working"
|
51
|
+
end
|
52
|
+
|
53
|
+
def foobar a, █ block.call(a) end
|
54
|
+
def k; foobar [1,2,3].each { |x| x*2 } do |x| x*2 end end
|
55
|
+
|
56
|
+
def test_block_predecence_escape
|
57
|
+
eval RubyToRuby.translate(self.class, :k).sub(" k"," l")
|
58
|
+
assert_equal(k, l)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_hairy_method
|
62
|
+
eval RubyToRuby.translate(self.class, :hairy_method).sub(" h", " f")
|
63
|
+
|
64
|
+
blk = lambda{|x,y,z,arr|
|
65
|
+
unless y
|
66
|
+
x.to_i*2
|
67
|
+
else
|
68
|
+
x.to_i*y*z*arr.inject(1){|s,i| s+i}
|
69
|
+
end
|
70
|
+
}
|
71
|
+
x1 = ""
|
72
|
+
x2 = ""
|
73
|
+
res = [hairy_method(-5,x1,&blk), fairy_method(-5,x2,&blk)]
|
74
|
+
assert_equal(res.first, res.last)
|
75
|
+
assert_equal(x1, x2)
|
76
|
+
assert_equal("ensure a-working", x1)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'spec'
|
2
|
-
|
3
1
|
module Spec
|
4
2
|
module Tool
|
5
3
|
context "TestUnitApi" do
|
6
|
-
|
7
4
|
setup do
|
8
5
|
@an_int = 789
|
9
6
|
end
|
10
7
|
|
11
8
|
teardown do
|
9
|
+
nil
|
12
10
|
end
|
13
11
|
|
14
|
-
specify "
|
12
|
+
specify "can be translated to rspec" do
|
15
13
|
a_float = 123.45
|
16
14
|
a_nil = nil
|
17
|
-
|
15
|
+
true.should_be true
|
18
16
|
@an_int.should_not_be nil
|
19
|
-
lambda {
|
20
|
-
|
17
|
+
lambda {
|
18
|
+
true
|
19
|
+
}.should_be true
|
20
|
+
lambda {
|
21
21
|
true
|
22
|
-
|
22
|
+
}.should_be true
|
23
23
|
@an_int.should_equal 789
|
24
24
|
a_float.should_be_close 123.5, 0.1
|
25
25
|
@an_int.should_be_instance_of Fixnum
|
@@ -30,32 +30,46 @@ module Spec
|
|
30
30
|
@an_int.should_not_equal 780
|
31
31
|
@an_int.should_not_be nil
|
32
32
|
a_float.should_not_be @an_int
|
33
|
-
lambda {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
lambda {
|
34
|
+
foo = 1
|
35
|
+
}.should_not_raise
|
36
|
+
lambda {
|
37
|
+
bar = 2
|
38
|
+
}.should_not_raise
|
39
|
+
[2].each {|a|
|
40
|
+
a.should_equal 2
|
41
|
+
}
|
42
|
+
[0,1,2].each_with_index {|b, c|
|
43
|
+
b.should_equal c
|
44
|
+
}
|
45
|
+
lambda {
|
46
|
+
zip = 3
|
47
|
+
}.should_not_throw
|
48
|
+
lambda {
|
49
|
+
zap = 4
|
50
|
+
}.should_not_throw
|
51
|
+
lambda {
|
52
|
+
raise(NotImplementedError)
|
53
|
+
}.should_raise(NotImplementedError)
|
54
|
+
lambda {
|
55
|
+
raise(NotImplementedError)
|
56
|
+
}.should_raise(NotImplementedError)
|
57
|
+
lambda {
|
58
|
+
raise(NotImplementedError)
|
59
|
+
}.should_raise(NotImplementedError)
|
60
|
+
lambda {
|
61
|
+
raise(NotImplementedError)
|
62
|
+
}.should_raise(NotImplementedError)
|
50
63
|
@an_int.should_respond_to :to_f
|
51
64
|
a_float.should_be a_float
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
65
|
+
lambda {
|
66
|
+
throw(:foo)
|
67
|
+
}.should_throw(:foo)
|
68
|
+
lambda {
|
69
|
+
throw(:foo)
|
70
|
+
}.should_throw(:foo)
|
58
71
|
end
|
72
|
+
|
59
73
|
end
|
60
74
|
end
|
61
75
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test/unit'
|
2
2
|
|
3
3
|
module Spec
|
4
4
|
module Tool
|
@@ -15,7 +15,8 @@ module Spec
|
|
15
15
|
a_float = 123.45
|
16
16
|
a_nil = nil
|
17
17
|
|
18
|
-
assert
|
18
|
+
assert true
|
19
|
+
assert_not_nil @an_int
|
19
20
|
assert_block { true }
|
20
21
|
assert_block do
|
21
22
|
true
|
@@ -32,11 +33,17 @@ module Spec
|
|
32
33
|
assert_not_same @an_int, a_float, "a message"
|
33
34
|
assert_nothing_raised { foo = 1 }
|
34
35
|
assert_nothing_raised do
|
35
|
-
|
36
|
+
bar = 2
|
36
37
|
end
|
37
|
-
|
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 }
|
38
45
|
assert_nothing_thrown do
|
39
|
-
|
46
|
+
zap = 4
|
40
47
|
end
|
41
48
|
#assert_operator object1, operator, object2, "a message"
|
42
49
|
assert_raise(NotImplementedError){ raise NotImplementedError }
|
@@ -54,8 +61,8 @@ module Spec
|
|
54
61
|
assert_throws(:foo, "a message") do
|
55
62
|
throw :foo
|
56
63
|
end
|
57
|
-
|
58
64
|
end
|
65
|
+
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'rubygems'
|
2
3
|
require 'spec/tool/test_unit_translator'
|
4
|
+
require 'spec/tool/test_unit_api_test'
|
3
5
|
require 'tempfile'
|
4
6
|
|
5
7
|
module Spec
|
@@ -8,7 +10,9 @@ module Spec
|
|
8
10
|
def test_should_translate_test_classes_to_contexts
|
9
11
|
c = TestUnitTranslator.new
|
10
12
|
test_unit_file = File.dirname(__FILE__) + '/test_unit_api_test.rb'
|
11
|
-
translated = c.translate(
|
13
|
+
translated = c.translate(Spec::Tool::TestUnitApiTest)
|
14
|
+
#puts translated
|
15
|
+
#exit!1
|
12
16
|
expected_path = File.dirname(__FILE__) + '/test_unit_api_spec.rb'
|
13
17
|
expected = File.open(expected_path).read
|
14
18
|
|
@@ -24,6 +28,7 @@ module Spec
|
|
24
28
|
assert true # Just so we get an assertion count in the output
|
25
29
|
end
|
26
30
|
end
|
31
|
+
|
27
32
|
end
|
28
33
|
end
|
29
34
|
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.8
|
7
|
+
date: 2006-06-09 00:00:00 -05:00
|
8
|
+
summary: RSpec-0.5.8 - BDD for Ruby http://rspec.rubyforge.org/
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: rspec-devel@rubyforge.org
|
@@ -29,6 +29,7 @@ authors:
|
|
29
29
|
- Steven Baker, Aslak Hellesoy, Dave Astels, David Chelimsky
|
30
30
|
files:
|
31
31
|
- CHANGES
|
32
|
+
- EXAMPLES.rd
|
32
33
|
- Rakefile
|
33
34
|
- README
|
34
35
|
- lib/spec.rb
|
@@ -69,8 +70,9 @@ files:
|
|
69
70
|
- lib/spec/runner/spec_matcher.rb
|
70
71
|
- lib/spec/runner/specdoc_formatter.rb
|
71
72
|
- lib/spec/runner/specification.rb
|
72
|
-
- lib/spec/tool/
|
73
|
+
- lib/spec/tool/ruby2ruby.rb
|
73
74
|
- lib/spec/tool/test_unit_translator.rb
|
75
|
+
- lib/spec/tool/translation_test_runner.rb
|
74
76
|
- test/test_helper.rb
|
75
77
|
- test/spec/api/duck_type_test.rb
|
76
78
|
- test/spec/api/sugar_test.rb
|
@@ -103,7 +105,7 @@ files:
|
|
103
105
|
- test/spec/runner/spec_matcher_test.rb
|
104
106
|
- test/spec/runner/specdoc_formatter_test.rb
|
105
107
|
- test/spec/runner/specification_test.rb
|
106
|
-
- test/spec/tool/
|
108
|
+
- test/spec/tool/ruby_to_ruby_test.rb
|
107
109
|
- test/spec/tool/test_unit_api_spec.rb
|
108
110
|
- test/spec/tool/test_unit_api_test.rb
|
109
111
|
- test/spec/tool/test_unit_translator_test.rb
|
@@ -144,7 +146,7 @@ files:
|
|
144
146
|
- doc/src/tools/rake.page
|
145
147
|
- doc/src/tools/rcov.page
|
146
148
|
- doc/src/tools/spec.page
|
147
|
-
- doc/src/tools/
|
149
|
+
- doc/src/tools/test2spec.page
|
148
150
|
- doc/src/tutorials/index.page
|
149
151
|
- doc/src/tutorials/meta.info
|
150
152
|
- doc/src/tutorials/notes.txt
|
@@ -159,22 +161,21 @@ files:
|
|
159
161
|
- doc/src/tutorials/stack_06.page
|
160
162
|
- doc/src/tutorials/stack_06.page.orig
|
161
163
|
- doc/src/tutorials/stack_spec.rb
|
162
|
-
- EXAMPLES.rd
|
163
164
|
test_files: []
|
164
165
|
|
165
166
|
rdoc_options:
|
166
167
|
- --title
|
167
168
|
- RSpec
|
169
|
+
- --line-numbers
|
170
|
+
- --inline-source
|
168
171
|
- --main
|
169
172
|
- README
|
170
|
-
- --line-numbers
|
171
173
|
extra_rdoc_files:
|
172
174
|
- README
|
173
175
|
- CHANGES
|
174
|
-
- EXAMPLES.rd
|
175
176
|
executables:
|
176
177
|
- spec
|
177
|
-
-
|
178
|
+
- test2spec
|
178
179
|
extensions: []
|
179
180
|
|
180
181
|
requirements: []
|
data/bin/test2rspec
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'find'
|
4
|
-
require 'ostruct'
|
5
|
-
require 'optparse'
|
6
|
-
require File.dirname(__FILE__) + "/../lib/spec/tool/command_line.rb"
|
7
|
-
require File.dirname(__FILE__) + "/../lib/spec/tool/test_unit_translator.rb"
|
8
|
-
|
9
|
-
opts = OptionParser.new do |opts|
|
10
|
-
opts.banner = "Usage: test2rspec [options] SRC [DEST]"
|
11
|
-
opts.separator ""
|
12
|
-
|
13
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
14
|
-
puts opts
|
15
|
-
exit
|
16
|
-
end
|
17
|
-
end
|
18
|
-
opts.parse!(ARGV)
|
19
|
-
|
20
|
-
cl = Spec::Tool::CommandLine.new
|
21
|
-
source = ARGV[0]
|
22
|
-
target = ARGV[1]
|
23
|
-
|
24
|
-
if source.nil?
|
25
|
-
STDERR.puts opts
|
26
|
-
exit 1
|
27
|
-
end
|
28
|
-
|
29
|
-
begin
|
30
|
-
cl.run source, target, STDOUT
|
31
|
-
rescue => e
|
32
|
-
STDERR.puts e.message
|
33
|
-
STDERR.puts e.backtrace.join("\n")
|
34
|
-
STDERR.puts opts
|
35
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: Test::Unit Migration
|
3
|
-
inMenu: true
|
4
|
-
---
|
5
|
-
h2. Test::Unit migration
|
6
|
-
|
7
|
-
rSpec provides a tool for translating existing Test::Unit files into specifications. Anything that cannot be converted is left in its original form. The command line is:
|
8
|
-
|
9
|
-
<pre>
|
10
|
-
test2rspec SRC [DEST]
|
11
|
-
</pre>
|
12
|
-
|
13
|
-
If DEST is not supplied, output is sent to STDOUT. SRC and DEST can be a file or a directory. If SRC is a directory, every test file under it will be translated.
|