diff options
Diffstat (limited to 'vendor/plugins/rspec/examples/passing')
28 files changed, 873 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/examples/passing/custom_formatter.rb b/vendor/plugins/rspec/examples/passing/custom_formatter.rb new file mode 100644 index 000000000..4c7482190 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/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 examples/failing -r examples/passing/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/plugins/rspec/examples/passing/custom_matchers.rb b/vendor/plugins/rspec/examples/passing/custom_matchers.rb new file mode 100644 index 000000000..075bb542d --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/custom_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/plugins/rspec/examples/passing/dynamic_spec.rb b/vendor/plugins/rspec/examples/passing/dynamic_spec.rb new file mode 100644 index 000000000..7c0372631 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/dynamic_spec.rb @@ -0,0 +1,7 @@ +describe "The square root" do + (1..10).each do |n| + it "of #{n*n} should be #{n}" do + Math.sqrt(n*n).should == n + end + end +end diff --git a/vendor/plugins/rspec/examples/passing/file_accessor.rb b/vendor/plugins/rspec/examples/passing/file_accessor.rb new file mode 100644 index 000000000..e67f44735 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/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 'examples/passing/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/plugins/rspec/examples/passing/file_accessor_spec.rb b/vendor/plugins/rspec/examples/passing/file_accessor_spec.rb new file mode 100644 index 000000000..84428b6fc --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/file_accessor_spec.rb @@ -0,0 +1,37 @@ +require 'examples/passing/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/plugins/rspec/examples/passing/filtered_formatter.rb b/vendor/plugins/rspec/examples/passing/filtered_formatter.rb new file mode 100644 index 000000000..eaeabbcfa --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/filtered_formatter.rb @@ -0,0 +1,17 @@ +require 'spec/runner/formatter/nested_text_formatter' + +class FilteredFormatter < Spec::Runner::Formatter::NestedTextFormatter + def add_example_group(example_group) + if example_group.options[:show] == false + @showing = false + else + @showing = true + puts example_group.description + end + end + + def example_passed(example) + puts " " << example.description if @showing unless example.options[:show] == false + end +end + diff --git a/vendor/plugins/rspec/examples/passing/filtered_formatter_example.rb b/vendor/plugins/rspec/examples/passing/filtered_formatter_example.rb new file mode 100644 index 000000000..3c9d067f1 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/filtered_formatter_example.rb @@ -0,0 +1,31 @@ +# This demonstrates how you can write custom formatters to handle arbitrary +# options passed to the +describe+ and +it+ methods. To see it in action, stand +# in the project root and say: +# +# bin/spec -r examples/passing/filtered_formatter.rb examples/passing/filtered_formatter_example.rb -f FilteredFormatter +# +# You should only see the examples and groups below that are not explicitly +# marked :show => false +# +# group 1 +# example 1 a +# group 3 +# example 3 + + +describe "group 1", :show => true do + it "example 1 a", :show => true do + end + it "example 1 b", :show => false do + end +end + +describe "group 2", :show => false do + it "example 2" do + end +end + +describe "group 3" do + it "example 3" do + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/examples/passing/greeter_spec.rb b/vendor/plugins/rspec/examples/passing/greeter_spec.rb new file mode 100644 index 000000000..7d67e3187 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/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/plugins/rspec/examples/passing/helper_method_example.rb b/vendor/plugins/rspec/examples/passing/helper_method_example.rb new file mode 100644 index 000000000..eb3dca92f --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/helper_method_example.rb @@ -0,0 +1,12 @@ +module HelperMethodExample + describe "an example group 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 +end + diff --git a/vendor/plugins/rspec/examples/passing/implicit_docstrings_example.rb b/vendor/plugins/rspec/examples/passing/implicit_docstrings_example.rb new file mode 100644 index 000000000..889cef425 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/implicit_docstrings_example.rb @@ -0,0 +1,16 @@ +# Run "spec implicit_docstrings_example.rb --format specdoc" to see the output of this file + +describe "Examples with no docstrings generate their own:" do + + specify { 3.should be < 5 } + + specify { ["a"].should include("a") } + + specify { [1,2,3].should respond_to(:size) } + +end + +describe 1 do + it { should == 1 } + it { should be < 2} +end diff --git a/vendor/plugins/rspec/examples/passing/io_processor.rb b/vendor/plugins/rspec/examples/passing/io_processor.rb new file mode 100644 index 000000000..6b15147b6 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/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/plugins/rspec/examples/passing/io_processor_spec.rb b/vendor/plugins/rspec/examples/passing/io_processor_spec.rb new file mode 100644 index 000000000..1f5020e76 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/io_processor_spec.rb @@ -0,0 +1,20 @@ +require 'examples/passing/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/plugins/rspec/examples/passing/mocking_example.rb b/vendor/plugins/rspec/examples/passing/mocking_example.rb new file mode 100644 index 000000000..1d342c735 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/mocking_example.rb @@ -0,0 +1,25 @@ +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/plugins/rspec/examples/passing/multi_threaded_example_group_runner.rb b/vendor/plugins/rspec/examples/passing/multi_threaded_example_group_runner.rb new file mode 100644 index 000000000..d5458ddf8 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/multi_threaded_example_group_runner.rb @@ -0,0 +1,26 @@ +class MultiThreadedExampleGroupRunner < Spec::Runner::ExampleGroupRunner + def initialize(options, arg) + super(options) + # configure these + @thread_count = 4 + @thread_wait = 0 + end + + def run + @threads = [] + q = Queue.new + example_groups.each { |b| q << b} + success = true + @thread_count.times do + @threads << Thread.new(q) do |queue| + while not queue.empty? + example_group = queue.pop + success &= example_group.suite.run(nil) + end + end + sleep @thread_wait + end + @threads.each {|t| t.join} + success + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/examples/passing/nested_classes_example.rb b/vendor/plugins/rspec/examples/passing/nested_classes_example.rb new file mode 100644 index 000000000..ce5499591 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/nested_classes_example.rb @@ -0,0 +1,35 @@ +require 'examples/passing/stack' + +class StackExamples < Spec::ExampleGroup + describe(Stack) + before(:each) do + @stack = Stack.new + end +end + +class EmptyStackExamples < StackExamples + describe("when empty") + it "should be empty" do + @stack.should be_empty + end +end + +class AlmostFullStackExamples < StackExamples + describe("when almost full") + before(:each) do + (1..9).each {|n| @stack.push n} + end + it "should be full" do + @stack.should_not be_full + end +end + +class FullStackExamples < StackExamples + describe("when full") + before(:each) do + (1..10).each {|n| @stack.push n} + end + it "should be full" do + @stack.should be_full + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/examples/passing/options_example.rb b/vendor/plugins/rspec/examples/passing/options_example.rb new file mode 100644 index 000000000..bed3077eb --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/options_example.rb @@ -0,0 +1,29 @@ +# This demonstrates the use of the options hash to support custom reporting. +# To see the result, run this command from the project root: +# +# bin/spec --require examples/passing/options_formatter.rb examples/passing/options_example.rb \ +# --format OptionsFormatter + +describe "this group will be reported", :report => true do + it "this example will be reported", :report => true do + # no-op + end + + it "this example will not be reported", :report => false do + # no-op + end + + it "this example will also not be reported", :foo => 'bar' do + # no-op + end + + it "this example will also also not be reported" do + # no-op + end +end + +describe "this group will not be reported", :report => false do + it "though this example will", :report => true do + # no-op + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/examples/passing/options_formatter.rb b/vendor/plugins/rspec/examples/passing/options_formatter.rb new file mode 100644 index 000000000..b88bebbc5 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/options_formatter.rb @@ -0,0 +1,20 @@ +# This is an example of how you can use a custom formatter to do custom +# reporting. This formatter will only report example groups and examples that +# have :report => true (or anything truthy) in the declaration. See +# options_example.rb in this directory. + +require 'spec/runner/formatter/base_text_formatter' + +class OptionsFormatter < Spec::Runner::Formatter::BaseTextFormatter + def example_started(proxy) + if proxy.options[:report] + puts proxy.description + end + end + + def example_group_started(proxy) + if proxy.options[:report] + puts proxy.description + end + end +end diff --git a/vendor/plugins/rspec/examples/passing/partial_mock_example.rb b/vendor/plugins/rspec/examples/passing/partial_mock_example.rb new file mode 100644 index 000000000..38aafa149 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/partial_mock_example.rb @@ -0,0 +1,27 @@ +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/plugins/rspec/examples/passing/pending_example.rb b/vendor/plugins/rspec/examples/passing/pending_example.rb new file mode 100644 index 000000000..7ce382742 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/pending_example.rb @@ -0,0 +1,18 @@ +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/plugins/rspec/examples/passing/predicate_example.rb b/vendor/plugins/rspec/examples/passing/predicate_example.rb new file mode 100644 index 000000000..f10c386f3 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/predicate_example.rb @@ -0,0 +1,25 @@ +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/plugins/rspec/examples/passing/shared_example_group_example.rb b/vendor/plugins/rspec/examples/passing/shared_example_group_example.rb new file mode 100644 index 000000000..f034a11b5 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/shared_example_group_example.rb @@ -0,0 +1,79 @@ +module SharedExampleGroupExample + class OneThing + def what_things_do + "stuff" + end + end + + class AnotherThing + def what_things_do + "stuff" + end + end + + class YetAnotherThing + def what_things_do + "stuff" + end + end + + # A SharedExampleGroup is an example group that doesn't get run. + # You can create one like this: + share_examples_for "most things" do + def helper_method + "helper method" + end + + it "should do what things do" do + @thing.what_things_do.should == "stuff" + end + end + + # A SharedExampleGroup is also a module. If you create one like this it gets + # assigned to the constant MostThings + share_as :MostThings 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 + # Now you can include the shared example group like this, which + # feels more like what you might say ... + it_should_behave_like "most things" + + before(:each) { @thing = OneThing.new } + + it "should have access to helper methods defined in the shared example group" do + helper_method.should == "helper method" + end + end + + describe AnotherThing do + # ... or you can include the example group like this, which + # feels more like the programming language we love. + it_should_behave_like MostThings + + before(:each) { @thing = AnotherThing.new } + + it "should have access to helper methods defined in the shared example group" do + helper_method.should == "helper method" + end + end + + describe YetAnotherThing do + # ... or you can include the example group like this, which + # feels more like the programming language we love. + include MostThings + + before(:each) { @thing = AnotherThing.new } + + it "should have access to helper methods defined in the shared example group" do + helper_method.should == "helper method" + end + end +end diff --git a/vendor/plugins/rspec/examples/passing/shared_stack_examples.rb b/vendor/plugins/rspec/examples/passing/shared_stack_examples.rb new file mode 100644 index 000000000..e14fd146d --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/shared_stack_examples.rb @@ -0,0 +1,36 @@ +shared_examples_for "non-empty Stack" do + + 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 + +shared_examples_for "non-full Stack" do + + 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
\ No newline at end of file diff --git a/vendor/plugins/rspec/examples/passing/simple_matcher_example.rb b/vendor/plugins/rspec/examples/passing/simple_matcher_example.rb new file mode 100644 index 000000000..5a0fc0fa5 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/simple_matcher_example.rb @@ -0,0 +1,29 @@ +describe "arrays" do + def contain_same_elements_as(expected) + simple_matcher "array with same elements in any order as #{expected.inspect}" do |actual| + if actual.size == expected.size + a, e = actual.dup, expected.dup + until e.empty? do + if i = a.index(e.pop) then a.delete_at(i) end + end + a.empty? + else + false + end + end + end + + describe "can be matched by their contents disregarding order" do + subject { [1,2,2,3] } + it { should contain_same_elements_as([1,2,2,3]) } + it { should contain_same_elements_as([2,3,2,1]) } + it { should_not contain_same_elements_as([3,3,2,1]) } + end + + describe "fail the match with different contents" do + subject { [1,2,3] } + it { should_not contain_same_elements_as([2,3,4])} + it { should_not contain_same_elements_as([1,2,2,3])} + it { should_not contain_same_elements_as([1,2])} + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/examples/passing/stack.rb b/vendor/plugins/rspec/examples/passing/stack.rb new file mode 100644 index 000000000..407173f7b --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/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/plugins/rspec/examples/passing/stack_spec.rb b/vendor/plugins/rspec/examples/passing/stack_spec.rb new file mode 100644 index 000000000..6d0d06366 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/stack_spec.rb @@ -0,0 +1,63 @@ +require 'examples/passing/stack' +require 'examples/passing/shared_stack_examples' + +describe Stack, " (empty)" do + before(:each) do + @stack = Stack.new + end + + # This uses @stack (because the described class is Stack) auto-generates the + # description "should be empty" + it { 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/plugins/rspec/examples/passing/stack_spec_with_nested_example_groups.rb b/vendor/plugins/rspec/examples/passing/stack_spec_with_nested_example_groups.rb new file mode 100644 index 000000000..6e36df789 --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/stack_spec_with_nested_example_groups.rb @@ -0,0 +1,66 @@ +require 'examples/passing/stack' +require 'examples/passing/shared_stack_examples' + +describe Stack do + + before(:each) do + @stack = Stack.new + end + + describe "(empty)" do + + 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 "(with one item)" do + + before(:each) do + @stack.push 3 + @last_item_added = 3 + end + + it_should_behave_like "non-empty Stack" + it_should_behave_like "non-full Stack" + + end + + describe "(with one item less than capacity)" do + + before(:each) do + (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 "(full)" do + + before(:each) do + (1..10).each { |i| @stack.push i } + @last_item_added = 10 + end + + 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 + +end diff --git a/vendor/plugins/rspec/examples/passing/stubbing_example.rb b/vendor/plugins/rspec/examples/passing/stubbing_example.rb new file mode 100644 index 000000000..dab8982ee --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/stubbing_example.rb @@ -0,0 +1,67 @@ +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/plugins/rspec/examples/passing/yielding_example.rb b/vendor/plugins/rspec/examples/passing/yielding_example.rb new file mode 100644 index 000000000..e7b43fffa --- /dev/null +++ b/vendor/plugins/rspec/examples/passing/yielding_example.rb @@ -0,0 +1,31 @@ +class MessageAppender + + def initialize(appendage) + @appendage = appendage + end + + def append_to(message) + if_told_to_yield do + message << @appendage + end + end + +end + +describe "a message expectation yielding to a block" do + it "should yield if told to" do + appender = MessageAppender.new("appended to") + appender.should_receive(:if_told_to_yield).and_yield + message = "" + appender.append_to(message) + message.should == "appended to" + end + + it "should not yield if not told to" do + appender = MessageAppender.new("appended to") + appender.should_receive(:if_told_to_yield) + message = "" + appender.append_to(message) + message.should == "" + end +end
\ No newline at end of file |