Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 261 lines (175 sloc) 7.935 kb
87ab554 @dchelimsky prep for 1.3.0
dchelimsky authored
1 = Upgrade to 1.3.0
f3cf634 @dchelimsky add raise_exception matcher
dchelimsky authored
2
bad2131 @dchelimsky update History and Upgrade
dchelimsky authored
3 == What's changed
4
87ab554 @dchelimsky prep for 1.3.0
dchelimsky authored
5 === +be_true+ and +be_false+
bad2131 @dchelimsky update History and Upgrade
dchelimsky authored
6
7 These methods now align with Ruby's conditional semantics:
8
87ab554 @dchelimsky prep for 1.3.0
dchelimsky authored
9 * +be_false+ passes for +false+ and +nil+
10 * +be_true+ passes for everything else
bad2131 @dchelimsky update History and Upgrade
dchelimsky authored
11
12 This is a change from the previous behaviour (which wasn't working correctly
87ab554 @dchelimsky prep for 1.3.0
dchelimsky authored
13 anyway), which was supposed to treat +be_true+ as <tt>equal(true)</tt>, and +be_false+ as
14 <tt>equal(false)</tt>.
bad2131 @dchelimsky update History and Upgrade
dchelimsky authored
15
f3cf634 @dchelimsky add raise_exception matcher
dchelimsky authored
16 If the actual values +true+ and +false+ are meaningful to your examples, you'll
87ab554 @dchelimsky prep for 1.3.0
dchelimsky authored
17 want to change the to use <tt>equal(true)</tt> and <tt>equal(false)</tt> (or
18 <tt>==(true)</tt> and <tt>==(false)</tt>).
19
20 === +raise_exception+
21
22 We changed the +raise_error+ matcher to +raise_exception+, and aliased it with
23 +raise_error+. This maintains backward compatibility, and also gives you the
24 option of being more precise in specs about what is expected.
25
26 === Matcher DSL
27
28 ==== +match+ rescues from +ExpectationNotMetErrror+ by default
29
30 This allows you to wrap other expectations in the +match+ method. Consider
31 this matcher:
32
33 Spec::Matchers.define :teach do |subject|
34 match do |teacher|
35 teacher.subjects.should include(subject)
36 end
37 end
38
39 The block passed to +match+ is called internally by Rspec, and is expected to
40 return a boolean value. In this case, if <tt>should include(subject)</tt>
41 fails, it raises an +ExpectationNotMetError+.
42
43 Beginning with rspec-1.3.0, when the match block raises an
44 +ExpectationNotMetError+, it is captured and the block returns +false+.
45 Otherwise it returns +true+, so it works like any other matcher.
46
47 ==== match_unless_raises
48
49 The new +match_unless_raises+ method allows you to wrap <tt>Test::Unit</tt>
50 assertions by capturing +AssertionFailedError+ and returning false, just as the
51 +match+ method now does with +ExpectationNotMetError+.
52
53 Spec::Matchers.define :teach do |subject|
54 match_unless_raises Test::Unit::AssertionFailedError do |teacher|
55 assert teacher.subjects.include?(subject)
56 end
57 end
bad2131 @dchelimsky update History and Upgrade
dchelimsky authored
58
f5de4eb @dchelimsky update History
dchelimsky authored
59 = Upgrade to rspec-1.2.9
60
61 == What's new
62
8eea6ab @dchelimsky update History and Upgrade info
dchelimsky authored
63 === spec/spec.opts
64
65 If you have a spec/spec.opts file, the spec command will now use that
66 automatically as long as you don't include any options on the command line.
67
f5de4eb @dchelimsky update History
dchelimsky authored
68 === let()
69
f3cf634 @dchelimsky add raise_exception matcher
dchelimsky authored
70 Writing specs tends to follow a regular pattern of using local variables,
71 discovering duplication, and then having to convert to local variables to
72 instance variables by adding an "@" symbol. The let() method assigns the result
73 of a lazy eval'd block as the return value of an instance method using the same
74 name. This way you can go from this:
f5de4eb @dchelimsky update History
dchelimsky authored
75
76 describe Subscription do
77 it "does something" do
78 subscription = Subscription.create :limit => 1
79 subscription...
80 end
8eea6ab @dchelimsky update History and Upgrade info
dchelimsky authored
81
f5de4eb @dchelimsky update History
dchelimsky authored
82 it "does something else" do
83 subscription = Subscription.create :limit => 1
84 subscription...
85 end
86 end
87
88 to this:
89
90 describe Subscription do
91 let(:subscription) { Subscription.create :limit => 1 }
8eea6ab @dchelimsky update History and Upgrade info
dchelimsky authored
92
f5de4eb @dchelimsky update History
dchelimsky authored
93 it "does something" do
94 subscription...
95 end
8eea6ab @dchelimsky update History and Upgrade info
dchelimsky authored
96
f5de4eb @dchelimsky update History
dchelimsky authored
97 it "does something else" do
98 subscription...
99 end
100 end
101
8eea6ab @dchelimsky update History and Upgrade info
dchelimsky authored
102 === its()
103
104 If you're in the habit of writing one-liners using implicit subject, this new
105 its() feature is for you. Here's the basic idea:
106
107 describe Array do
108 its(:length) { should == 0 }
109 end
110
3ca0294 @dchelimsky bump to final 1.2.7
dchelimsky authored
111 = Upgrade to rspec-1.2.3-1.2.7
52a97a5 @dchelimsky Change add_example_group to example_group_started in formatters
dchelimsky authored
112
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
dchelimsky authored
113 == What's Changed
114
115 === Matcher DSL
116
117 Use Spec::Matchers.define instead of Spec::Matchers.create (which is now
118 deprecated).
52a97a5 @dchelimsky Change add_example_group to example_group_started in formatters
dchelimsky authored
119
c311d53 @dchelimsky words
dchelimsky authored
120 === Explicit Predicate Matchers are deprecated
121
122 With the addition of the new Matcher DSL the old, confusing, and
123 almost-nobody-uses-it explicit predicate matcher functionality's days are now
124 numbered.
125
126 If you're not familiar with this feature, don't worry about it. If you have anything
127 that looks like this:
128
129 predicate_matchers[:swim] = :can_swim?
f5de4eb @dchelimsky update History
dchelimsky authored
130
c311d53 @dchelimsky words
dchelimsky authored
131 Or this
132
133 config.predicate_matchers[:swim] = :can_swim?
f5de4eb @dchelimsky update History
dchelimsky authored
134
c311d53 @dchelimsky words
dchelimsky authored
135 Change it to this:
136
137 Spec::Matchers.define :swim do
138 match do |potential_swimmer|
139 potential_swimmer.can_swim?
140 end
141 end
142
52a97a5 @dchelimsky Change add_example_group to example_group_started in formatters
dchelimsky authored
143 == Custom Formatters
144
145 If you have an custom formatter, the <tt>add_example_group</tt> method has
146 been changed to <tt>example_group_started</tt>, and kept as an alias so your
147 formatters will still work. Though not yet, <tt>add_example_group</tt> will be
148 deprecated in a future minor release, and removed in a future major release,
149 so we recommend you make this change now.
150
151 = Upgrade to rspec-1.2.2
9403afb @dchelimsky update upgrade
dchelimsky authored
152
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
153 == What's Changed
9403afb @dchelimsky update upgrade
dchelimsky authored
154
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
155 === <tt>require 'rubygems' unless ENV['NO_RUBYGEMS']</tt>
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
156
157 After minor public outcry and confusion, we restored necessary references to
158 rubygems in rspec. If you use a different mechanism for managing gems, just
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
159 set a <tt>NO_RUBYGEMS</tt> environment variable (to any non-nil value).
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
160
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
161 === Proxies and locations
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
162
163 This is probably only interesting to you if you use custom formatters.
164
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
165 Formatters now receive Spec::Example::ExampleGroupProxy and
166 Spec::Example::ExampleGroup objects with cohesive APIs for reporting. See the
167 RDoc for those classes and Spec::Runner::Formatter::BaseFormatter for more
168 information.
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
169
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
170 == What's new
9403afb @dchelimsky update upgrade
dchelimsky authored
171
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
172 === The new matcher DSL works with test/unit (without the rest of rspec)
9403afb @dchelimsky update upgrade
dchelimsky authored
173
174 We'll be separating this out to its own gem for rspec 2.0, but for now, just install
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
175 rspec >= 1.2.1 and add the following to your <tt>test_helper</tt> file:
f5de4eb @dchelimsky update History
dchelimsky authored
176
9403afb @dchelimsky update upgrade
dchelimsky authored
177 require 'spec/expectations'
178 class Test::Unit::TestCase
179 include Spec::Matchers
180 end
f5de4eb @dchelimsky update History
dchelimsky authored
181
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
182 This will add <tt>should()</tt> and <tt>should_not()</tt> to your objects, make all of
9403afb @dchelimsky update upgrade
dchelimsky authored
183 rspec's built-in matchers available to your tests, INCLUDING rspec's DSL for
184 creating matchers (see below, under Upgrade to rspec-1.2.0)
185
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
186 === debugger
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
187
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
188 If you have ruby-debug installed, you can set a breakpoint by adding <tt>debugger()</tt>
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
189 in your code:
190
191 # some code .....
192 debugger
193 # some more code ....
f5de4eb @dchelimsky update History
dchelimsky authored
194
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
195 ... and using the <tt>--debugger</tt> or <tt>-u</tt> command line option.
cd14eee @dchelimsky doco for ExampleGroupProxy and ExampleProxy
dchelimsky authored
196
197 spec path/to/file.rb --debugger
f5de4eb @dchelimsky update History
dchelimsky authored
198
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
199 = Upgrade to rspec-1.2.0
18632ff @dchelimsky update equal matcher to new protocol
dchelimsky authored
200
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
201 == What's Changed
730cc6e @dchelimsky words
dchelimsky authored
202
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
203 === WARNINGS
18632ff @dchelimsky update equal matcher to new protocol
dchelimsky authored
204
205 * If you use the ruby command to run specs instead of the spec command, you'll
206 need to require 'spec/autorun' or they won't run. This won't affect you if
207 you use the spec command or the Spec::Rake::SpecTask that ships with RSpec.
208
209 * require 'spec/test/unit' to invoke test/unit interop if you're using
210 RSpec's core (this is handled implicitly with spec-rails)
211
b0a6f28 @dchelimsky words
dchelimsky authored
212 * setup and teardown are gone - use before and after instead
213
214 * you can still use setup and teardown if you're using
215 Test::Unit::TestCase as the base ExampleGroup class (which is implicit
216 in rspec-rails)
217
ed09e27 @dchelimsky Update info in prep for 1.2 release
dchelimsky authored
218 * The matcher protocol has been improved. The old protocol is still supported,
219 but we added support for two new methods that speak a bit more clearly:
f5de4eb @dchelimsky update History
dchelimsky authored
220
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
221 failure_message => failure_message_for_should
222 negative_failure_message => failure_message_for_should_not
18632ff @dchelimsky update equal matcher to new protocol
dchelimsky authored
223
224 * All references to rubygems have been removed from within rspec's code.
225
ed09e27 @dchelimsky Update info in prep for 1.2 release
dchelimsky authored
226 * See http://gist.github.com/54177 for rationale and suggestions on
227 alternative approaches to loading rubygems
18632ff @dchelimsky update equal matcher to new protocol
dchelimsky authored
228
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
229 == What's New
730cc6e @dchelimsky words
dchelimsky authored
230
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
231 === Ruby 1.9
730cc6e @dchelimsky words
dchelimsky authored
232
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
233 RSpec now works with Ruby 1.9.1. See http://wiki.github.com/dchelimsky/rspec/ruby-191
ed09e27 @dchelimsky Update info in prep for 1.2 release
dchelimsky authored
234 for useful information.
730cc6e @dchelimsky words
dchelimsky authored
235
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
236 === Improved heckle integration
730cc6e @dchelimsky words
dchelimsky authored
237
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
238 RSpec works with heckle again! Gotta use heckle >= 1.4.2 for this to work
ed09e27 @dchelimsky Update info in prep for 1.2 release
dchelimsky authored
239 though, and it only works with ruby-1.8.6 and 1.8.7 (heckle doesn't support
240 1.9.1 yet).
730cc6e @dchelimsky words
dchelimsky authored
241
242 [sudo] gem install heckle --version ">=1.4.2"
243 spec spec/game/mastermind.rb --heckle Game::Mastermind
244
0924861 @dchelimsky convert Upgrade to .rdoc
dchelimsky authored
245 === New Matcher DSL
18632ff @dchelimsky update equal matcher to new protocol
dchelimsky authored
246
247 We've added a new DSL for generating custom matchers very simply and cleanly.
248 We'll still support the simple_matcher method, so never fear if you're using
249 that, but we recommend that you start developing your new matchers with this
250 new syntax.
251
8a4f0ca @dchelimsky typo
dchelimsky authored
252 Spec::Matchers.create :be_a_multiple_of do |smaller|
b0a6f28 @dchelimsky words
dchelimsky authored
253 match do |bigger|
254 bigger % smaller == 0
255 end
256 end
257
258 9.should be_a_multiple_of(3)
18632ff @dchelimsky update equal matcher to new protocol
dchelimsky authored
259
045fa96 @dchelimsky deprecate Spec::Matchers.create (use Spec::Matchers.define instead)
dchelimsky authored
260 See <tt>features/matchers/define_matcher.feature</tt> for more examples
Something went wrong with that request. Please try again.