rspec 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +7 -12
- data/Rakefile +17 -12
- data/TUTORIAL +1 -1
- data/WHY_RSPEC +115 -0
- data/bin/spec +17 -4
- data/bin/test2rspec +35 -0
- data/examples/airport_spec.rb +35 -0
- data/examples/mocking_spec.rb +16 -0
- data/examples/spec_framework_spec.rb +28 -0
- data/examples/stack.rb +36 -0
- data/examples/stack_spec.rb +112 -0
- data/lib/spec.rb +5 -18
- data/lib/spec/api.rb +4 -0
- data/lib/spec/{exceptions.rb → api/exceptions.rb} +1 -1
- data/lib/spec/{expectations.rb → api/expectations.rb} +5 -4
- data/lib/spec/api/helper.rb +10 -0
- data/lib/spec/{have_helper.rb → api/helper/have_helper.rb} +1 -1
- data/lib/spec/{instance_helper.rb → api/helper/instance_helper.rb} +0 -0
- data/lib/spec/{instance_negator.rb → api/helper/instance_negator.rb} +0 -0
- data/lib/spec/{kind_helper.rb → api/helper/kind_helper.rb} +0 -0
- data/lib/spec/{kind_negator.rb → api/helper/kind_negator.rb} +0 -0
- data/lib/spec/{respond_helper.rb → api/helper/respond_helper.rb} +0 -0
- data/lib/spec/{respond_negator.rb → api/helper/respond_negator.rb} +0 -0
- data/lib/spec/{should_base.rb → api/helper/should_base.rb} +6 -4
- data/lib/spec/{should_helper.rb → api/helper/should_helper.rb} +12 -0
- data/lib/spec/{should_negator.rb → api/helper/should_negator.rb} +11 -0
- data/lib/spec/api/mock.rb +184 -0
- data/lib/spec/rake/spectask.rb +153 -0
- data/lib/spec/runner.rb +9 -0
- data/lib/spec/runner/backtrace_tweaker.rb +17 -0
- data/lib/spec/runner/context.rb +47 -0
- data/lib/spec/runner/context_runner.rb +52 -0
- data/lib/spec/runner/execution_context.rb +15 -0
- data/lib/spec/runner/instance_exec.rb +15 -0
- data/lib/spec/runner/kernel_ext.rb +6 -0
- data/lib/spec/runner/option_parser.rb +41 -0
- data/lib/spec/runner/rdoc_formatter.rb +17 -0
- data/lib/spec/runner/simple_text_reporter.rb +92 -0
- data/lib/spec/runner/specification.rb +42 -0
- data/lib/spec/tool/command_line.rb +39 -0
- data/lib/spec/tool/test_unit_translator.rb +112 -0
- data/lib/spec/version.rb +13 -0
- data/test/spec/api/helper/arbitrary_predicate_test.rb +121 -0
- data/test/spec/api/helper/containment_test.rb +117 -0
- data/test/spec/api/helper/equality_test.rb +46 -0
- data/test/spec/api/helper/identity_test.rb +68 -0
- data/test/spec/api/helper/raising_test.rb +50 -0
- data/test/spec/api/helper/regex_matching_test.rb +38 -0
- data/test/spec/api/helper/should_satisfy_test.rb +37 -0
- data/test/spec/api/helper/throwing_test.rb +56 -0
- data/test/spec/api/helper/true_false_special_case_test.rb +87 -0
- data/test/spec/api/helper/typing_test.rb +107 -0
- data/test/spec/api/mock_test.rb +161 -0
- data/test/spec/runner/backtrace_tweaker_test.rb +20 -0
- data/test/spec/runner/context_runner_test.rb +19 -0
- data/test/spec/runner/context_test.rb +29 -0
- data/test/spec/runner/execution_context_test.rb +13 -0
- data/test/spec/runner/option_parser_test.rb +50 -0
- data/test/spec/runner/rdoc_formatter_test.rb +23 -0
- data/test/spec/runner/simple_text_reporter_test.rb +128 -0
- data/test/spec/runner/specification_test.rb +70 -0
- data/test/spec/tool/command_line_test.rb +22 -0
- data/test/spec/tool/test_unit_api_spec.rb +61 -0
- data/test/spec/tool/test_unit_api_test.rb +61 -0
- data/test/spec/tool/test_unit_translator_test.rb +29 -0
- data/test/test_helper.rb +8 -0
- metadata +89 -67
- data/examples/add_specification_spec.rb +0 -15
- data/examples/craps.rb +0 -15
- data/examples/craps_spec.rb +0 -105
- data/examples/dsl_spec.rb +0 -8
- data/examples/movie.rb +0 -7
- data/examples/movie_list.rb +0 -19
- data/examples/movie_spec.rb +0 -37
- data/lib/spec/collector.rb +0 -17
- data/lib/spec/context.rb +0 -89
- data/lib/spec/dsl.rb +0 -23
- data/lib/spec/gui_runner.rb +0 -59
- data/lib/spec/mock.rb +0 -183
- data/lib/spec/text_runner.rb +0 -75
- data/test/collection_owner.rb +0 -48
- data/test/context_fixtures_test.rb +0 -71
- data/test/context_run_test.rb +0 -174
- data/test/dsl_test.rb +0 -48
- data/test/error_reporting_test.rb +0 -225
- data/test/expectations_for_should_have_test.rb +0 -144
- data/test/expectations_test.rb +0 -592
- data/test/get_classes.rb +0 -6
- data/test/gui_runner_test.rb +0 -162
- data/test/mock_test.rb +0 -157
- data/test/spec_collection_test.rb +0 -39
- data/test/specification_addition_test.rb +0 -29
- data/test/specification_identification_test.rb +0 -71
- data/test/text_runner_test.rb +0 -146
data/CHANGES
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
= RSpec Changelog
|
2
2
|
|
3
|
-
==
|
4
|
-
|
5
|
-
* This document should be updated for every commit.
|
3
|
+
== Version 0.5.0
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
as in the news posted on rubyforge. Therefore,
|
10
|
-
make sure it is a sentence that makes sense to the reader.
|
11
|
-
It should summarise the release at a high level.
|
12
|
-
|
13
|
-
* Make sure the PKG_VERSION constant in Rakefile.rb is
|
14
|
-
consistent with the latest version in this document.
|
5
|
+
This release introduces a new API and obsoletes previous versions
|
6
|
+
* Lots and lots of changes. See examples.
|
15
7
|
|
16
8
|
== Version 0.4.0
|
17
9
|
|
18
|
-
The "two Daves walked into a bar" release.
|
10
|
+
The "two Daves walked into a bar and Aslak ruined the party" release.
|
19
11
|
|
12
|
+
* Moved source code to separate subfolders
|
13
|
+
* Added new DSL runner based on instance_exec
|
14
|
+
* Added spike for testdox/rdoc generation
|
20
15
|
* merge Astels' and Chelimsky's work on ShouldHelper
|
21
16
|
* this would be 0.5.0 if I updated the documentation
|
22
17
|
* it breaks all of your existing specifications. We're not sorry.
|
data/Rakefile
CHANGED
@@ -7,6 +7,8 @@ require 'rake/contrib/xforge'
|
|
7
7
|
require 'rake/clean'
|
8
8
|
require 'rake/testtask'
|
9
9
|
require 'rake/rdoctask'
|
10
|
+
require 'lib/spec/version'
|
11
|
+
require 'lib/spec/rake/spectask'
|
10
12
|
|
11
13
|
PKG_NAME = "rspec"
|
12
14
|
# Versioning scheme: MAJOR.MINOR.PATCH
|
@@ -19,7 +21,7 @@ PKG_NAME = "rspec"
|
|
19
21
|
# (This is subject to change - AH)
|
20
22
|
#
|
21
23
|
# REMEMBER TO KEEP PKG_VERSION IN SYNC WITH CHANGELOG
|
22
|
-
PKG_VERSION
|
24
|
+
PKG_VERSION = Spec::VERSION::STRING
|
23
25
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
24
26
|
PKG_FILES = FileList[
|
25
27
|
'[A-Z]*',
|
@@ -29,23 +31,26 @@ PKG_FILES = FileList[
|
|
29
31
|
'doc/**/*'
|
30
32
|
]
|
31
33
|
|
32
|
-
task :default => [:test
|
34
|
+
task :default => [:test] #, :test_text_runner]
|
35
|
+
|
36
|
+
Spec::Rake::SpecTask.new do |t|
|
37
|
+
t.spec_files = FileList['examples/**/*_spec.rb']
|
38
|
+
t.verbose = true
|
39
|
+
end
|
33
40
|
|
34
41
|
Rake::TestTask.new do |t|
|
35
42
|
t.libs << "test"
|
36
|
-
t.test_files = FileList['
|
37
|
-
"test/rspec_*.rb", "test/text_runner_test.rb")
|
43
|
+
t.test_files = FileList['test/**/*_test.rb']
|
38
44
|
t.verbose = true
|
39
45
|
end
|
40
46
|
|
41
47
|
# text runner tests need to run individually
|
42
|
-
|
43
|
-
|
44
|
-
t.libs << "
|
45
|
-
t.
|
46
|
-
t.
|
47
|
-
|
48
|
-
end
|
48
|
+
#Rake::TestTask.new(:test_text_runner) do |t|
|
49
|
+
# t.libs << "test"
|
50
|
+
# t.libs << "examples"
|
51
|
+
# t.test_files = FileList['test/text_runner_test.rb']
|
52
|
+
# t.verbose = true
|
53
|
+
#end
|
49
54
|
|
50
55
|
|
51
56
|
# Create a task to build the RDOC documentation tree.
|
@@ -95,7 +100,7 @@ spec = Gem::Specification.new do |s|
|
|
95
100
|
s.autorequire = 'spec'
|
96
101
|
|
97
102
|
s.bindir = "bin"
|
98
|
-
s.executables = ["spec"]
|
103
|
+
s.executables = ["spec", "test2rspec"]
|
99
104
|
s.default_executable = "spec"
|
100
105
|
|
101
106
|
#### Author and project details.
|
data/TUTORIAL
CHANGED
@@ -236,7 +236,7 @@ includes "Star Wars", you will get the following error:
|
|
236
236
|
|
237
237
|
1)
|
238
238
|
<#<MovieList:0x284c1e0 @movies={"Star Wars"=>#<Movie:0x284c180 @name="Star Wars"
|
239
|
-
>}>> should include <"Space Balls"> (Spec::
|
239
|
+
>}>> should include <"Space Balls"> (Spec::Api::ExpectationNotMetError)
|
240
240
|
./movie_spec.rb:34:in `should_include_space_balls'
|
241
241
|
../bin/spec:10
|
242
242
|
|
data/WHY_RSPEC
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
== Why RSpec
|
2
|
+
|
3
|
+
=== Readability
|
4
|
+
RSpec specifications read better than Test::Unit tests. Compare this:
|
5
|
+
|
6
|
+
class TemperatureCoverterTest < Test::Unit::TestCase
|
7
|
+
def test_converts_0C_to_32F
|
8
|
+
c = TemperatureCoverter.new
|
9
|
+
assert_equal(32.0, c.convert_from_c_to_f(0.0)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_converts_100C_to_100F
|
13
|
+
c = TemperatureCoverter.new
|
14
|
+
assert_equal(212.0, c.convert_from_c_to_f(100.0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
to this:
|
19
|
+
|
20
|
+
context "TemperatureCoverter"
|
21
|
+
specify "Converts 0C to 32F"
|
22
|
+
c = TemperatureCoverter.new
|
23
|
+
c.convert_from_c_to_f(0.0).should.equal 32.0
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "Converts 100C to 212F"
|
27
|
+
c = TemperatureCoverter.new
|
28
|
+
c.convert_from_c_to_f(100.0).should.equal 212.0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
=== Built-in mocks
|
33
|
+
....
|
34
|
+
|
35
|
+
=== Self-documenting
|
36
|
+
RSpec specifications are self documenting. If run with the --rspec-report option,
|
37
|
+
it will produce the following report:
|
38
|
+
|
39
|
+
== TemperatureCoverter
|
40
|
+
* Converts 0C to 32F
|
41
|
+
* Converts 100C to 212F
|
42
|
+
|
43
|
+
RSpec reports gives a high-level overview of how the classes
|
44
|
+
in the system should behave. Of course, the developers have to
|
45
|
+
name their specifications appropriately.
|
46
|
+
|
47
|
+
By making RSpec reports visible as part of the API documentation,
|
48
|
+
developers are likely to put a little effort into making the RSpec
|
49
|
+
report make sense. Consider this example (translated from an
|
50
|
+
imaginary Test::Unit test):
|
51
|
+
|
52
|
+
context "TemperatureCoverter"
|
53
|
+
specify "Convert"
|
54
|
+
c = TemperatureCoverter.new
|
55
|
+
c.convert_from_c_to_f(0.0).should.equal 32.0
|
56
|
+
c.convert_from_c_to_f(100.0).should.equal 212.0
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
And the generated report:
|
61
|
+
|
62
|
+
== TemperatureCoverter
|
63
|
+
* Convert
|
64
|
+
|
65
|
+
This specification was translated from a Test::Unit file that has one test method,
|
66
|
+
<tt>test_onvert</tt>. It doesn't read so well, and it doesn't convey much high-leve
|
67
|
+
information about how the TemperatureCoverter class is supposed to behave. RSpec
|
68
|
+
encourages developers to give specifications a name that conveys the intent of the
|
69
|
+
specification. This in turn has several subtle benefits:
|
70
|
+
|
71
|
+
* Specifications tend to become smaller
|
72
|
+
* It tends to higlight too coupled code (specification names become complex)
|
73
|
+
|
74
|
+
It is the developers' responsibility to make sure that the name of each specification
|
75
|
+
represent at a high level what is being assumed in the specification body.
|
76
|
+
|
77
|
+
== What about my existing Test::Unit tests?
|
78
|
+
RSpec comes with a migration tool that will translate all of your existing
|
79
|
+
Test::Unit tests to RSpec specifications.
|
80
|
+
|
81
|
+
== How do I run RSpec specifications?
|
82
|
+
|
83
|
+
There are several ways to do this.
|
84
|
+
|
85
|
+
=== Just run the ruby file
|
86
|
+
Any RSpec specification is stand-alone and can be run with:
|
87
|
+
|
88
|
+
ruby path/to/my/spec.rb
|
89
|
+
|
90
|
+
This will run your spec and output the results to stdout. You can use command line options
|
91
|
+
to tell RSpec to output documentation to a specific file too:
|
92
|
+
|
93
|
+
ruby path/to/my/spec.rb --rspec-report doc/rspec_report.rd
|
94
|
+
|
95
|
+
=== Use the spec commandline
|
96
|
+
You can run several specifications with:
|
97
|
+
|
98
|
+
spec path/to/my/directory
|
99
|
+
|
100
|
+
or
|
101
|
+
|
102
|
+
spec path/to/my/directory --rspec-report doc/rspec_report.rd
|
103
|
+
|
104
|
+
=== Use Rake
|
105
|
+
RSpec ships with a task similar that lets you run RSpec specifications
|
106
|
+
from Rake. Just upt the following in your Rakefile:
|
107
|
+
|
108
|
+
Rake::RSpecTask.new
|
109
|
+
|
110
|
+
This will create a task called <tt>spec</tt> task that you can run like this:
|
111
|
+
|
112
|
+
rake spec
|
113
|
+
|
114
|
+
By default this will run all the specifications under the spec directory. See
|
115
|
+
the Rake::RSpecTask documentation for details on how to override the defaults.
|
data/bin/spec
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
if ARGV.empty?
|
4
|
+
puts "You must provide a directory or file to run"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'find'
|
9
|
+
require File.dirname(__FILE__) + "/../lib/spec"
|
10
|
+
|
11
|
+
context_runner = Spec::Runner::ContextRunner.new(ARGV)
|
12
|
+
Spec::Runner::Context.context_runner = context_runner
|
4
13
|
|
5
14
|
ARGV.each do |file|
|
6
|
-
|
15
|
+
Find.find(file) do |path|
|
16
|
+
if FileTest.file?(path) and File.extname(path) == '.rb'
|
17
|
+
require path
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
8
21
|
|
9
|
-
|
10
|
-
|
22
|
+
context_runner.run
|
23
|
+
|
data/bin/test2rspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'optparse'
|
6
|
+
require File.dirname(__FILE__) + "/../lib/spec/tool/command_line.rb"
|
7
|
+
require File.dirname(__FILE__) + "/../lib/spec/tool/test_unit_translator.rb"
|
8
|
+
|
9
|
+
opts = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: test2rspec [options] SRC [DEST]"
|
11
|
+
opts.separator ""
|
12
|
+
|
13
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
14
|
+
puts opts
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
end
|
18
|
+
opts.parse!(ARGV)
|
19
|
+
|
20
|
+
cl = Spec::Tool::CommandLine.new
|
21
|
+
source = ARGV[0]
|
22
|
+
target = ARGV[1]
|
23
|
+
|
24
|
+
if source.nil?
|
25
|
+
STDERR.puts opts
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
cl.run source, target, STDOUT
|
31
|
+
rescue => e
|
32
|
+
STDERR.puts e.message
|
33
|
+
STDERR.puts e.backtrace.join("\n")
|
34
|
+
STDERR.puts opts
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/spec'
|
2
|
+
|
3
|
+
class Airport
|
4
|
+
def working?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def need?(thing)
|
9
|
+
thing != :cables
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Airport at home" do
|
14
|
+
setup do
|
15
|
+
@airport = Airport.new
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "should always work" do
|
19
|
+
@airport.should.be.working
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "should not need cables" do
|
23
|
+
@airport.should.not.need :cables
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "should not need electricity" do
|
27
|
+
# This will fail...
|
28
|
+
@airport.should.not.need :electricity
|
29
|
+
end
|
30
|
+
|
31
|
+
teardown do
|
32
|
+
@airport = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/spec'
|
2
|
+
|
3
|
+
context "Mocker" do
|
4
|
+
|
5
|
+
specify "should be able to call mock()" do
|
6
|
+
mock = mock("poke me")
|
7
|
+
mock.should_receive(:poke)
|
8
|
+
mock.poke
|
9
|
+
end
|
10
|
+
|
11
|
+
specify "should fail when expected message not received" do
|
12
|
+
mock = mock("poke me")
|
13
|
+
mock.should_receive(:poke)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/spec'
|
2
|
+
|
3
|
+
class SpecFramework
|
4
|
+
def intuitive?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def adopted_quickly?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Spec framework" do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@spec_framework = SpecFramework.new
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should be intuitive" do
|
20
|
+
@spec_framework.should.be.intuitive
|
21
|
+
end
|
22
|
+
|
23
|
+
specify "should be adopted quickly" do
|
24
|
+
#this will fail
|
25
|
+
@spec_framework.should.be.adopted_quickly
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/examples/stack.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class StackUnderflowError < RuntimeError
|
2
|
+
end
|
3
|
+
|
4
|
+
class StackOverflowError < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
class Stack
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@items = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def push object
|
14
|
+
raise StackOverflowError if @items.length == 10
|
15
|
+
@items.push object
|
16
|
+
end
|
17
|
+
|
18
|
+
def pop
|
19
|
+
raise StackUnderflowError if @items.empty?
|
20
|
+
@items.delete @items.last
|
21
|
+
end
|
22
|
+
|
23
|
+
def top
|
24
|
+
raise StackUnderflowError if @items.empty?
|
25
|
+
@items.last
|
26
|
+
end
|
27
|
+
|
28
|
+
def empty?
|
29
|
+
@items.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def size
|
33
|
+
@items.length
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
context "An empty stack" do
|
2
|
+
|
3
|
+
setup do
|
4
|
+
@stack = Stack.new
|
5
|
+
end
|
6
|
+
|
7
|
+
specify "should accept an item when sent push" do
|
8
|
+
lambda { @stack.push Object.new }.should.not.raise
|
9
|
+
end
|
10
|
+
|
11
|
+
specify "should complain when sent top" do
|
12
|
+
lambda { @stack.top }.should.raise StackUnderflowError
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "should complain when sent pop" do
|
16
|
+
lambda { @stack.pop }.should.raise StackUnderflowError
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "A stack with one item" do
|
22
|
+
setup do
|
23
|
+
@stack = Stack.new
|
24
|
+
@stack.push 3
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should accept an item when sent push" do
|
28
|
+
lambda { @stack.push Object.new }.should.not.raise
|
29
|
+
end
|
30
|
+
|
31
|
+
specify "should return top when sent top" do
|
32
|
+
@stack.top.should.be 3
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "should not remove top when sent top" do
|
36
|
+
@stack.top.should.be 3
|
37
|
+
@stack.top.should.be 3
|
38
|
+
end
|
39
|
+
|
40
|
+
specify "should return top when sent pop" do
|
41
|
+
@stack.pop.should.be 3
|
42
|
+
end
|
43
|
+
|
44
|
+
specify "should remove top when sent pop" do
|
45
|
+
@stack.pop.should.be 3
|
46
|
+
lambda { @stack.pop }.should.raise StackUnderflowError
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "An almost full stack (with one item less than capacity)" do
|
52
|
+
setup do
|
53
|
+
@stack = Stack.new
|
54
|
+
(1..9).each { |i| @stack.push i }
|
55
|
+
end
|
56
|
+
|
57
|
+
specify "should accept an item when sent push" do
|
58
|
+
@stack.push Object.new
|
59
|
+
end
|
60
|
+
|
61
|
+
specify "should return top when sent top" do
|
62
|
+
@stack.top.should.be 9
|
63
|
+
end
|
64
|
+
|
65
|
+
specify "should not remove top when sent top" do
|
66
|
+
@stack.top.should.be 9
|
67
|
+
@stack.top.should.be 9
|
68
|
+
end
|
69
|
+
|
70
|
+
specify "should return top when sent pop" do
|
71
|
+
@stack.pop.should.be 9
|
72
|
+
end
|
73
|
+
|
74
|
+
specify "should remove top when sent pop" do
|
75
|
+
@stack.pop.should.be 9
|
76
|
+
@stack.pop.should.be 8
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
context "A full stack" do
|
81
|
+
|
82
|
+
setup do
|
83
|
+
@stack = Stack.new
|
84
|
+
(1..10).each { |i| @stack.push i }
|
85
|
+
end
|
86
|
+
|
87
|
+
specify "should complain on push" do
|
88
|
+
lambda { @stack.push Object.new }.should.raise StackOverflowError
|
89
|
+
end
|
90
|
+
|
91
|
+
specify "should return top when sent top" do
|
92
|
+
@stack.top.should.be 10
|
93
|
+
end
|
94
|
+
|
95
|
+
specify "should not remove top when sent top" do
|
96
|
+
@stack.top.should.be 10
|
97
|
+
@stack.top.should.be 10
|
98
|
+
end
|
99
|
+
|
100
|
+
specify "should return top when sent pop" do
|
101
|
+
@stack.pop.should.be 10
|
102
|
+
end
|
103
|
+
|
104
|
+
specify "should remove top when sent pop" do
|
105
|
+
@stack.pop.should.be 10
|
106
|
+
@stack.pop.should.be 9
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|