forked from rspec/rspec.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.page
133 lines (101 loc) · 3.52 KB
/
index.page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
title: home
order: 1
filter:
- erb
- textile
---
h2. Overview
RSpec is a testing tool for the Ruby programming language. Born under the banner of Behaviour-Driven Development, it is designed to make Test-Driven Development a productive and enjoyable experience with features like:
* a rich command line program (the rspec command)
* textual descriptions of examples and groups ("rspec-core":http://rubydoc.info/gems/rspec-core/frames)
* flexible and customizable reporting
* extensible expectation language ("rspec-expectations":http://rubydoc.info/gems/rspec-expectations/frames)
* built-in mocking/stubbing framework ("rspec-mocks":http://rubydoc.info/gems/rspec-mocks/frames)
h2. Documentation
RDoc
* "http://rubydoc.info/gems/rspec-core":http://rubydoc.info/gems/rspec-core/frames
* "http://rubydoc.info/gems/rspec-expectations":http://rubydoc.info/gems/rspec-expectations/frames
* "http://rubydoc.info/gems/rspec-mocks":http://rubydoc.info/gems/rspec-mocks/frames
* "http://rubydoc.info/gems/rspec-rails":http://rubydoc.info/gems/rspec-rails/frames
Cucumber Features
* "http://relishapp.com/rspec":http://relishapp.com/rspec
RSpec-1.x
* "http://old.rspec.info":http://old.rspec.info
h2. RSpec source
* "https://github.com/rspec":https://github.com/rspec
* "https://github.com/rspec/rspec-core":https://github.com/rspec/rspec-core
* "https://github.com/rspec/rspec-expectations":https://github.com/rspec/rspec-expectations
* "https://github.com/rspec/rspec-mocks":https://github.com/rspec/rspec-mocks
h2. The RSpec Book
<div style="float:right">
<a target="_blank" href="http://www.pragprog.com/titles/achbd/the-rspec-book">
<img width="190" height="228" border="0" title="The RSpec Book" alt="The RSpec Book" src="http://imagery.pragprog.com/products/140/achbd_xlargecover.jpg"/>
</a>
</div>
The RSpec Book will introduce you to RSpec, Cucumber, and a number of other tools that make up the Ruby BDD family. Replete with tutorials and practical examples, the RSpec Book will help you get your BDD on, taking you from executable requirements to working software that is clean, well tested, well documented, flexible and highly maintainable.
h2. Get Started Now
<pre>
$ gem install rspec
</pre>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<p>
Start with a very simple example that expresses
some basic desired behaviour.
</p>
<% coderay(:language => 'ruby') do -%>
# bowling_spec.rb
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should eq(0)
end
end
<% end -%>
<p>
Run the example and watch it fail.
</p>
<pre style="color:red;">
$ rspec bowling_spec.rb
./bowling_spec.rb:4:
uninitialized constant Bowling
</pre>
</td>
<td width="50%">
<p>
Now write
just enough code to make it pass.
</p>
<% coderay do -%>
# bowling.rb
class Bowling
def hit(pins)
end
def score
0
end
end
<% end -%>
<p>
Run the example and bask in the joy that is green.
</p>
<pre style="color:green;">
$ rspec bowling_spec.rb --format nested
Bowling#score
returns 0 for all gutter game
Finished in 0.007534 seconds
1 example, 0 failures
</pre>
</td>
</tr>
</table>
h2. Take very small steps
Don't rush ahead with more code. Instead, add another example and let it guide you to what you have to do next. And don't forget to take time to refactor your code before it gets messy. You should keep your code clean at every step of the way.
h2. Take the first step now!
<pre>
gem install rspec
</pre>