summaryrefslogtreecommitdiffstats
path: root/vendor/gems/rspec/examples
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-12 17:14:21 -0600
committerLuke Kanies <luke@madstop.com>2008-02-12 17:14:21 -0600
commitbcb9b564281003e22d72752d84fa9dc9c8c7107b (patch)
tree57ba50f64b5c5092c1901cb4c0664deffa61ab0a /vendor/gems/rspec/examples
parent3af6827875f4e02b47fe2293280ff9afe811485f (diff)
downloadpuppet-bcb9b564281003e22d72752d84fa9dc9c8c7107b.tar.gz
puppet-bcb9b564281003e22d72752d84fa9dc9c8c7107b.tar.xz
puppet-bcb9b564281003e22d72752d84fa9dc9c8c7107b.zip
Copying over Rick's work from the master branch supporting autotest and
cleaning up the rspec support.
Diffstat (limited to 'vendor/gems/rspec/examples')
-rw-r--r--vendor/gems/rspec/examples/auto_spec_description_example.rb19
-rw-r--r--vendor/gems/rspec/examples/before_and_after_example.rb39
-rw-r--r--vendor/gems/rspec/examples/behave_as_example.rb45
-rw-r--r--vendor/gems/rspec/examples/custom_expectation_matchers.rb54
-rw-r--r--vendor/gems/rspec/examples/custom_formatter.rb11
-rw-r--r--vendor/gems/rspec/examples/dynamic_spec.rb9
-rw-r--r--vendor/gems/rspec/examples/file_accessor.rb18
-rw-r--r--vendor/gems/rspec/examples/file_accessor_spec.rb38
-rw-r--r--vendor/gems/rspec/examples/greeter_spec.rb30
-rw-r--r--vendor/gems/rspec/examples/helper_method_example.rb11
-rw-r--r--vendor/gems/rspec/examples/io_processor.rb8
-rw-r--r--vendor/gems/rspec/examples/io_processor_spec.rb21
-rw-r--r--vendor/gems/rspec/examples/legacy_spec.rb10
-rw-r--r--vendor/gems/rspec/examples/mocking_example.rb27
-rw-r--r--vendor/gems/rspec/examples/multi_threaded_behaviour_runner.rb25
-rw-r--r--vendor/gems/rspec/examples/partial_mock_example.rb28
-rw-r--r--vendor/gems/rspec/examples/pending_example.rb20
-rw-r--r--vendor/gems/rspec/examples/predicate_example.rb27
-rw-r--r--vendor/gems/rspec/examples/priority.txt1
-rw-r--r--vendor/gems/rspec/examples/shared_behaviours_example.rb39
-rw-r--r--vendor/gems/rspec/examples/spec_helper.rb1
-rw-r--r--vendor/gems/rspec/examples/stack.rb36
-rw-r--r--vendor/gems/rspec/examples/stack_spec.rb97
-rw-r--r--vendor/gems/rspec/examples/stubbing_example.rb69
-rw-r--r--vendor/gems/rspec/examples/test_case_adapter_example.rb26
-rw-r--r--vendor/gems/rspec/examples/test_case_spec.rb65
26 files changed, 774 insertions, 0 deletions
diff --git a/vendor/gems/rspec/examples/auto_spec_description_example.rb b/vendor/gems/rspec/examples/auto_spec_description_example.rb
new file mode 100644
index 000000000..a4928ef4a
--- /dev/null
+++ b/vendor/gems/rspec/examples/auto_spec_description_example.rb
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+# Run spec w/ -fs to see the output of this file
+
+describe "Examples with no descriptions" do
+
+ # description is auto-generated as "should equal(5)" based on the last #should
+ it do
+ 3.should equal(3)
+ 5.should equal(5)
+ end
+
+ it { 3.should be < 5 }
+
+ it { ["a"].should include("a") }
+
+ it { [1,2,3].should respond_to(:size) }
+
+end
diff --git a/vendor/gems/rspec/examples/before_and_after_example.rb b/vendor/gems/rspec/examples/before_and_after_example.rb
new file mode 100644
index 000000000..09e3805fb
--- /dev/null
+++ b/vendor/gems/rspec/examples/before_and_after_example.rb
@@ -0,0 +1,39 @@
+$global = 0
+
+describe "State created in before(:all)" do
+ before :all do
+ @sideeffect = 1
+ $global +=1
+ end
+
+ before :each do
+ @isolated = 1
+ end
+
+ it "should be accessible from example" do
+ @sideeffect.should == 1
+ $global.should == 1
+ @isolated.should == 1
+
+ @sideeffect += 1
+ @isolated += 1
+ end
+
+ it "should not have sideffects" do
+ @sideeffect.should == 1
+ $global.should == 2
+ @isolated.should == 1
+
+ @sideeffect += 1
+ @isolated += 1
+ end
+
+ after :each do
+ $global += 1
+ end
+
+ after :all do
+ $global.should == 3
+ $global = 0
+ end
+end
diff --git a/vendor/gems/rspec/examples/behave_as_example.rb b/vendor/gems/rspec/examples/behave_as_example.rb
new file mode 100644
index 000000000..e95d1469a
--- /dev/null
+++ b/vendor/gems/rspec/examples/behave_as_example.rb
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+def behave_as_electric_musician
+ respond_to(:read_notes, :turn_down_amp)
+end
+
+def behave_as_musician
+ respond_to(:read_notes)
+end
+
+module BehaveAsExample
+
+ class BluesGuitarist
+ def read_notes; end
+ def turn_down_amp; end
+ end
+
+ class RockGuitarist
+ def read_notes; end
+ def turn_down_amp; end
+ end
+
+ class ClassicGuitarist
+ def read_notes; end
+ end
+
+ describe BluesGuitarist do
+ it "should behave as guitarist" do
+ BluesGuitarist.new.should behave_as_electric_musician
+ end
+ end
+
+ describe RockGuitarist do
+ it "should behave as guitarist" do
+ RockGuitarist.new.should behave_as_electric_musician
+ end
+ end
+
+ describe ClassicGuitarist do
+ it "should not behave as guitarist" do
+ ClassicGuitarist.new.should behave_as_musician
+ end
+ end
+
+end
diff --git a/vendor/gems/rspec/examples/custom_expectation_matchers.rb b/vendor/gems/rspec/examples/custom_expectation_matchers.rb
new file mode 100644
index 000000000..075bb542d
--- /dev/null
+++ b/vendor/gems/rspec/examples/custom_expectation_matchers.rb
@@ -0,0 +1,54 @@
+module AnimalSpecHelper
+ class Eat
+ def initialize(food)
+ @food = food
+ end
+
+ def matches?(animal)
+ @animal = animal
+ @animal.eats?(@food)
+ end
+
+ def failure_message
+ "expected #{@animal} to eat #{@food}, but it does not"
+ end
+
+ def negative_failure_message
+ "expected #{@animal} not to eat #{@food}, but it does"
+ end
+ end
+
+ def eat(food)
+ Eat.new(food)
+ end
+end
+
+module Animals
+ class Animal
+ def eats?(food)
+ return foods_i_eat.include?(food)
+ end
+ end
+
+ class Mouse < Animal
+ def foods_i_eat
+ [:cheese]
+ end
+ end
+
+ describe Mouse do
+ include AnimalSpecHelper
+ before(:each) do
+ @mouse = Animals::Mouse.new
+ end
+
+ it "should eat cheese" do
+ @mouse.should eat(:cheese)
+ end
+
+ it "should not eat cat" do
+ @mouse.should_not eat(:cat)
+ end
+ end
+
+end
diff --git a/vendor/gems/rspec/examples/custom_formatter.rb b/vendor/gems/rspec/examples/custom_formatter.rb
new file mode 100644
index 000000000..851c9906f
--- /dev/null
+++ b/vendor/gems/rspec/examples/custom_formatter.rb
@@ -0,0 +1,11 @@
+require 'spec/runner/formatter/progress_bar_formatter'
+
+# Example of a formatter with custom bactrace printing. Run me with:
+# ruby bin/spec failing_examples -r examples/custom_formatter.rb -f CustomFormatter
+class CustomFormatter < Spec::Runner::Formatter::ProgressBarFormatter
+ def backtrace_line(line)
+ line.gsub(/([^:]*\.rb):(\d*)/) do
+ "<a href=\"file://#{File.expand_path($1)}\">#{$1}:#{$2}</a> "
+ end
+ end
+end
diff --git a/vendor/gems/rspec/examples/dynamic_spec.rb b/vendor/gems/rspec/examples/dynamic_spec.rb
new file mode 100644
index 000000000..15d473d61
--- /dev/null
+++ b/vendor/gems/rspec/examples/dynamic_spec.rb
@@ -0,0 +1,9 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "Some integers" do
+ (1..10).each do |n|
+ it "The root of #{n} square should be #{n}" do
+ Math.sqrt(n*n).should == n
+ end
+ end
+end
diff --git a/vendor/gems/rspec/examples/file_accessor.rb b/vendor/gems/rspec/examples/file_accessor.rb
new file mode 100644
index 000000000..16bc45dbb
--- /dev/null
+++ b/vendor/gems/rspec/examples/file_accessor.rb
@@ -0,0 +1,18 @@
+class FileAccessor
+ def open_and_handle_with(pathname, processor)
+ pathname.open do |io|
+ processor.process(io)
+ end
+ end
+end
+
+if __FILE__ == $0
+ require File.dirname(__FILE__) + '/io_processor'
+ require 'pathname'
+
+ accessor = FileAccessor.new
+ io_processor = IoProcessor.new
+ file = Pathname.new ARGV[0]
+
+ accessor.open_and_handle_with(file, io_processor)
+end
diff --git a/vendor/gems/rspec/examples/file_accessor_spec.rb b/vendor/gems/rspec/examples/file_accessor_spec.rb
new file mode 100644
index 000000000..628d4c0b0
--- /dev/null
+++ b/vendor/gems/rspec/examples/file_accessor_spec.rb
@@ -0,0 +1,38 @@
+require File.dirname(__FILE__) + '/spec_helper'
+require File.dirname(__FILE__) + '/file_accessor'
+require 'stringio'
+
+describe "A FileAccessor" do
+ # This sequence diagram illustrates what this spec specifies.
+ #
+ # +--------------+ +----------+ +-------------+
+ # | FileAccessor | | Pathname | | IoProcessor |
+ # +--------------+ +----------+ +-------------+
+ # | | |
+ # open_and_handle_with | | |
+ # -------------------->| | open | |
+ # | |--------------->| | |
+ # | | io | | |
+ # | |<...............| | |
+ # | | | process(io) |
+ # | |---------------------------------->| |
+ # | | | | |
+ # | |<..................................| |
+ # | | |
+ #
+ it "should open a file and pass it to the processor's process method" do
+ # This is the primary actor
+ accessor = FileAccessor.new
+
+ # These are the primary actor's neighbours, which we mock.
+ file = mock "Pathname"
+ io_processor = mock "IoProcessor"
+
+ io = StringIO.new "whatever"
+ file.should_receive(:open).and_yield io
+ io_processor.should_receive(:process).with(io)
+
+ accessor.open_and_handle_with(file, io_processor)
+ end
+
+end
diff --git a/vendor/gems/rspec/examples/greeter_spec.rb b/vendor/gems/rspec/examples/greeter_spec.rb
new file mode 100644
index 000000000..7d67e3187
--- /dev/null
+++ b/vendor/gems/rspec/examples/greeter_spec.rb
@@ -0,0 +1,30 @@
+# greeter.rb
+#
+# Based on http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle
+#
+# Run with:
+#
+# spec greeter_spec.rb --heckle Greeter
+#
+class Greeter
+ def initialize(person = nil)
+ @person = person
+ end
+
+ def greet
+ @person.nil? ? "Hi there!" : "Hi #{@person}!"
+ end
+end
+
+describe "Greeter" do
+ it "should say Hi to person" do
+ greeter = Greeter.new("Kevin")
+ greeter.greet.should == "Hi Kevin!"
+ end
+
+ it "should say Hi to nobody" do
+ greeter = Greeter.new
+ # Uncomment the next line to make Heckle happy
+ #greeter.greet.should == "Hi there!"
+ end
+end
diff --git a/vendor/gems/rspec/examples/helper_method_example.rb b/vendor/gems/rspec/examples/helper_method_example.rb
new file mode 100644
index 000000000..5f94cf151
--- /dev/null
+++ b/vendor/gems/rspec/examples/helper_method_example.rb
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "a context with helper a method" do
+ def helper_method
+ "received call"
+ end
+
+ it "should make that method available to specs" do
+ helper_method.should == "received call"
+ end
+end
diff --git a/vendor/gems/rspec/examples/io_processor.rb b/vendor/gems/rspec/examples/io_processor.rb
new file mode 100644
index 000000000..6b15147b6
--- /dev/null
+++ b/vendor/gems/rspec/examples/io_processor.rb
@@ -0,0 +1,8 @@
+class DataTooShort < StandardError; end
+
+class IoProcessor
+ # Does some fancy stuff unless the length of +io+ is shorter than 32
+ def process(io)
+ raise DataTooShort if io.read.length < 32
+ end
+end
diff --git a/vendor/gems/rspec/examples/io_processor_spec.rb b/vendor/gems/rspec/examples/io_processor_spec.rb
new file mode 100644
index 000000000..5cab7bf31
--- /dev/null
+++ b/vendor/gems/rspec/examples/io_processor_spec.rb
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/spec_helper'
+require File.dirname(__FILE__) + '/io_processor'
+require 'stringio'
+
+describe "An IoProcessor" do
+ before(:each) do
+ @processor = IoProcessor.new
+ end
+
+ it "should raise nothing when the file is exactly 32 bytes" do
+ lambda {
+ @processor.process(StringIO.new("z"*32))
+ }.should_not raise_error
+ end
+
+ it "should raise an exception when the file length is less than 32 bytes" do
+ lambda {
+ @processor.process(StringIO.new("z"*31))
+ }.should raise_error(DataTooShort)
+ end
+end
diff --git a/vendor/gems/rspec/examples/legacy_spec.rb b/vendor/gems/rspec/examples/legacy_spec.rb
new file mode 100644
index 000000000..61669e7e6
--- /dev/null
+++ b/vendor/gems/rspec/examples/legacy_spec.rb
@@ -0,0 +1,10 @@
+context "A legacy spec" do
+ setup do
+ end
+
+ specify "should work fine" do
+ end
+
+ teardown do
+ end
+end
diff --git a/vendor/gems/rspec/examples/mocking_example.rb b/vendor/gems/rspec/examples/mocking_example.rb
new file mode 100644
index 000000000..6adbef59d
--- /dev/null
+++ b/vendor/gems/rspec/examples/mocking_example.rb
@@ -0,0 +1,27 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "A consumer of a mock" do
+ it "should be able to send messages to the mock" do
+ mock = mock("poke me")
+ mock.should_receive(:poke)
+ mock.poke
+ end
+end
+
+describe "a mock" do
+ it "should be able to mock the same message twice w/ different args" do
+ mock = mock("mock")
+ mock.should_receive(:msg).with(:arg1).and_return(:val1)
+ mock.should_receive(:msg).with(:arg2).and_return(:val2)
+ mock.msg(:arg1).should eql(:val1)
+ mock.msg(:arg2).should eql(:val2)
+ end
+
+ it "should be able to mock the same message twice w/ different args in reverse order" do
+ mock = mock("mock")
+ mock.should_receive(:msg).with(:arg1).and_return(:val1)
+ mock.should_receive(:msg).with(:arg2).and_return(:val2)
+ mock.msg(:arg2).should eql(:val2)
+ mock.msg(:arg1).should eql(:val1)
+ end
+end
diff --git a/vendor/gems/rspec/examples/multi_threaded_behaviour_runner.rb b/vendor/gems/rspec/examples/multi_threaded_behaviour_runner.rb
new file mode 100644
index 000000000..e2824a61e
--- /dev/null
+++ b/vendor/gems/rspec/examples/multi_threaded_behaviour_runner.rb
@@ -0,0 +1,25 @@
+
+class MultiThreadedBehaviourRunner < Spec::Runner::BehaviourRunner
+ def initialize(options)
+ super
+ # configure these
+ @thread_count = 4
+ @thread_wait = 0
+ end
+
+ def run_behaviours(behaviours)
+ @threads = []
+ q = Queue.new
+ behaviours.each { |b| q << b}
+ @thread_count.times do
+ @threads << Thread.new(q) do |queue|
+ while not queue.empty?
+ behaviour = queue.pop
+ behaviour.run(@options.reporter, @options.dry_run, @options.reverse)
+ end
+ end
+ sleep @thread_wait
+ end
+ @threads.each {|t| t.join}
+ end
+end
diff --git a/vendor/gems/rspec/examples/partial_mock_example.rb b/vendor/gems/rspec/examples/partial_mock_example.rb
new file mode 100644
index 000000000..841ec8847
--- /dev/null
+++ b/vendor/gems/rspec/examples/partial_mock_example.rb
@@ -0,0 +1,28 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+class MockableClass
+ def self.find id
+ return :original_return
+ end
+end
+
+describe "A partial mock" do
+
+ it "should work at the class level" do
+ MockableClass.should_receive(:find).with(1).and_return {:stub_return}
+ MockableClass.find(1).should equal(:stub_return)
+ end
+
+ it "should revert to the original after each spec" do
+ MockableClass.find(1).should equal(:original_return)
+ end
+
+ it "can be mocked w/ ordering" do
+ MockableClass.should_receive(:msg_1).ordered
+ MockableClass.should_receive(:msg_2).ordered
+ MockableClass.should_receive(:msg_3).ordered
+ MockableClass.msg_1
+ MockableClass.msg_2
+ MockableClass.msg_3
+ end
+end
diff --git a/vendor/gems/rspec/examples/pending_example.rb b/vendor/gems/rspec/examples/pending_example.rb
new file mode 100644
index 000000000..13f3d00c4
--- /dev/null
+++ b/vendor/gems/rspec/examples/pending_example.rb
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "pending example (using pending method)" do
+ it %Q|should be reported as "PENDING: for some reason"| do
+ pending("for some reason")
+ end
+end
+
+describe "pending example (with no block)" do
+ it %Q|should be reported as "PENDING: Not Yet Implemented"|
+end
+
+describe "pending example (with block for pending)" do
+ it %Q|should have a failing block, passed to pending, reported as "PENDING: for some reason"| do
+ pending("for some reason") do
+ raise "some reason"
+ end
+ end
+end
+
diff --git a/vendor/gems/rspec/examples/predicate_example.rb b/vendor/gems/rspec/examples/predicate_example.rb
new file mode 100644
index 000000000..1202bb670
--- /dev/null
+++ b/vendor/gems/rspec/examples/predicate_example.rb
@@ -0,0 +1,27 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+class BddFramework
+ def intuitive?
+ true
+ end
+
+ def adopted_quickly?
+ true
+ end
+end
+
+describe "BDD framework" do
+
+ before(:each) do
+ @bdd_framework = BddFramework.new
+ end
+
+ it "should be adopted quickly" do
+ @bdd_framework.should be_adopted_quickly
+ end
+
+ it "should be intuitive" do
+ @bdd_framework.should be_intuitive
+ end
+
+end
diff --git a/vendor/gems/rspec/examples/priority.txt b/vendor/gems/rspec/examples/priority.txt
new file mode 100644
index 000000000..5b00064e2
--- /dev/null
+++ b/vendor/gems/rspec/examples/priority.txt
@@ -0,0 +1 @@
+examples/custom_expectation_matchers.rb \ No newline at end of file
diff --git a/vendor/gems/rspec/examples/shared_behaviours_example.rb b/vendor/gems/rspec/examples/shared_behaviours_example.rb
new file mode 100644
index 000000000..33c924643
--- /dev/null
+++ b/vendor/gems/rspec/examples/shared_behaviours_example.rb
@@ -0,0 +1,39 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+module SharedBehaviourExample
+ class OneThing
+ def what_things_do
+ "stuff"
+ end
+ end
+
+ class AnotherThing
+ def what_things_do
+ "stuff"
+ end
+ end
+
+ describe "All Things", :shared => true do
+ def helper_method
+ "helper method"
+ end
+
+ it "should do what things do" do
+ @thing.what_things_do.should == "stuff"
+ end
+ end
+
+ describe OneThing do
+ it_should_behave_like "All Things"
+ before(:each) { @thing = OneThing.new }
+
+ it "should have access to helper methods defined in the shared behaviour" do
+ helper_method.should == "helper method"
+ end
+ end
+
+ describe AnotherThing do
+ it_should_behave_like "All Things"
+ before(:each) { @thing = AnotherThing.new }
+ end
+end
diff --git a/vendor/gems/rspec/examples/spec_helper.rb b/vendor/gems/rspec/examples/spec_helper.rb
new file mode 100644
index 000000000..61f51fbdb
--- /dev/null
+++ b/vendor/gems/rspec/examples/spec_helper.rb
@@ -0,0 +1 @@
+require File.dirname(__FILE__) + '/../lib/spec'
diff --git a/vendor/gems/rspec/examples/stack.rb b/vendor/gems/rspec/examples/stack.rb
new file mode 100644
index 000000000..407173f7b
--- /dev/null
+++ b/vendor/gems/rspec/examples/stack.rb
@@ -0,0 +1,36 @@
+class StackUnderflowError < RuntimeError
+end
+
+class StackOverflowError < RuntimeError
+end
+
+class Stack
+
+ def initialize
+ @items = []
+ end
+
+ def push object
+ raise StackOverflowError if @items.length == 10
+ @items.push object
+ end
+
+ def pop
+ raise StackUnderflowError if @items.empty?
+ @items.delete @items.last
+ end
+
+ def peek
+ raise StackUnderflowError if @items.empty?
+ @items.last
+ end
+
+ def empty?
+ @items.empty?
+ end
+
+ def full?
+ @items.length == 10
+ end
+
+end
diff --git a/vendor/gems/rspec/examples/stack_spec.rb b/vendor/gems/rspec/examples/stack_spec.rb
new file mode 100644
index 000000000..22d8a652b
--- /dev/null
+++ b/vendor/gems/rspec/examples/stack_spec.rb
@@ -0,0 +1,97 @@
+require File.dirname(__FILE__) + '/spec_helper'
+require File.dirname(__FILE__) + "/stack"
+
+describe "non-empty Stack", :shared => true do
+ # NOTE that this one auto-generates the description "should not be empty"
+ it { @stack.should_not be_empty }
+
+ it "should return the top item when sent #peek" do
+ @stack.peek.should == @last_item_added
+ end
+
+ it "should NOT remove the top item when sent #peek" do
+ @stack.peek.should == @last_item_added
+ @stack.peek.should == @last_item_added
+ end
+
+ it "should return the top item when sent #pop" do
+ @stack.pop.should == @last_item_added
+ end
+
+ it "should remove the top item when sent #pop" do
+ @stack.pop.should == @last_item_added
+ unless @stack.empty?
+ @stack.pop.should_not == @last_item_added
+ end
+ end
+end
+
+describe "non-full Stack", :shared => true do
+ # NOTE that this one auto-generates the description "should not be full"
+ it { @stack.should_not be_full }
+
+ it "should add to the top when sent #push" do
+ @stack.push "newly added top item"
+ @stack.peek.should == "newly added top item"
+ end
+end
+
+describe Stack, " (empty)" do
+ before(:each) do
+ @stack = Stack.new
+ end
+
+ # NOTE that this one auto-generates the description "should be empty"
+ it { @stack.should be_empty }
+
+ it_should_behave_like "non-full Stack"
+
+ it "should complain when sent #peek" do
+ lambda { @stack.peek }.should raise_error(StackUnderflowError)
+ end
+
+ it "should complain when sent #pop" do
+ lambda { @stack.pop }.should raise_error(StackUnderflowError)
+ end
+end
+
+describe Stack, " (with one item)" do
+ before(:each) do
+ @stack = Stack.new
+ @stack.push 3
+ @last_item_added = 3
+ end
+
+ it_should_behave_like "non-empty Stack"
+ it_should_behave_like "non-full Stack"
+
+end
+
+describe Stack, " (with one item less than capacity)" do
+ before(:each) do
+ @stack = Stack.new
+ (1..9).each { |i| @stack.push i }
+ @last_item_added = 9
+ end
+
+ it_should_behave_like "non-empty Stack"
+ it_should_behave_like "non-full Stack"
+end
+
+describe Stack, " (full)" do
+ before(:each) do
+ @stack = Stack.new
+ (1..10).each { |i| @stack.push i }
+ @last_item_added = 10
+ end
+
+ # NOTE that this one auto-generates the description "should be full"
+ it { @stack.should be_full }
+
+ it_should_behave_like "non-empty Stack"
+
+ it "should complain on #push" do
+ lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
+ end
+
+end
diff --git a/vendor/gems/rspec/examples/stubbing_example.rb b/vendor/gems/rspec/examples/stubbing_example.rb
new file mode 100644
index 000000000..31354aec6
--- /dev/null
+++ b/vendor/gems/rspec/examples/stubbing_example.rb
@@ -0,0 +1,69 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "A consumer of a stub" do
+ it "should be able to stub methods on any Object" do
+ obj = Object.new
+ obj.stub!(:foobar).and_return {:return_value}
+ obj.foobar.should equal(:return_value)
+ end
+end
+
+class StubbableClass
+ def self.find id
+ return :original_return
+ end
+end
+
+describe "A stubbed method on a class" do
+ it "should return the stubbed value" do
+ StubbableClass.stub!(:find).and_return(:stub_return)
+ StubbableClass.find(1).should equal(:stub_return)
+ end
+
+ it "should revert to the original method after each spec" do
+ StubbableClass.find(1).should equal(:original_return)
+ end
+
+ it "can stub! and mock the same message" do
+ StubbableClass.stub!(:msg).and_return(:stub_value)
+ StubbableClass.should_receive(:msg).with(:arg).and_return(:mock_value)
+
+ StubbableClass.msg.should equal(:stub_value)
+ StubbableClass.msg(:other_arg).should equal(:stub_value)
+ StubbableClass.msg(:arg).should equal(:mock_value)
+ StubbableClass.msg(:another_arg).should equal(:stub_value)
+ StubbableClass.msg(:yet_another_arg).should equal(:stub_value)
+ StubbableClass.msg.should equal(:stub_value)
+ end
+end
+
+describe "A mock" do
+ it "can stub!" do
+ mock = mock("stubbing mock")
+ mock.stub!(:msg).and_return(:value)
+ (1..10).each {mock.msg.should equal(:value)}
+ end
+
+ it "can stub! and mock" do
+ mock = mock("stubbing mock")
+ mock.stub!(:stub_message).and_return(:stub_value)
+ mock.should_receive(:mock_message).once.and_return(:mock_value)
+ (1..10).each {mock.stub_message.should equal(:stub_value)}
+ mock.mock_message.should equal(:mock_value)
+ (1..10).each {mock.stub_message.should equal(:stub_value)}
+ end
+
+ it "can stub! and mock the same message" do
+ mock = mock("stubbing mock")
+ mock.stub!(:msg).and_return(:stub_value)
+ mock.should_receive(:msg).with(:arg).and_return(:mock_value)
+ mock.msg.should equal(:stub_value)
+ mock.msg(:other_arg).should equal(:stub_value)
+ mock.msg(:arg).should equal(:mock_value)
+ mock.msg(:another_arg).should equal(:stub_value)
+ mock.msg(:yet_another_arg).should equal(:stub_value)
+ mock.msg.should equal(:stub_value)
+ end
+end
+
+
diff --git a/vendor/gems/rspec/examples/test_case_adapter_example.rb b/vendor/gems/rspec/examples/test_case_adapter_example.rb
new file mode 100644
index 000000000..02ba3be17
--- /dev/null
+++ b/vendor/gems/rspec/examples/test_case_adapter_example.rb
@@ -0,0 +1,26 @@
+#This is an example of using RSpec's expectations in test/unit.
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
+
+require 'test/unit'
+require 'spec/test_case_adapter'
+
+class IntegratingRSpecExpectationsIntoTestCaseTest < Test::Unit::TestCase
+
+ def test_should_support_rspecs_equality_expectations
+ 5.should == 5
+ end
+
+ def test_should_support_rspecs_comparison_expectations
+ 5.should be > 4
+ end
+
+ class Band
+ def players
+ ["John", "Paul", "George", "Ringo"]
+ end
+ end
+
+ def test_should_support_rspecs_collection_expectations
+ Band.new.should have(4).players
+ end
+end
diff --git a/vendor/gems/rspec/examples/test_case_spec.rb b/vendor/gems/rspec/examples/test_case_spec.rb
new file mode 100644
index 000000000..4ffa2c598
--- /dev/null
+++ b/vendor/gems/rspec/examples/test_case_spec.rb
@@ -0,0 +1,65 @@
+require File.dirname(__FILE__) + '/spec_helper'
+require 'test/unit'
+
+class RSpecIntegrationTest < Test::Unit::TestCase
+ def self.fixtures(*args)
+ @@fixtures = true
+ end
+
+ def self.verify_class_method
+ @@fixtures.should == true
+ end
+
+ def setup
+ @test_case_setup_called = true
+ end
+
+ def teardown
+ @test_case_teardown_called = true
+ end
+
+ def run(result)
+ end
+
+ def helper_method
+ @helper_method_called = true
+ end
+end
+
+module RandomHelperModule
+ def random_task
+ @random_task_called = true
+ end
+end
+
+describe "RSpec should integrate with Test::Unit::TestCase" do
+ inherit RSpecIntegrationTest
+ include RandomHelperModule
+
+ fixtures :some_table
+
+ prepend_before(:each) {setup}
+
+ before(:each) do
+ @rspec_setup_called = true
+ end
+
+ it "TestCase#setup should be called." do
+ @test_case_setup_called.should be_true
+ @rspec_setup_called.should be_true
+ end
+
+ it "RSpec should be able to access TestCase methods" do
+ helper_method
+ @helper_method_called.should be_true
+ end
+
+ it "RSpec should be able to accept included modules" do
+ random_task
+ @random_task_called.should be_true
+ end
+
+ after(:each) do
+ RSpecIntegrationTest.verify_class_method
+ end
+end