rspec 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -5
- data/Rakefile +35 -29
- data/bin/spec +0 -5
- data/doc/README +5 -0
- data/doc/config.yaml +2 -0
- data/doc/plugin/syntax.rb +38 -0
- data/doc/reference/rspec reference.page +0 -0
- data/doc/src/community.page +8 -0
- data/doc/src/default.css +198 -0
- data/doc/src/default.template +34 -0
- data/doc/src/documentation/api.page +251 -0
- data/doc/src/documentation/index.page +8 -0
- data/doc/src/documentation/mocks.page +207 -0
- data/doc/src/documentation/specs.page +20 -0
- data/doc/src/download.page +8 -0
- data/doc/src/examples.page +9 -0
- data/doc/src/images/ul.gif +0 -0
- data/doc/src/index.page +8 -0
- data/doc/src/tools/index.page +8 -0
- data/doc/src/tools/rails.page +8 -0
- data/doc/src/tools/rake.page +8 -0
- data/doc/src/tools/rcov.page +8 -0
- data/doc/src/tools/spec_runner.page +8 -0
- data/doc/src/tools/specdoc.page +8 -0
- data/doc/src/tools/test2rspec.page +8 -0
- data/doc/src/ul.gif +0 -0
- data/doc/src/why_rspec.page +8 -0
- data/examples/mocking_spec.rb +2 -2
- data/examples/spec_framework_spec.rb +4 -4
- data/lib/spec/api/helper/have_helper.rb +55 -55
- data/lib/spec/api/mock.rb +111 -38
- data/lib/spec/runner/backtrace_tweaker.rb +4 -4
- data/lib/spec/runner/context.rb +2 -1
- data/lib/spec/runner/context_runner.rb +3 -3
- data/lib/spec/runner/option_parser.rb +8 -4
- data/lib/spec/runner/simple_text_reporter.rb +29 -19
- data/lib/spec/runner/specification.rb +2 -1
- data/lib/spec/version.rb +1 -1
- data/test/rake/rcov_testtask.rb +45 -0
- data/test/spec/api/helper/arbitrary_predicate_test.rb +39 -24
- data/test/spec/api/helper/equality_test.rb +19 -0
- data/test/spec/api/helper/should_have_test.rb +183 -0
- data/test/spec/api/mock_arg_constraints_test.rb +90 -0
- data/test/spec/api/mock_test.rb +101 -21
- data/test/spec/runner/context_runner_test.rb +3 -3
- data/test/spec/runner/context_test.rb +2 -5
- data/test/spec/runner/execution_context_test.rb +1 -1
- data/test/spec/runner/option_parser_test.rb +16 -8
- data/test/spec/runner/simple_text_reporter_test.rb +57 -33
- data/test/spec/runner/specification_test.rb +7 -7
- data/test/spec/tool/command_line_test.rb +4 -4
- data/test/test_helper.rb +2 -2
- metadata +37 -8
- data/README +0 -38
- data/TODO +0 -9
- data/TUTORIAL +0 -259
- data/WHY_RSPEC +0 -115
@@ -12,35 +12,35 @@ module Spec
|
|
12
12
|
self.should.not.be.instance_of Specification
|
13
13
|
self.should.be.instance_of ExecutionContext
|
14
14
|
end
|
15
|
-
@reporter.
|
15
|
+
@reporter.should.receive(:add_spec).with "should pass", :anything, []
|
16
16
|
spec.run @reporter
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_should_add_itself_to_reporter_when_passes
|
20
20
|
spec = Specification.new("spec") {}
|
21
|
-
@reporter.
|
21
|
+
@reporter.should.receive(:add_spec).with "spec", :anything, []
|
22
22
|
spec.run(@reporter)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_should_add_itself_to_reporter_when_fails
|
26
26
|
error = RuntimeError.new
|
27
27
|
spec = Specification.new("spec") { raise error }
|
28
|
-
@reporter.
|
28
|
+
@reporter.should.receive(:add_spec).with "spec", :anything, [error]
|
29
29
|
spec.run(@reporter)
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_should_add_itself_to_reporter_when_calling_run_docs
|
33
33
|
spec = Specification.new("spec") {}
|
34
|
-
@reporter.
|
34
|
+
@reporter.should.receive(:add_spec).with "spec"
|
35
35
|
spec.run_docs(@reporter)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_should_verify_mocks_after_teardown
|
39
39
|
spec = Specification.new("spec") do
|
40
40
|
mock = mock("a mock")
|
41
|
-
mock.
|
41
|
+
mock.should.receive(:poke)
|
42
42
|
end
|
43
|
-
@reporter.
|
43
|
+
@reporter.should.receive(:add_spec) do |spec_name, calling_line, errors|
|
44
44
|
spec_name.should.equal "spec"
|
45
45
|
errors[0].message.should.match /expected poke once, but received it 0 times/
|
46
46
|
end
|
@@ -54,7 +54,7 @@ module Spec
|
|
54
54
|
teardown = lambda do
|
55
55
|
raise "in teardown"
|
56
56
|
end
|
57
|
-
@reporter.
|
57
|
+
@reporter.should.receive(:add_spec) do |spec, calling_line, errors|
|
58
58
|
errors.length.should.equal 2
|
59
59
|
errors[0].message.should.equal "in body"
|
60
60
|
errors[1].message.should.equal "in teardown"
|
@@ -8,10 +8,10 @@ module Spec
|
|
8
8
|
def test_writes_translated_file
|
9
9
|
translator = Api::Mock.new "translator"
|
10
10
|
filesystem = Api::Mock.new "filesystem"
|
11
|
-
filesystem.
|
12
|
-
filesystem.
|
13
|
-
filesystem.
|
14
|
-
filesystem.
|
11
|
+
filesystem.should.receive(:write_translation).with "./test/spec/tool/test_unit_translator_test.rb", "spec/test_unit_translator_test.rb"
|
12
|
+
filesystem.should.receive(:write_translation).with "./test/spec/tool/test_unit_api_test.rb", "spec/test_unit_api_test.rb"
|
13
|
+
filesystem.should.receive(:write_translation).with "./test/spec/tool/test_unit_api_spec.rb", "spec/test_unit_api_spec.rb"
|
14
|
+
filesystem.should.receive(:write_translation).with "./test/spec/tool/command_line_test.rb", "spec/command_line_test.rb"
|
15
15
|
|
16
16
|
cl = CommandLine.new(filesystem)
|
17
17
|
out = StringIO.new
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,6 @@ $LOAD_PATH.push File.dirname(__FILE__) + '/../lib'
|
|
3
3
|
$LOAD_PATH.push File.dirname(__FILE__) + '/../test'
|
4
4
|
require 'spec'
|
5
5
|
mock_context_runner = Spec::Api::Mock.new "mock_context_runner"
|
6
|
-
mock_context_runner.
|
7
|
-
mock_context_runner.
|
6
|
+
mock_context_runner.should. receive(:add_context).any.number.of.times
|
7
|
+
mock_context_runner.should.receive(:run).any.number.of.times
|
8
8
|
Spec::Runner::Context.context_runner = mock_context_runner
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rspec
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2006-04-
|
6
|
+
version: 0.5.1
|
7
|
+
date: 2006-04-08 00:00:00 -05:00
|
8
8
|
summary: Behaviour Specification Framework for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,10 +30,6 @@ authors:
|
|
30
30
|
files:
|
31
31
|
- CHANGES
|
32
32
|
- Rakefile
|
33
|
-
- README
|
34
|
-
- TODO
|
35
|
-
- TUTORIAL
|
36
|
-
- WHY_RSPEC
|
37
33
|
- lib/spec.rb
|
38
34
|
- lib/spec/api.rb
|
39
35
|
- lib/spec/runner.rb
|
@@ -66,6 +62,8 @@ files:
|
|
66
62
|
- lib/spec/tool/command_line.rb
|
67
63
|
- lib/spec/tool/test_unit_translator.rb
|
68
64
|
- test/test_helper.rb
|
65
|
+
- test/rake/rcov_testtask.rb
|
66
|
+
- test/spec/api/mock_arg_constraints_test.rb
|
69
67
|
- test/spec/api/mock_test.rb
|
70
68
|
- test/spec/api/helper/arbitrary_predicate_test.rb
|
71
69
|
- test/spec/api/helper/containment_test.rb
|
@@ -73,6 +71,7 @@ files:
|
|
73
71
|
- test/spec/api/helper/identity_test.rb
|
74
72
|
- test/spec/api/helper/raising_test.rb
|
75
73
|
- test/spec/api/helper/regex_matching_test.rb
|
74
|
+
- test/spec/api/helper/should_have_test.rb
|
76
75
|
- test/spec/api/helper/should_satisfy_test.rb
|
77
76
|
- test/spec/api/helper/throwing_test.rb
|
78
77
|
- test/spec/api/helper/true_false_special_case_test.rb
|
@@ -94,6 +93,38 @@ files:
|
|
94
93
|
- examples/spec_framework_spec.rb
|
95
94
|
- examples/stack.rb
|
96
95
|
- examples/stack_spec.rb
|
96
|
+
- doc/config.yaml
|
97
|
+
- doc/output
|
98
|
+
- doc/plugin
|
99
|
+
- doc/README
|
100
|
+
- doc/reference
|
101
|
+
- doc/src
|
102
|
+
- doc/output/rdoc
|
103
|
+
- doc/plugin/syntax.rb
|
104
|
+
- doc/reference/rspec reference.page
|
105
|
+
- doc/src/community.page
|
106
|
+
- doc/src/default.css
|
107
|
+
- doc/src/default.template
|
108
|
+
- doc/src/documentation
|
109
|
+
- doc/src/download.page
|
110
|
+
- doc/src/examples.page
|
111
|
+
- doc/src/images
|
112
|
+
- doc/src/index.page
|
113
|
+
- doc/src/tools
|
114
|
+
- doc/src/ul.gif
|
115
|
+
- doc/src/why_rspec.page
|
116
|
+
- doc/src/documentation/api.page
|
117
|
+
- doc/src/documentation/index.page
|
118
|
+
- doc/src/documentation/mocks.page
|
119
|
+
- doc/src/documentation/specs.page
|
120
|
+
- doc/src/images/ul.gif
|
121
|
+
- doc/src/tools/index.page
|
122
|
+
- doc/src/tools/rails.page
|
123
|
+
- doc/src/tools/rake.page
|
124
|
+
- doc/src/tools/rcov.page
|
125
|
+
- doc/src/tools/spec_runner.page
|
126
|
+
- doc/src/tools/specdoc.page
|
127
|
+
- doc/src/tools/test2rspec.page
|
97
128
|
test_files: []
|
98
129
|
|
99
130
|
rdoc_options:
|
@@ -103,9 +134,7 @@ rdoc_options:
|
|
103
134
|
- README
|
104
135
|
- --line-numbers
|
105
136
|
extra_rdoc_files:
|
106
|
-
- README
|
107
137
|
- CHANGES
|
108
|
-
- TUTORIAL
|
109
138
|
executables:
|
110
139
|
- spec
|
111
140
|
- test2rspec
|
data/README
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
= RSpec - Behaviour Specification Framework for Ruby
|
2
|
-
|
3
|
-
RSpec is a behaviour specification framework for Ruby. RSpec was created in response to Dave Astels' article _A New Look at Test Driven Development_ which can be read at: http://daveastels.com/index.php?p=5 RSpec is intended to provide the features discussed in Dave's article.
|
4
|
-
|
5
|
-
RSpec is primarily developed by Steven Baker <srbaker@pobox.com>, and was inspired by and contributed to by Dave Astels. Special thanks also to Aslak Hellesoy for many significant contributions.
|
6
|
-
|
7
|
-
RSpec's included mocking framework is based on SchMock by Ben Griffiths. SchMock can be found at http://rubyforge.org/projects/schmock/.
|
8
|
-
|
9
|
-
== Download/Installation
|
10
|
-
|
11
|
-
=== Using RubyGems
|
12
|
-
|
13
|
-
$ sudo gem install rspec
|
14
|
-
|
15
|
-
=== Getting the latest sources
|
16
|
-
|
17
|
-
RSpec was previously hosted under the Monotone distributed version control system. Due to the increasing popularity of RSpec, and the fact that a large part of the world hasn't yet discovered how wonderful Monotone is, we have succumbed to peer pressure and moved the repository to Subversion.
|
18
|
-
|
19
|
-
RSpec is hosted on RubyForge. It can be checked out of Subversion from: svn://rubyforge.org//var/svn/rspec
|
20
|
-
|
21
|
-
== Creating a Gem
|
22
|
-
|
23
|
-
If you have checked out the sources from version control, you can create a Gem from the checked out version with the 'gem' rake task, like so:
|
24
|
-
|
25
|
-
$ rake gem
|
26
|
-
|
27
|
-
This will create a gem in the pkg/ subdirectory. To install the created gem, simply run 'gem install' as root (preferably using sudo(1)):
|
28
|
-
|
29
|
-
$ sudo gem install pkg/rspec_x.y.z.gem
|
30
|
-
|
31
|
-
Please visit the RSpec web site periodically, it will be updated with more information as it is made available including documentation, mailing lists, bug tracking, and more. Special thanks to RubyForge for hosting the project site.
|
32
|
-
|
33
|
-
== Usage
|
34
|
-
|
35
|
-
This will also install a new executable for you, 'spec'. Now you can
|
36
|
-
|
37
|
-
spec movie_spec.rb
|
38
|
-
spec *_spec.rb
|
data/TODO
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
- Rakefile should have an install target.
|
2
|
-
- Spec CLI needs to have a way to specify a runner.
|
3
|
-
- Rake tasks for spec running (see TestTask).
|
4
|
-
- Write specifications for the spec CLI.
|
5
|
-
- Avoid using both the 'rspec' and 'spec' names in sources and doco. It's confusing. Consider how to align with Dan North's JBehave effort in terms of name and vocabulary (AH).
|
6
|
-
- Decide whether mocks should expect messages in a particular order or not. -Or make it configurable. Ex: mock("foo", :order => "strict") (AH).
|
7
|
-
- Do we want to use an issue tracker? The one at RubyForge maybe?
|
8
|
-
- Create first class result objects instead of just Strings. This can be used to generate XML/YAML reports
|
9
|
-
which in turn can be transformed to e.g. HTML reports.
|
data/TUTORIAL
DELETED
@@ -1,259 +0,0 @@
|
|
1
|
-
= Getting Started with RSpec
|
2
|
-
|
3
|
-
RSpec is a behaviour specification framework for the Ruby Programming
|
4
|
-
Language. More information on the Ruby Programming Language can be found at
|
5
|
-
http://www.ruby-lang.org/. For more information on Behaviour Driven
|
6
|
-
Development, please see _A New Look at Test Driven Development_ which can be
|
7
|
-
found at http://www.daveastels.com/index.php?p=5.
|
8
|
-
|
9
|
-
This document is intended to help those interested in getting started with
|
10
|
-
Behaviour Driven Development using the RSpec behaviour specification
|
11
|
-
framework. Please send comments and/or corrections to me via email: srbaker at
|
12
|
-
pobox dot com.
|
13
|
-
|
14
|
-
== Installation
|
15
|
-
|
16
|
-
The first thing you need to do to start specifying your software is to install
|
17
|
-
RSpec. Thanks to the work on the Gem packaging of RSpec by Aslak Hellesoy, you
|
18
|
-
can install RSpec via RubyGems by issuing the following command:
|
19
|
-
|
20
|
-
$ gem install rspec
|
21
|
-
|
22
|
-
If you do not have RubyGems installed, see http://docs.rubygems.org/ for
|
23
|
-
information about RubyGems including how to install it.
|
24
|
-
|
25
|
-
== Usage
|
26
|
-
|
27
|
-
Once you have RSpec installed, ensure that it is correctly installed by
|
28
|
-
running the spec command from the command line without arguments. You should
|
29
|
-
get something like the following output:
|
30
|
-
|
31
|
-
Finished in 0.002726 seconds
|
32
|
-
|
33
|
-
0 specifications, 0 expectations, 0 failures
|
34
|
-
|
35
|
-
If you get this output, you can be sure that RSpec has been installed and is
|
36
|
-
ready for use!
|
37
|
-
|
38
|
-
= Specification Anatomy
|
39
|
-
|
40
|
-
== Expectations
|
41
|
-
|
42
|
-
The simplest part of your set of specifications will be an expectation. An
|
43
|
-
expectation tells RSpec what the expected result of a piece code is. Your set
|
44
|
-
of specifications is simply a collection of expectations about how your code
|
45
|
-
should behave.
|
46
|
-
|
47
|
-
In RSpec, the expectations are methods that are available on every object in
|
48
|
-
the system. If I want to set an expectation that the value of 1 is 1, I would
|
49
|
-
write:
|
50
|
-
|
51
|
-
1.should_equal 1
|
52
|
-
|
53
|
-
And to set the expectation that 1 + 1 should be equal to 2, I would write the
|
54
|
-
following code:
|
55
|
-
|
56
|
-
(1 + 1).should_equal 2
|
57
|
-
|
58
|
-
There are many available expectation methods, and they can be found by looking
|
59
|
-
in the API documentation for RSpec. For most, if not all, of the expections
|
60
|
-
the negation is also provided. Thus, to ensure that subtracting 1 from 2 does
|
61
|
-
not equal 2, write the following:
|
62
|
-
|
63
|
-
(2 - 1).should_not_equal 2
|
64
|
-
|
65
|
-
These examples are extremely simple, but they accurately convey the simplicity
|
66
|
-
with which expectations can be written. When specifying your software, you are
|
67
|
-
simply writing expectations that specify how your software will behave. The
|
68
|
-
rest of the constructs in RSpec exist entirely to help you organize your
|
69
|
-
expectations, and to provide accurate and helpful reporting when these
|
70
|
-
expectations are not met.
|
71
|
-
|
72
|
-
Eventually, writing expectations for addition and subtraction of numbers will
|
73
|
-
get boring. When that happens, you can start writing expectations for your own
|
74
|
-
code. Let's try a slightly more involved example.
|
75
|
-
|
76
|
-
We have been asked to write a robot which will start at a given X, Y
|
77
|
-
coordinate, and will move in for directions a given number of units. If no
|
78
|
-
starting coordinate is given, the robot will start at 0,0. When the robot is
|
79
|
-
moved, a two-element array should be returned with the x and y coordinates.
|
80
|
-
Some expectations you might write for this robot might be the following:
|
81
|
-
|
82
|
-
rob = Robot.new
|
83
|
-
|
84
|
-
rob.should_not_be_nil
|
85
|
-
rob.should_be_kind_of Robot
|
86
|
-
rob.x_coordinate.should_equal 0
|
87
|
-
rob.y_coordinate.should_equal 0
|
88
|
-
rob.location.should_equal [0,0]
|
89
|
-
|
90
|
-
rob.move_north(1).should_equal [0, 1]
|
91
|
-
rob.move_south(5).should_equal [0, -4]
|
92
|
-
rob.move_east(10).should_equal [10, -4]
|
93
|
-
rob.move_west(5).should_equal [5, -4]
|
94
|
-
|
95
|
-
The code example above isn't intended to demonstrate good design, but has been
|
96
|
-
created explicitly to demonstrate the use of the expectation methods.
|
97
|
-
|
98
|
-
Also note that these expectations would be written iteratively, but the
|
99
|
-
purpose of this document is to serve as an introduction to the RSpec
|
100
|
-
framework, not to Behaviour Driven Development itself.
|
101
|
-
|
102
|
-
As you can see, writing expectations can be rather verbose, even for a simple
|
103
|
-
project like the example above. For clarity, your expectations will be grouped
|
104
|
-
into specifications, which are described in the next section.
|
105
|
-
|
106
|
-
== Specifications
|
107
|
-
|
108
|
-
Your software will be specified by writing expectations, which were explained
|
109
|
-
in the previous section. Your expectations will be grouped into specifications
|
110
|
-
for clarity. A specification is simply a method that contains expectations.
|
111
|
-
The name of your specification will be used by the Spec Runner (see Running
|
112
|
-
and Reporting) to inform you of unmet expectations, so choose your names
|
113
|
-
wisely.
|
114
|
-
|
115
|
-
Consider the robot example from the previous example, but divided into
|
116
|
-
specification methods:
|
117
|
-
|
118
|
-
def initialization_without_coordinates
|
119
|
-
rob = Robot.new
|
120
|
-
rob.x_coordinate.should_equal 0
|
121
|
-
rob.y_coordinate.should_equal 0
|
122
|
-
rob.location.should_equal [0,0]
|
123
|
-
end
|
124
|
-
|
125
|
-
def initialization_with_coordinates
|
126
|
-
rob = Robot.new(10, 15)
|
127
|
-
rob.x_coordinate.should_equal 10
|
128
|
-
rob.y_coordinate.should_equal 15
|
129
|
-
rob.location.should_equal [10, 15]
|
130
|
-
end
|
131
|
-
|
132
|
-
def north_movement
|
133
|
-
rob = Robot.new
|
134
|
-
rob.move_north(1).should_equal [0, 1]
|
135
|
-
end
|
136
|
-
|
137
|
-
def west_movement
|
138
|
-
rob = Robot.new(10, 5)
|
139
|
-
rob.move_west(15).should_equal [-5, 5]
|
140
|
-
end
|
141
|
-
|
142
|
-
By dividing expectations into specification methods, our specifications for
|
143
|
-
the behaviour of our software are far easier to read and clearly express the
|
144
|
-
intent. Even those who are unfamiliar with Ruby specifically (and perhaps even
|
145
|
-
some who are relatively unfamiliar with software development in general) can
|
146
|
-
easily read our specifications.
|
147
|
-
|
148
|
-
== Contexts
|
149
|
-
|
150
|
-
As you can see, there is some duplicated code in the example from the last
|
151
|
-
section in the creation of the Robot objects. You will find that the
|
152
|
-
initialization of objects will often be duplicated when writing
|
153
|
-
specifications.
|
154
|
-
|
155
|
-
RSpec provides you with a way of setting up this data ahead of time, by
|
156
|
-
providing two methods: setup and teardown.
|
157
|
-
|
158
|
-
The setup method is called before invoking each specification to allow you to
|
159
|
-
set up resources which are required for each specification, and the teardown
|
160
|
-
method is called after invoking each specification, to allow you to
|
161
|
-
appropriately deallocate or close resources which were required for the
|
162
|
-
specifications.
|
163
|
-
|
164
|
-
The specifications described in the Specifications example are absolutely
|
165
|
-
useless if they're not placed in a context. Because you will be writing a
|
166
|
-
large number of specifications for your software, you will want a way to
|
167
|
-
divide them into logical groups. Specification methods are grouped within
|
168
|
-
subclasses of Context. You can define as many contexts as you wish, and you
|
169
|
-
are encouraged to divide your software into many well-defined contexts.
|
170
|
-
|
171
|
-
The following Context is a complete specification for the movement of the
|
172
|
-
robot, and if it were run, would produce useful output.
|
173
|
-
|
174
|
-
require 'spec'
|
175
|
-
class RobotMovement < Spec::Context
|
176
|
-
def setup
|
177
|
-
@rob = Robot.new
|
178
|
-
@rob1 = Robot.new(10, 15)
|
179
|
-
end
|
180
|
-
|
181
|
-
def movement
|
182
|
-
@rob.move_north(1).should_equal [0, 1]
|
183
|
-
@rob1.move_west(15).should_equal [-5, 5]
|
184
|
-
end
|
185
|
-
|
186
|
-
def teardown
|
187
|
-
@rob.die
|
188
|
-
@rob1.die
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
=== Specification Naming
|
193
|
-
|
194
|
-
RSpec does not require the use of a specific naming scheme for specifications.
|
195
|
-
When a context is run, all of the public methods which you define in the
|
196
|
-
context will be executed. The only exceptions are currently methods which are
|
197
|
-
used internally by RSpec. The forbidden names are initialize, mock, violated,
|
198
|
-
and run. Because of Ruby's dynamic nature, you will not see a warning if you
|
199
|
-
override any of these methods, and unexpected behaviour may ensue.
|
200
|
-
|
201
|
-
In addition to the four aforementioned forbidden specification method names,
|
202
|
-
methods named with a leading underscore will also not be run as
|
203
|
-
specifications. This allows you a way to define methods for your own use
|
204
|
-
within the Context and not have them run as specifications.
|
205
|
-
|
206
|
-
== Running and Reporting
|
207
|
-
|
208
|
-
There currently exists a command-line runner for RSpec, called 'spec'. If you
|
209
|
-
write specifications and pass them to the runner on the command line, your
|
210
|
-
specifications will run and tell you where you have errors. You are encouraged
|
211
|
-
to try out the command line runner, first with the provided examples, and then
|
212
|
-
by writing your own specifications.
|
213
|
-
|
214
|
-
As an example of the output, if you run the movie_spec.rb file from the RSpec
|
215
|
-
examples, you will get the following output:
|
216
|
-
|
217
|
-
$ spec movie_spec.rb
|
218
|
-
....
|
219
|
-
Finished in 0.016 seconds.
|
220
|
-
|
221
|
-
4 specifications, 4 expectations, 0 failures.
|
222
|
-
|
223
|
-
The spec runner counts the specification as it executes them by printing a
|
224
|
-
single dot (.) to the screen. It indicates a failure with an X. For every
|
225
|
-
failure, the specification runner will provide a backtrace indicating where
|
226
|
-
the failure occurred. A failure is basically a raised exception. Either an
|
227
|
-
exception raised by the software you're specifying, by Ruby itself (such as
|
228
|
-
SyntaxError or RuntimeError), or it will be an unmet expectation
|
229
|
-
(ExpectationNotMet).
|
230
|
-
|
231
|
-
For instance, if you expect "Space Balls" to be in OneMovieList which actually
|
232
|
-
includes "Star Wars", you will get the following error:
|
233
|
-
|
234
|
-
$ spec movie_spec.rb
|
235
|
-
X...
|
236
|
-
|
237
|
-
1)
|
238
|
-
<#<MovieList:0x284c1e0 @movies={"Star Wars"=>#<Movie:0x284c180 @name="Star Wars"
|
239
|
-
>}>> should include <"Space Balls"> (Spec::Api::ExpectationNotMetError)
|
240
|
-
./movie_spec.rb:34:in `should_include_space_balls'
|
241
|
-
../bin/spec:10
|
242
|
-
|
243
|
-
Finished in 0.016 seconds
|
244
|
-
|
245
|
-
4 specifications, 4 expectations, 1 failures
|
246
|
-
|
247
|
-
This informs you that the MovieList object should include "Space Balls", but
|
248
|
-
got an ExpectationNotMet error. The backtrace also informs you that the unmet
|
249
|
-
expectation can be found in the file 'movie_spec.rb' on line 34, in the
|
250
|
-
`should_include_space_balls' method.
|
251
|
-
|
252
|
-
== Conclusion
|
253
|
-
|
254
|
-
This document was by no means intended to provide an exhaustive overview of
|
255
|
-
Behaviour Driven Development in general, or RSpec specifically. It is intended
|
256
|
-
as a tutorial to get you started with specifying the behaviour of your
|
257
|
-
software with RSpec. More information can be found in the API documentation of
|
258
|
-
RSpec itself. Further documentation on BDD, and RSpec is on the way.
|
259
|
-
|