Sha256: 0def7a33c335cc34db73d551f94ccf1e9fce46e28eabac6a96c3575ef69adc06

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

require "examples/example_helper"

module RR
describe MockCreator, :shared => true do
  before(:each) do
    @space = Space.new
    @subject = Object.new
  end

  it "initializes creator with passed in object" do
    class << @creator
      attr_reader :subject
    end
    @creator.subject.should === @subject
  end
end

describe MockCreator, ".new without block" do
  it_should_behave_like "RR::MockCreator"

  before do
    @creator = MockCreator.new(@space, @subject)
  end
end

describe MockCreator, ".new with block" do
  it_should_behave_like "RR::MockCreator"

  before do
    @creator = MockCreator.new(@space, @subject) do |c|
      c.foobar(1, 2) {:one_two}
      c.foobar(1) {:one}
      c.foobar.with_any_args {:default}
      c.baz() {:baz_result}
    end
  end

  it "creates doubles" do
    @subject.foobar(1, 2).should == :one_two
    @subject.foobar(1).should == :one
    @subject.foobar(:something).should == :default
    @subject.baz.should == :baz_result
  end
end


describe MockCreator, "#method_missing" do
  it_should_behave_like "RR::MockCreator"
  
  before do
    @subject = Object.new
    @creator = MockCreator.new(@space, @subject)
  end

  it "sets expectations on the subject" do
    @creator.foobar(1, 2) {:baz}.twice

    @subject.foobar(1, 2).should == :baz
    @subject.foobar(1, 2).should == :baz
    proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
  end
end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rr-0.1.7 examples/rr/mock_creator_example.rb
rr-0.1.10 examples/rr/mock_creator_example.rb
rr-0.1.11 examples/rr/mock_creator_example.rb
rr-0.1.8 examples/rr/mock_creator_example.rb
rr-0.1.9 examples/rr/mock_creator_example.rb