rspec 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -0
- data/Rakefile +11 -11
- data/bin/spec +4 -1
- data/doc/src/documentation/index.page +37 -37
- data/doc/src/documentation/mocks.page +34 -34
- data/doc/src/documentation/underscores.page +5 -4
- data/doc/src/index.page +2 -2
- data/doc/src/tools/rails.page +11 -0
- data/doc/src/tools/spec.page +18 -3
- data/doc/src/tutorials/notes.txt +17 -6
- data/doc/src/tutorials/stack_04.page.orig +2 -2
- data/doc/src/tutorials/stack_05.page.orig +5 -5
- data/doc/src/tutorials/stack_06.page +7 -7
- data/doc/src/tutorials/stack_06.page.orig +7 -7
- data/examples/custom_formatter.rb +21 -0
- data/examples/mocking_spec.rb +1 -1
- data/examples/stack_spec.rb +21 -21
- data/lib/spec/runner/base_text_formatter.rb +42 -0
- data/lib/spec/runner/context_runner.rb +1 -1
- data/lib/spec/runner/kernel_ext.rb +1 -1
- data/lib/spec/runner/option_parser.rb +23 -7
- data/lib/spec/runner/progress_bar_formatter.rb +1 -1
- data/lib/spec/runner/rdoc_formatter.rb +0 -10
- data/lib/spec/runner/reporter.rb +3 -4
- data/lib/spec/runner/specdoc_formatter.rb +0 -3
- data/lib/spec/runner/specification.rb +3 -7
- data/lib/spec/tool/test_unit_translator.rb +20 -20
- data/lib/spec/version.rb +1 -1
- data/test/spec/api/mocks/mock_ordering_test.rb +28 -0
- data/test/spec/runner/context_test.rb +4 -4
- data/test/spec/runner/failure_dump_test.rb +7 -7
- data/test/spec/runner/option_parser_test.rb +22 -1
- data/test/spec/runner/progress_bar_formatter_test.rb +6 -0
- data/test/spec/runner/rdoc_formatter_test.rb +1 -1
- data/test/spec/runner/reporter_test.rb +9 -8
- data/test/spec/runner/specdoc_formatter_test.rb +5 -0
- data/test/spec/runner/specification_test.rb +8 -8
- data/test/spec/tool/command_line_test.rb +4 -4
- data/test/spec/tool/test_unit_api_spec.rb +25 -25
- metadata +5 -4
@@ -4,17 +4,18 @@ inMenu: true
|
|
4
4
|
---
|
5
5
|
h2. Underscore sugar
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
The internal implementation of RSpec actually uses chained method calls, so it's possible
|
8
|
+
to write:
|
9
9
|
|
10
10
|
<ruby>
|
11
11
|
lambda { 1.should.not.equal 1 }.should.raise
|
12
12
|
</ruby>
|
13
13
|
|
14
|
-
|
14
|
+
However, in order to make RSpec look and feel closer to other ruby code,
|
15
|
+
RSpec allows you to use underscores instead if you wish:
|
15
16
|
|
16
17
|
<ruby>
|
17
18
|
lambda { 1.should_not_equal 1 }.should_raise
|
18
19
|
</ruby>
|
19
20
|
|
20
|
-
|
21
|
+
Therefore, you will see the underscored syntax throughout the documentation and examples.
|
data/doc/src/index.page
CHANGED
@@ -55,11 +55,11 @@ context "BDD framework" do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
specify "should be adopted quickly" do
|
58
|
-
@bdd_framework.
|
58
|
+
@bdd_framework.should_be_adopted_quickly
|
59
59
|
end
|
60
60
|
|
61
61
|
specify "should be intuitive" do
|
62
|
-
@bdd_framework.
|
62
|
+
@bdd_framework.should_be_intuitive
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
data/doc/src/tools/rails.page
CHANGED
@@ -15,11 +15,13 @@ h3. Features
|
|
15
15
|
h3. Installation
|
16
16
|
|
17
17
|
RSpec support for rails lives in a separate gem. Install that gem:
|
18
|
+
|
18
19
|
<pre>
|
19
20
|
gem install rspec_generator
|
20
21
|
</pre>
|
21
22
|
|
22
23
|
Once the gem is installed, you must configure you Rails app. Stand in the root of your Rails app and run:
|
24
|
+
|
23
25
|
<pre>
|
24
26
|
ruby script/generate rspec
|
25
27
|
</pre>
|
@@ -40,17 +42,26 @@ For more information on each generator, just run them without any arguments.
|
|
40
42
|
|
41
43
|
h3. Running specs
|
42
44
|
|
45
|
+
All specs can be run with
|
46
|
+
|
47
|
+
<pre>
|
48
|
+
rake spec
|
49
|
+
</pre>
|
50
|
+
|
43
51
|
Model specs can be run with
|
52
|
+
|
44
53
|
<pre>
|
45
54
|
rake spec:models
|
46
55
|
</pre>
|
47
56
|
|
48
57
|
Controller specs can be run with
|
58
|
+
|
49
59
|
<pre>
|
50
60
|
rake spec:controllers
|
51
61
|
</pre>
|
52
62
|
|
53
63
|
To see all the RSpec related tasks, run
|
64
|
+
|
54
65
|
<pre>
|
55
66
|
rake --tasks spec
|
56
67
|
</pre>
|
data/doc/src/tools/spec.page
CHANGED
@@ -25,10 +25,10 @@ spec will exit with the exitcode 1 if one or more specs fail.
|
|
25
25
|
The general form of the command is
|
26
26
|
|
27
27
|
<pre>
|
28
|
-
spec [options] (FILE|DIRECTORY)+
|
28
|
+
spec [options] (FILE|DIRECTORY|GLOB)+
|
29
29
|
</pre>
|
30
30
|
|
31
|
-
Any number of files and
|
31
|
+
Any number of files, directories and shell globs can be provided, all ruby source files
|
32
32
|
that are found are loaded. Running spec on the previous example results in:
|
33
33
|
|
34
34
|
<pre>
|
@@ -68,10 +68,25 @@ $ bin/spec failing_examples/team_spec.rb -f rdoc
|
|
68
68
|
{execute: ../bin/spec ../failing_examples/team_spec.rb -f rdoc}
|
69
69
|
</pre>
|
70
70
|
|
71
|
+
h4. Custom formatters
|
72
|
+
|
73
|
+
As of RSpec 0.5.7 custom formatters are supported. If the argument to the --format option is none
|
74
|
+
of the builtin formatters, RSpec will assume it's a class name, and try to instantiate that class.
|
75
|
+
If you're using this feature, make sure to use the --require option as well - *before* the
|
76
|
+
--format option.
|
77
|
+
|
78
|
+
See the RDoc for "Spec::Runner::BaseTextFormatter":../rdoc/classes/Spec/Runner/BaseTextFormatter.html
|
79
|
+
for details on how to implement your own. A custom formatter can be found under examples/custom_formatter.rb.
|
80
|
+
|
81
|
+
h3. -r, --require FILE
|
82
|
+
|
83
|
+
Causes FILE to be loaded (via require) before any specs are executed. If you're using a custom
|
84
|
+
formatter, you have to specify this option *before* the --format option.
|
85
|
+
|
71
86
|
h3. -d, --dry-run
|
72
87
|
|
73
88
|
This option tells RSpec not to execute the specs, but they are still being parsed.
|
74
|
-
This can be useful when generating "testdox":http://agiledox.sourceforge.net/ documents
|
89
|
+
This can be useful when generating "testdox-like":http://agiledox.sourceforge.net/ documents
|
75
90
|
|
76
91
|
h3. -b, --backtrace
|
77
92
|
|
data/doc/src/tutorials/notes.txt
CHANGED
@@ -7,7 +7,7 @@ context "A stack with one item" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
specify "should return top when you send it 'top'" do
|
10
|
-
@stack.top.
|
10
|
+
@stack.top.should_equal "one item"
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
@@ -64,7 +64,10 @@ Finished in 0.000531 seconds
|
|
64
64
|
2 contexts, 2 specifications, 1 failure
|
65
65
|
</pre>
|
66
66
|
|
67
|
-
This is a very interesting result. <code>nil should equal "one item"</code> tells us that the expression
|
67
|
+
This is a very interesting result. <code>nil should equal "one item"</code> tells us that the expression
|
68
|
+
<code>@stack.top</code> returned nil. In ruby, nil is a real object to which you can send messages.
|
69
|
+
<code>should_equal "one item"</code> tells rspec that the object returned by the expression (in this case nil)
|
70
|
+
should be equal to the string literal "one item".
|
68
71
|
|
69
72
|
So let's get the code to meet this specification. When we do this, we want to implement the simplest thing that we can to satisfy the existing specs. Given the current set of specs, we can simply return "one item"
|
70
73
|
|
@@ -189,17 +192,25 @@ Finished in 0.000557 seconds
|
|
189
192
|
2 contexts, 3 specifications, 0 failures
|
190
193
|
</pre>
|
191
194
|
|
192
|
-
RSpec reads the contexts and specs within a given file in the order in which
|
195
|
+
RSpec reads the contexts and specs within a given file in the order in which
|
196
|
+
they appear, giving you some control over this output.
|
193
197
|
|
194
|
-
So what can we expect here? The name of the spec tells us - "should keep its
|
198
|
+
So what can we expect here? The name of the spec tells us - "should keep its
|
199
|
+
mouth shut". That implies that it should not react in any way - including
|
200
|
+
raising an error. So let's set the expectation that there will be no error raised:
|
195
201
|
|
196
202
|
<ruby>
|
197
203
|
specify "should keep its mouth shut when you send it 'push'" do
|
198
|
-
lambda { @stack.push Object.new }.
|
204
|
+
lambda { @stack.push Object.new }.should_not_raise
|
199
205
|
end
|
200
206
|
</ruby>
|
201
207
|
|
202
|
-
If you're not familiar, <code>lambda</code> accepts a block but does not
|
208
|
+
If you're not familiar, <code>lambda</code> accepts a block but does not
|
209
|
+
execute it. It then constructs a Proc object, which can called at any time.
|
210
|
+
So, in this case, the block <code>{ stack.push Object.new }</code> gets saved
|
211
|
+
in a Proc object. <code>should_not_raise</code> then tells rSpec to call the
|
212
|
+
Proc and raise an ExpectationNotMetError if it raises any errors at all.
|
213
|
+
Running the spec...
|
203
214
|
|
204
215
|
<pre>
|
205
216
|
$ spec stack_spec.rb -v
|
@@ -14,11 +14,11 @@ context "An empty stack" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
specify "should keep its mouth shut when you send it 'push'" do
|
17
|
-
lambda { @stack.push Object.new }.
|
17
|
+
lambda { @stack.push Object.new }.should_not_raise Exception
|
18
18
|
end
|
19
19
|
|
20
20
|
specify "should raise a StackUnderflowError when you send it 'top'" do
|
21
|
-
lambda { @stack.top }.
|
21
|
+
lambda { @stack.top }.should_raise StackUnderflowError
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -14,11 +14,11 @@ context "An empty stack" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
specify "should keep its mouth shut when you send it 'push'" do
|
17
|
-
lambda { @stack.push Object.new }.
|
17
|
+
lambda { @stack.push Object.new }.should_not_raise Exception
|
18
18
|
end
|
19
19
|
|
20
20
|
specify "should raise a StackUnderflowError when you send it 'top'" do
|
21
|
-
lambda { @stack.top }.
|
21
|
+
lambda { @stack.top }.should_raise StackUnderflowError
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -31,7 +31,7 @@ context "A stack with one item" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
specify "should return top when sent the 'top' message" do
|
34
|
-
@stack.top.
|
34
|
+
@stack.top.should_equal "one item"
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -80,11 +80,11 @@ context "A stack with one item" do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
specify "should keep its mouth shut when you send it 'push'" do
|
83
|
-
lambda { @stack.push Object.new }.
|
83
|
+
lambda { @stack.push Object.new }.should_not_raise Exception
|
84
84
|
end
|
85
85
|
|
86
86
|
specify "should return top when you send it 'top'" do
|
87
|
-
@stack.top.
|
87
|
+
@stack.top.should_equal "one item"
|
88
88
|
end
|
89
89
|
|
90
90
|
end
|
@@ -10,15 +10,15 @@ context "An empty stack" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
specify "should keep its mouth shut when you send it 'push'" do
|
13
|
-
lambda { @stack.push Object.new }.
|
13
|
+
lambda { @stack.push Object.new }.should_not.raise Exception
|
14
14
|
end
|
15
15
|
|
16
16
|
specify "should raise a StackUnderflowError when you send it 'top'" do
|
17
|
-
lambda { @stack.top }.
|
17
|
+
lambda { @stack.top }.should_raise StackUnderflowError
|
18
18
|
end
|
19
19
|
|
20
20
|
specify "should raise a StackUnderflowError when you send it 'pop'" do
|
21
|
-
lambda { @stack.pop }.
|
21
|
+
lambda { @stack.pop }.should_raise StackUnderflowError
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -121,15 +121,15 @@ context "A stack with one item" do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
specify "should keep its mouth shut when you send it 'push'" do
|
124
|
-
lambda { @stack.push Object.new }.
|
124
|
+
lambda { @stack.push Object.new }.should_not.raise Exception
|
125
125
|
end
|
126
126
|
|
127
127
|
specify "should return top when you send it 'top'" do
|
128
|
-
@stack.top.
|
128
|
+
@stack.top.should_equal "one item"
|
129
129
|
end
|
130
130
|
|
131
131
|
specify "should return top when you send it 'pop'" do
|
132
|
-
@stack.pop.
|
132
|
+
@stack.pop.should_equal "one item"
|
133
133
|
end
|
134
134
|
|
135
135
|
end
|
@@ -236,7 +236,7 @@ What we're looking for here is observable behaviour. How does a one-element stac
|
|
236
236
|
<ruby>
|
237
237
|
specify "should raise a StackUnderflowError the second time you sent it 'pop'" do
|
238
238
|
@stack.pop
|
239
|
-
lambda { @stack.pop }.
|
239
|
+
lambda { @stack.pop }.should_raise StackUnderflowError
|
240
240
|
end
|
241
241
|
</ruby>
|
242
242
|
|
@@ -295,20 +295,20 @@ context "A stack with one item" do
|
|
295
295
|
end
|
296
296
|
|
297
297
|
specify "should keep its mouth shut when you send it 'push'" do
|
298
|
-
lambda { @stack.push Object.new }.
|
298
|
+
lambda { @stack.push Object.new }.should_not_raise Exception
|
299
299
|
end
|
300
300
|
|
301
301
|
specify "should return top when you send it 'top'" do
|
302
|
-
@stack.top.
|
302
|
+
@stack.top.should_equal "one item"
|
303
303
|
end
|
304
304
|
|
305
305
|
specify "should return top when you send it 'pop'" do
|
306
|
-
@stack.pop.
|
306
|
+
@stack.pop.should_equal "one item"
|
307
307
|
end
|
308
308
|
|
309
309
|
specify "should raise a StackUnderflowError the second time you sent it 'pop'" do
|
310
310
|
@stack.pop
|
311
|
-
lambda { @stack.pop }.
|
311
|
+
lambda { @stack.pop }.should_raise StackUnderflowError
|
312
312
|
end
|
313
313
|
|
314
314
|
end
|
@@ -322,9 +322,9 @@ context "A stack with one item" do
|
|
322
322
|
...
|
323
323
|
|
324
324
|
specify "should return top repeatedly when you send it 'top'" do
|
325
|
-
@stack.top.
|
326
|
-
@stack.top.
|
327
|
-
@stack.top.
|
325
|
+
@stack.top.should_equal "one item"
|
326
|
+
@stack.top.should_equal "one item"
|
327
|
+
@stack.top.should_equal "one item"
|
328
328
|
end
|
329
329
|
|
330
330
|
...
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec/runner/base_text_formatter'
|
2
|
+
|
3
|
+
# Example of a custom formatter. Run me with:
|
4
|
+
# bin/spec examples -r examples/custom_formatter.rb -f CustomFormatter
|
5
|
+
class CustomFormatter < Spec::Runner::BaseTextFormatter
|
6
|
+
def add_context(name, first)
|
7
|
+
@output << "\n" if first
|
8
|
+
end
|
9
|
+
|
10
|
+
def spec_failed(name, counter)
|
11
|
+
@output << 'X'
|
12
|
+
end
|
13
|
+
|
14
|
+
def spec_passed(name)
|
15
|
+
@output << '_'
|
16
|
+
end
|
17
|
+
|
18
|
+
def start_dump
|
19
|
+
@output << "\n"
|
20
|
+
end
|
21
|
+
end
|
data/examples/mocking_spec.rb
CHANGED
data/examples/stack_spec.rb
CHANGED
@@ -16,7 +16,7 @@ context "An empty stack" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
specify "should complain when sent pop" do
|
19
|
-
lambda { @stack.pop }.
|
19
|
+
lambda { @stack.pop }.should_raise StackUnderflowError
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -29,25 +29,25 @@ context "A stack with one item" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
specify "should accept an item when sent push" do
|
32
|
-
lambda { @stack.push Object.new }.
|
32
|
+
lambda { @stack.push Object.new }.should_not_raise
|
33
33
|
end
|
34
34
|
|
35
35
|
specify "should return top when sent top" do
|
36
|
-
@stack.top.
|
36
|
+
@stack.top.should_be 3
|
37
37
|
end
|
38
38
|
|
39
39
|
specify "should not remove top when sent top" do
|
40
|
-
@stack.top.
|
41
|
-
@stack.top.
|
40
|
+
@stack.top.should_be 3
|
41
|
+
@stack.top.should_be 3
|
42
42
|
end
|
43
43
|
|
44
44
|
specify "should return top when sent pop" do
|
45
|
-
@stack.pop.
|
45
|
+
@stack.pop.should_be 3
|
46
46
|
end
|
47
47
|
|
48
48
|
specify "should remove top when sent pop" do
|
49
|
-
@stack.pop.
|
50
|
-
lambda { @stack.pop }.
|
49
|
+
@stack.pop.should_be 3
|
50
|
+
lambda { @stack.pop }.should_raise StackUnderflowError
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -64,21 +64,21 @@ context "An almost full stack (with one item less than capacity)" do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
specify "should return top when sent top" do
|
67
|
-
@stack.top.
|
67
|
+
@stack.top.should_be 9
|
68
68
|
end
|
69
69
|
|
70
70
|
specify "should not remove top when sent top" do
|
71
|
-
@stack.top.
|
72
|
-
@stack.top.
|
71
|
+
@stack.top.should_be 9
|
72
|
+
@stack.top.should_be 9
|
73
73
|
end
|
74
74
|
|
75
75
|
specify "should return top when sent pop" do
|
76
|
-
@stack.pop.
|
76
|
+
@stack.pop.should_be 9
|
77
77
|
end
|
78
78
|
|
79
79
|
specify "should remove top when sent pop" do
|
80
|
-
@stack.pop.
|
81
|
-
@stack.pop.
|
80
|
+
@stack.pop.should_be 9
|
81
|
+
@stack.pop.should_be 8
|
82
82
|
end
|
83
83
|
|
84
84
|
end
|
@@ -91,25 +91,25 @@ context "A full stack" do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
specify "should complain on push" do
|
94
|
-
lambda { @stack.push Object.new }.
|
94
|
+
lambda { @stack.push Object.new }.should_raise StackOverflowError
|
95
95
|
end
|
96
96
|
|
97
97
|
specify "should return top when sent top" do
|
98
|
-
@stack.top.
|
98
|
+
@stack.top.should_be 10
|
99
99
|
end
|
100
100
|
|
101
101
|
specify "should not remove top when sent top" do
|
102
|
-
@stack.top.
|
103
|
-
@stack.top.
|
102
|
+
@stack.top.should_be 10
|
103
|
+
@stack.top.should_be 10
|
104
104
|
end
|
105
105
|
|
106
106
|
specify "should return top when sent pop" do
|
107
|
-
@stack.pop.
|
107
|
+
@stack.pop.should_be 10
|
108
108
|
end
|
109
109
|
|
110
110
|
specify "should remove top when sent pop" do
|
111
|
-
@stack.pop.
|
112
|
-
@stack.pop.
|
111
|
+
@stack.pop.should_be 10
|
112
|
+
@stack.pop.should_be 9
|
113
113
|
end
|
114
114
|
|
115
115
|
end
|
@@ -1,11 +1,52 @@
|
|
1
1
|
module Spec
|
2
2
|
module Runner
|
3
|
+
# Baseclass for text-based formatters. Can in fact be used for
|
4
|
+
# non-text based ones too - just ignore the +output+ constructor
|
5
|
+
# argument.
|
3
6
|
class BaseTextFormatter
|
4
7
|
def initialize(output, dry_run=false)
|
5
8
|
@dry_run = dry_run
|
6
9
|
@output = output
|
7
10
|
end
|
8
11
|
|
12
|
+
# This method is invoked before any specs are run, right after
|
13
|
+
# they have all been collected. This can be useful for special
|
14
|
+
# formatters that need to provide progress on feedback (graphical ones)
|
15
|
+
#
|
16
|
+
# This method will only be invoked once, and the next one to be invoked
|
17
|
+
# is #add_context
|
18
|
+
def start(spec_count)
|
19
|
+
end
|
20
|
+
|
21
|
+
# This method is invoked at the beginning of the execution of each context.
|
22
|
+
# +name+ is the name of the context and +first+ is true if it is the
|
23
|
+
# first context - otherwise it's false.
|
24
|
+
#
|
25
|
+
# The next method to be invoked after this one is one of #spec_failed
|
26
|
+
# or #spec_passed.
|
27
|
+
def add_context(name, first)
|
28
|
+
end
|
29
|
+
|
30
|
+
# This method is invoked whenever a spec fails, i.e. an exception occurred
|
31
|
+
# inside it (such as a failed should or other exception). +name+ is the name
|
32
|
+
# of the specification.
|
33
|
+
def spec_failed(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# This method is invoked whwnever a spec passes. +name+ is the name of the
|
37
|
+
# specification.
|
38
|
+
def spec_passed(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
# This method is invoked after all of the specs have executed. The next method
|
42
|
+
# to be invoked after this one is #dump_failure (once for each failed spec),
|
43
|
+
def start_dump
|
44
|
+
end
|
45
|
+
|
46
|
+
# Dumps detailed information about a spec failure.
|
47
|
+
# This method is invoked for each failed spec. +counter+ is the sequence number
|
48
|
+
# of the associated spec. +failure+ is a Failure object, which contains detailed
|
49
|
+
# information about the failure.
|
9
50
|
def dump_failure(counter, failure)
|
10
51
|
@output << "\n"
|
11
52
|
@output << counter.to_s << ")\n"
|
@@ -14,6 +55,7 @@ module Spec
|
|
14
55
|
@output << "#{failure.backtrace}\n"
|
15
56
|
end
|
16
57
|
|
58
|
+
# This method is invoked at the very end.
|
17
59
|
def dump_summary(duration, context_count, spec_count, failure_count)
|
18
60
|
return if @dry_run
|
19
61
|
@output << "\n"
|