Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 2c4ae5c

Browse files
committed
Improve “Get Started” section of README.
It’s important that you see the expectation fail (it’s how you “test the test”, so to speak, and you can confirm it gives you a good failure message), so let’s not skip that step.
1 parent de156c1 commit 2c4ae5c

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,12 @@ $ rspec spec/calculator_spec.rb
203203
./spec/calculator_spec.rb:1: uninitialized constant Calculator
204204
```
205205

206-
Implement the simplest solution:
206+
Address the failure by defining a skeleton of the `Calculator` class:
207207

208208
```ruby
209209
# in lib/calculator.rb
210210
class Calculator
211-
def add(a,b)
212-
a + b
211+
def add(a, b)
213212
end
214213
end
215214
```
@@ -222,6 +221,39 @@ Be sure to require the implementation file in the spec:
222221
require "calculator"
223222
```
224223

224+
Now run the spec again, and watch the expectation fail:
225+
226+
```
227+
$ rspec spec/calculator_spec.rb
228+
F
229+
230+
Failures:
231+
232+
1) Calculator#add returns the sum of its arguments
233+
Failure/Error: expect(Calculator.new.add(1, 2)).to eq(3)
234+
235+
expected: 3
236+
got: nil
237+
238+
(compared using ==)
239+
# ./spec/calcalator_spec.rb:6:in `block (3 levels) in <top (required)>'
240+
241+
Finished in 0.00131 seconds (files took 0.10968 seconds to load)
242+
1 example, 1 failure
243+
244+
Failed examples:
245+
246+
rspec ./spec/calcalator_spec.rb:5 # Calculator#add returns the sum of its arguments
247+
```
248+
249+
Implement the simplest solution, by changing the definition of `Calculator#add` to:
250+
251+
```ruby
252+
def add(a, b)
253+
a + b
254+
end
255+
```
256+
225257
Now run the spec again, and watch it pass:
226258

227259
```

0 commit comments

Comments
 (0)