Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 85 lines (57 sloc) 2.109 kB
f1a8e72 @dchelimsky update README
dchelimsky authored
1 # Rspec Core
7b8b714 @spicycode Version bump to 0.0.0
spicycode authored
2
d81c090 @dchelimsky words
dchelimsky authored
3 Rspec is an automated testing framework for Ruby, designed for use in Behaviour
4 Driven Development and Test Driven Development.
5c8d5ec @dchelimsky update readme
dchelimsky authored
5
d81c090 @dchelimsky words
dchelimsky authored
6 rspec-core includes the Rspec runner, output formatters, and the `rspec`
7 command.
5c8d5ec @dchelimsky update readme
dchelimsky authored
8
fada219 @dchelimsky words
dchelimsky authored
9 ## Install
10
11 [sudo] gem install rspec --prerelease
12
d81c090 @dchelimsky words
dchelimsky authored
13 This will install the rspec, rspec-core, rspec-expectations and rspec-mocks
14 gems.
71d3926 @dchelimsky words
dchelimsky authored
15
f1a8e72 @dchelimsky update README
dchelimsky authored
16 ## Get Started
71d3926 @dchelimsky words
dchelimsky authored
17
f1a8e72 @dchelimsky update README
dchelimsky authored
18 Start with a simple example of behavior you expect from your system. Do
19 this before you write any code:
71d3926 @dchelimsky words
dchelimsky authored
20
f1a8e72 @dchelimsky update README
dchelimsky authored
21 # in spec/calculator_spec.rb
22 describe Calculator, "add" do
23 it "returns the sum of its arguments" do
24 Calculator.new.add(1, 2).should eq(3)
71d3926 @dchelimsky words
dchelimsky authored
25 end
26 end
27
f1a8e72 @dchelimsky update README
dchelimsky authored
28 Run this with the rspec command, and watch it fail:
71d3926 @dchelimsky words
dchelimsky authored
29
f1a8e72 @dchelimsky update README
dchelimsky authored
30 $ rspec spec/calculator_spec.rb
31 ./spec/calculator_spec.rb:1: uninitialized constant Calculator
71d3926 @dchelimsky words
dchelimsky authored
32
f1a8e72 @dchelimsky update README
dchelimsky authored
33 Implement the simplest solution:
71d3926 @dchelimsky words
dchelimsky authored
34
f1a8e72 @dchelimsky update README
dchelimsky authored
35 # in lib/calculator.rb
36 class Calculator
37 def add(a,b)
38 a + b
71d3926 @dchelimsky words
dchelimsky authored
39 end
40 end
fada219 @dchelimsky words
dchelimsky authored
41
f1a8e72 @dchelimsky update README
dchelimsky authored
42 Be sure to require the implementation file in the spec:
43
44 # in spec/calculator_spec.rb
45 # - Rspec adds ./lib to the $LOAD_PATH, so you can
46 # just require "calculator" directly
47 require "calculator"
48
49 Now run the spec again, and watch it pass:
50
51 $ rspec spec/calculator_spec.rb
52 .
53
54 Finished in 0.000315 seconds
55 1 example, 0 failures
56
57 Use the documentation formatter to see the resulting spec:
58
59 $ rspec spec/calculator_spec.rb --format doc
60 Calculator add
61 returns the sum of its arguments
62
63 Finished in 0.000379 seconds
64 1 example, 0 failures
65
beaf23b @dchelimsky .rspec (instead of .rspecrc)
dchelimsky authored
66 ## Configuration
67
68 You can define runtime configuration options in four places. They
69 are loaded and processed in this order:
70
71 * ~/.rspec
72 * .rspec
73 * RSpec.configure
74 * command line
75
76 Run `rspec --help` to see supported configuration options.
77
fada219 @dchelimsky words
dchelimsky authored
78 #### Also see
79
80 * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
81 * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
82 * [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
83 * [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)
84
Something went wrong with that request. Please try again.