rspec 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/CHANGES +12 -0
  2. data/README +4 -2
  3. data/Rakefile +14 -4
  4. data/bin/spec +7 -7
  5. data/bin/test2spec +13 -8
  6. data/lib/spec/api/helper/diff.rb +53 -0
  7. data/lib/spec/api/helper/instance_helper.rb +11 -11
  8. data/lib/spec/api/helper/instance_negator.rb +11 -11
  9. data/lib/spec/api/helper/kind_helper.rb +11 -11
  10. data/lib/spec/api/helper/kind_negator.rb +11 -11
  11. data/lib/spec/api/helper/respond_helper.rb +11 -11
  12. data/lib/spec/api/helper/respond_negator.rb +11 -11
  13. data/lib/spec/api/helper/should_base.rb +6 -6
  14. data/lib/spec/api/helper/should_helper.rb +35 -35
  15. data/lib/spec/api/helper/should_negator.rb +20 -20
  16. data/lib/spec/rake/spectask.rb +15 -6
  17. data/lib/spec/runner.rb +1 -0
  18. data/lib/spec/runner/backtrace_tweaker.rb +2 -0
  19. data/lib/spec/runner/base_text_formatter.rb +3 -1
  20. data/lib/spec/runner/html_formatter.rb +153 -0
  21. data/lib/spec/runner/option_parser.rb +9 -2
  22. data/lib/spec/runner/progress_bar_formatter.rb +4 -0
  23. data/lib/spec/runner/rdoc_formatter.rb +3 -0
  24. data/lib/spec/runner/reporter.rb +5 -5
  25. data/lib/spec/runner/specdoc_formatter.rb +3 -0
  26. data/lib/spec/test_to_spec/sexp_transformer.rb +1 -0
  27. data/lib/spec/test_to_spec/translation_test_runner.rb +10 -2
  28. data/lib/spec/version.rb +1 -1
  29. data/test/spec/api/helper/arbitrary_predicate_test.rb +49 -73
  30. data/test/spec/api/helper/diff_test.rb +60 -0
  31. data/test/spec/api/helper/equality_test.rb +14 -0
  32. data/test/spec/api/helper/should_have_test.rb +0 -29
  33. data/test/spec/api/helper/typing_test.rb +87 -87
  34. data/test/spec/api/sugar_test.rb +0 -6
  35. data/test/spec/runner/backtrace_tweaker_test.rb +8 -2
  36. data/test/spec/runner/html_formatter_test.rb +47 -0
  37. data/test/spec/runner/option_parser_test.rb +0 -5
  38. data/test/test_classes.rb +73 -0
  39. data/test/test_helper.rb +3 -0
  40. metadata +8 -49
  41. data/doc/README +0 -3
  42. data/doc/config.yaml +0 -2
  43. data/doc/plugin/syntax.rb +0 -60
  44. data/doc/plugin/version.rb +0 -19
  45. data/doc/src/core_team.page +0 -31
  46. data/doc/src/default.css +0 -199
  47. data/doc/src/default.template +0 -31
  48. data/doc/src/documentation/index.page +0 -188
  49. data/doc/src/documentation/meta.info +0 -22
  50. data/doc/src/documentation/mocks.page +0 -287
  51. data/doc/src/documentation/underscores.page +0 -21
  52. data/doc/src/examples.page +0 -9
  53. data/doc/src/images/David_and_Aslak.jpg +0 -0
  54. data/doc/src/images/Whats_That_Dude.jpg +0 -0
  55. data/doc/src/images/ducks1.png +0 -0
  56. data/doc/src/images/ul.gif +0 -0
  57. data/doc/src/index.page +0 -74
  58. data/doc/src/meta.info +0 -33
  59. data/doc/src/tools/index.page +0 -49
  60. data/doc/src/tools/meta.info +0 -18
  61. data/doc/src/tools/rails.page +0 -132
  62. data/doc/src/tools/rake.page +0 -21
  63. data/doc/src/tools/rcov.page +0 -28
  64. data/doc/src/tools/spec.page +0 -129
  65. data/doc/src/tools/test2spec.page +0 -103
  66. data/doc/src/tutorials/index.page +0 -52
  67. data/doc/src/tutorials/meta.info +0 -36
  68. data/doc/src/tutorials/notes.txt +0 -263
  69. data/doc/src/tutorials/stack.rb +0 -11
  70. data/doc/src/tutorials/stack_01.page +0 -226
  71. data/doc/src/tutorials/stack_02.page +0 -182
  72. data/doc/src/tutorials/stack_03.page +0 -283
  73. data/doc/src/tutorials/stack_04.page +0 -164
  74. data/doc/src/tutorials/stack_04.page.orig +0 -123
  75. data/doc/src/tutorials/stack_05.page +0 -90
  76. data/doc/src/tutorials/stack_05.page.orig +0 -124
  77. data/doc/src/tutorials/stack_06.page +0 -359
  78. data/doc/src/tutorials/stack_06.page.orig +0 -359
  79. data/doc/src/tutorials/stack_spec.rb +0 -25
  80. data/doc/src/ul.gif +0 -0
@@ -1,103 +0,0 @@
1
- ---
2
- title: Test::Unit Migration
3
- inMenu: true
4
- ---
5
- h2. Overview of test2spec
6
-
7
- RSpec's test2spec command line tool translates existing Test::Unit classes to RSpec.
8
-
9
- Before you can use test2spec you must gem install ParseTree (and RubyInline).
10
- RubyInline only works on systems that have a C compiler - i.e. most anything except Windows.
11
-
12
- If you're stuck on Windows, ask a friend who has a POSIX system to translate your specs.
13
- Once translated they can run on any Ruby platform (including Windows). After all, it's
14
- just Ruby.
15
-
16
- h2. The test2spec command line
17
-
18
- <pre>
19
- test2spec --help
20
- {execute: ruby ../bin/test2spec --help}
21
- </pre>
22
-
23
- A typical invocation might look like this:
24
-
25
- <pre>
26
- test2spec --template spec/test2spec.erb --specdir spec test
27
- </pre>
28
-
29
- Where spec/test2spec.erb contains the following:
30
-
31
- <pre>
32
- {includeFile: {filename: ../../../spec/test2spec.erb, processOutput: false}}
33
- </pre>
34
-
35
-
36
- h2. Sample translation
37
-
38
- <notextile>
39
- <table>
40
- <thead>
41
- <tr>
42
- <td>Test::Unit (input)</td>
43
- <td>RSpec (output)</td>
44
- </tr>
45
- </thead>
46
- <tbody>
47
- <tr>
48
- <td>
49
- <ruby file="../test/spec/test_to_spec/testfiles/test_unit_api_test.rb"/>
50
- </td>
51
- <td>
52
- <ruby file="../spec/translated/test_unit_api_spec.rb"/>
53
- </td>
54
- </tr>
55
- </tbody>
56
- </table>
57
- </notextile>
58
-
59
- h2. What's translated?
60
-
61
- test2spec only translates classes that extend from Test::Unit - and their methods. It will not bring over any
62
- code that isn't inside a Test::Unit class. This means that require statements at the top of your file, any
63
- non-Test::Unit classes (even if they are in in the same file as the test class) *will not be translated*.
64
-
65
- We recommend that you manually write a spec_helper.rb file with require statements and put it at the top
66
- of your spec directory. Also, write a test2spec.erb file that will put a <tt>require</tt> of that file at
67
- the top of each translated spec. Use the <tt>--template</tt> option to specify this erb file when you run test2spec.
68
-
69
- Sometimes, test classes have helper methods that don't start with test_ (and that are not setup or teardown).
70
- These methods will be moved inside the setup block, and will also have any core Test::Unit assert_* methods
71
- translated. (Non-Test::Unit core assert_ methods will not be translated.)
72
-
73
- So, there is a fair chance that you will have to do some manual editing after test2spec has run. We're only
74
- aiming to get most of the translation job done for you - not all of it.
75
-
76
- If you're translating Rails tests, please refer to the RSpec on Rails page for more detail of what needs to
77
- be done.
78
-
79
- h2. Troubleshooting
80
-
81
- In some cases, test2spec will not be able to translate a test class. In that case, please submit a bug report
82
- at RSpec's bug report system along with some code so we can reproduce (and hopefully - fix) the problem.
83
- -Or better - submit a patch.
84
-
85
- h2. Internals
86
-
87
- The test2spec commandline 'runs' the tests with a special test runner - one that translates and writes out
88
- the translations to disk instead of actually executing the tests.
89
-
90
- The translation is done by the <tt>Test::Unit::TestCase#to_rspec</tt> method (which test2spec adds to all
91
- test classes). This method will load the parse tree for the class, transform that tree to an RSpec context
92
- and return the source code (using RubyToRuby).
93
-
94
- test2spec is based directly on two other tools:
95
-
96
- * "RubyToRuby":http://blog.zenspider.com/archives/2005/02/rubytoruby.html
97
- * "ParseTree":http://rubyforge.org/projects/parsetree/
98
-
99
- In fact, it's based on a modified version of "George Moschovitis' RubyToRuby enhancement":http://dark.fhtr.org/ruby2ruby.rb
100
- of "Ryan Davis' original RubyToRuby":http://blog.zenspider.com/archives/2005/02/rubytoruby.html.
101
-
102
- It has been modified to fix some subtle bugs that were not found by Gerorge's tests. The modified RubyToRuby
103
- currently lives in RSpec's subversion repository.
@@ -1,52 +0,0 @@
1
- ---
2
- title: Overview
3
- ---
4
- h2. A Simple Stack - Overview
5
-
6
- h3. A simple (very much in progress) tutorial by David Chelimsky
7
-
8
- In this tutorial, we're going to explore Behaviour Driven Development using rSpec. A primary goal of BDD is to think about specifications rather than testing. We'll explore what that means, and how it affects the process of specifying components in a system. For example, one of the examples I've used in TDD classes is test-driving a Stack. It would usually start with a test like this:
9
-
10
- <ruby>
11
- #NOT A BDD EXAMPLE
12
- def test_new_stack_should_be_empty
13
- stack = Stack.new
14
- assert_equal(0, stack.size)
15
- end
16
- </ruby>
17
-
18
- We start with that because it is a VERY simple place to start. To get that test to pass, you need very little code...
19
-
20
- <ruby>
21
- class Stack
22
- def size
23
- 0
24
- end
25
- end
26
- </ruby>
27
-
28
- ...and you're off and running. So here's a question: what is the <em><b>behaviour</b></em> that is exhibited by <code>size</code>? You could say that the stack is answering the question correctly. But then the question becomes "what is the question?"
29
-
30
- Think of it this way: does size really matter? Keeping focused on the Stack example, I'd say the answer is often "no". Most clients probably care about whether they can push something on to the stack, or pop something off of it. But knowing whether it has 0 or 1000 items is only helpful if the client knows what those numbers mean. And that often requires asking more questions. For example, let's say we want to push but we want to check if we can first:
31
-
32
- <ruby>
33
- stack.push item if stack.size < stack.capacity
34
- </ruby>
35
-
36
- Instead, we could ask if the stack is full...
37
-
38
- <ruby>
39
- stack.push item unless stack.full?
40
- </ruby>
41
-
42
- ...but even then we have to know what it means to be full and adapt that knowledge to our real question which is "can I push something on to you"?
43
-
44
- <ruby>
45
- stack.push item if stack.accept? item
46
- </ruby>
47
-
48
- This is not to argue that "accept" is the best or right choice. The point is that all of this discussion has been about how our stack appears from the outside. We want to think about how other clients can use the object, not how the object will satisfy its clients' needs.
49
-
50
- "Tell, Don't Ask" is a powerful guideline, but sometimes you have to ask questions. So let's extend TDA with this: "...but if you MUST ask, then ask for what you really need". Do we need to know the stack's size? Probably not. We <em>do</em>, however, need to know whether we can push onto it.
51
-
52
- We'll be exploring these questions in this tutorial in addition to getting you started with rSpec. So <a href="stack_01.html">let's get started!</a>
@@ -1,36 +0,0 @@
1
- index.page:
2
- title: Overview
3
- inMenu: true
4
- orderInfo: 10
5
-
6
- stack_01.page:
7
- title: '1'
8
- inMenu: true
9
- orderInfo: 11
10
-
11
- stack_02.page:
12
- title: '2'
13
- inMenu: true
14
- orderInfo: 12
15
-
16
- stack_03.page:
17
- title: '3'
18
- inMenu: true
19
- orderInfo: 13
20
-
21
- stack_04.page:
22
- title: '4'
23
- inMenu: true
24
- orderInfo: 14
25
-
26
- stack_05.page:
27
- title: '5'
28
- inMenu: false
29
- orderInfo: 15
30
-
31
- stack_05.page:
32
- title: '6'
33
- inMenu: false
34
- orderInfo: 16
35
-
36
-
@@ -1,263 +0,0 @@
1
- <ruby>
2
- context "A stack with one item" do
3
-
4
- setup do
5
- @stack = Stack.new
6
- @stack.push "one item"
7
- end
8
-
9
- specify "should return top when you send it 'top'" do
10
- @stack.top.should_equal "one item"
11
- end
12
-
13
- end
14
- </ruby>
15
-
16
- Run the spec...
17
-
18
- <pre>
19
- $ spec stack_spec.rb -v
20
-
21
- An empty stack
22
- - should keep its mouth shut when you send it 'push'
23
-
24
- A stack with one item
25
- - should return top when you send it 'top' (FAILED - 1)
26
-
27
-
28
- 1)
29
- NoMethodError in 'A stack with one item should return top when you send it 'top''
30
- undefined method `top' for #<Stack:0x3703bc @item="one item">
31
- ./stack_spec.rb:35:in `should return top when you send it 'top''
32
-
33
- Finished in 0.000677 seconds
34
-
35
- 2 contexts, 2 specifications, 1 failure
36
- </pre>
37
-
38
- Again, running the spec tells us what we have to implement next. <code>undefined method `top' for #<Stack:0x3703bc @item="one item"></code> tells us to implement a <code>top</code> method. So, back in stack.rb...
39
-
40
- <ruby>
41
- def top
42
- end
43
- </ruby>
44
-
45
- Why not implement the return now? Well, this becomes a matter of taste and level of discipline. While you're learning BDD (especially if you have no prior TDD experience), you want to take very, very small steps. There's usually something to learn after each one. In this case, if we run the spec now...
46
-
47
- <pre>
48
- $ spec stack_spec.rb -v
49
-
50
- An empty stack
51
- - should keep its mouth shut when you send it 'push'
52
-
53
- A stack with one item
54
- - should return top when you send it 'top' (FAILED - 1)
55
-
56
-
57
- 1)
58
- ExpectationNotMetError in 'A stack with one item should return top when you send it 'top''
59
- nil should equal "one item"
60
- ./stack_spec.rb:35:in `should return top when you send it 'top''
61
-
62
- Finished in 0.000531 seconds
63
-
64
- 2 contexts, 2 specifications, 1 failure
65
- </pre>
66
-
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".
71
-
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"
73
-
74
- <ruby>
75
- class Stack
76
-
77
- def push item
78
- end
79
-
80
- def top
81
- "one item"
82
- end
83
-
84
- end
85
- </ruby>
86
-
87
- Run the specs...
88
-
89
- <pre>
90
- $ spec stack_spec.rb -v
91
-
92
- An empty stack
93
- - should keep its mouth shut when you send it 'push'
94
-
95
- A stack with one item
96
- - should return top when you send it 'top'
97
-
98
-
99
- Finished in 0.0004 seconds
100
-
101
- 2 contexts, 2 specifications, 0 failures
102
- </pre>
103
-
104
- Seems odd? We know that we don't want to always return "one item", so the implementation seems silly. But that implementation did something great. It made it so all of our expectations are met and we didn't have to change much to get there. We always want to take really small steps, with all the specs passing between each step. Now that we have passing specs, we're free to refactor - and we WANT to refactor because we've introduced duplication between the specs and the implementation.
105
-
106
- So let's refactor to eliminate this duplication. We can use the existing push method to setup the item that top will return.
107
-
108
- <ruby>
109
- class Stack
110
-
111
- def push item
112
- @item = item
113
- end
114
-
115
- def top
116
- @item
117
- end
118
-
119
- end
120
- </ruby>
121
-
122
- So now we have two specifications, each with their own context. We've implemented two simple methods that satisfy the existing specifications. If you've never done any TDD before this, this may seem really odd. We all know that this isn't enough to meet the specs that we intend. But right now, at this moment, as far as the code is concerned, there are only two simple specifications. To move our implementation along, we first have to specify more about how we want our stack to behave.
123
-
124
- <a href="stack_01.html">Previous</a> |
125
- <a href="stack_03.html">Next</a>
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
- OK. That's pretty standard stuff so far, but it's all about the object's <em><b>state</b></em>, not its behaviour. We want to think about what our Stack does - how it responds to various messages that we can send it. What should an empty Stack do when you send it the push method? Absolutely nothing, right? It should just accept the object and keep its mouth shut:
140
-
141
- <ruby>
142
- context "An empty stack" do
143
- ...
144
- specify "should keep its mouth shut when you send it 'push'" do
145
- end
146
- end
147
- </ruby>
148
- <pre>
149
- $ spec stack_spec.rb -f s
150
-
151
- A new stack
152
- - should be empty
153
-
154
- An empty stack
155
- - should not be empty after 'push'
156
- - should keep its mouth shut when you send it 'push'
157
-
158
- Finished in 0.000552 seconds
159
-
160
- 2 contexts, 3 specifications, 0 failures
161
- </pre>
162
-
163
- Actually, I'd like the "keep its mouth shut" spec to come first - I think it reads better. So let's just switch them around in the context:
164
-
165
- <ruby>
166
- context "An empty stack" do
167
- setup do
168
- @stack = Stack.new
169
- end
170
-
171
- specify "should keep its mouth shut when you send it 'push'" do
172
- end
173
-
174
- specify "should not be empty after 'push'" do
175
- @stack.push 37
176
- @stack.should_not_be_empty
177
- end
178
- end
179
- </ruby>
180
-
181
- <pre>$ spec stack_spec.rb -f s
182
-
183
- A new stack
184
- - should be empty
185
-
186
- An empty stack
187
- - should keep its mouth shut when you send it 'push'
188
- - should not be empty after 'push'
189
-
190
- Finished in 0.000557 seconds
191
-
192
- 2 contexts, 3 specifications, 0 failures
193
- </pre>
194
-
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.
197
-
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:
201
-
202
- <ruby>
203
- specify "should keep its mouth shut when you send it 'push'" do
204
- lambda { @stack.push Object.new }.should_not_raise
205
- end
206
- </ruby>
207
-
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...
214
-
215
- <pre>
216
- $ spec stack_spec.rb -v
217
-
218
- An empty stack
219
- - should keep its mouth shut when you send it 'push' (FAILED - 1)
220
-
221
-
222
- 1)
223
- ExpectationNotMetError in 'An empty stack should keep its mouth shut when you send it 'push''
224
- <Proc> should not raise <Exception> but raised #<NoMethodError: undefined method `push' for #<Stack:0x370d94>>
225
- ./stack_spec.rb:10:in `should keep its mouth shut when you send it 'push''
226
-
227
- Finished in 0.000418 seconds
228
-
229
- 1 context, 1 specification, 1 failure
230
- </pre>
231
-
232
- The first line tells us the rSpec error that was raised: we were expecting that nothing would be raised, but something (anything) was, so we get an "ExpectationNotMetError".
233
-
234
- The second line tells us that we specified that there should be no Exception (in this case we didn't specify what type of exception, so by default rSpec assumes Exception), but that there was a NoMethodError raised.
235
-
236
- The third line tells us that the error was raised in the block defining the specification "should keep its mouth shut when you send it 'push'".
237
-
238
- We get a NoMethodError because our stack doesn't know what to do with the "push" message. So we add it...
239
-
240
- <ruby>
241
- class Stack
242
- def push item
243
- end
244
- end
245
- </ruby>
246
-
247
- ...and run the spec and voila!...
248
-
249
- <pre>
250
- $ spec stack_spec.rb -v
251
-
252
- An empty stack
253
- - should keep its mouth shut when you send it 'push'
254
-
255
-
256
- Finished in 0.000209 seconds
257
-
258
- 1 context, 1 specification, 0 failures
259
- </pre>
260
-
261
- ... the code meets the first specification. Now obviously this code doesn't do much, but that's because we have more specifications to write!
262
-
263
- One important thing to note here is that we did not begin by setting any expectations about the size or emptiness of the stack. That may feel funny to experienced TDDers, as it is standard faire to verify that an empty collection is empty. As explained in the <a href="index.html">Overview</a>, we're going to explore what it means to specify behaviour rather than testing state. Based on our existing spec thus far, there is no need to have a size or empty method. Let's see how far we can go without them...