Sha256: 8fe0b72ed27170e4053003c2d537067394bff287b3ff69b69b2b131b57c0fbd2

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

dir = File.dirname(__FILE__)
require "#{dir}/../example_helper"

module RR
describe ProbeCreator, :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 ProbeCreator, ".new without block" do
  it_should_behave_like "RR::ProbeCreator"

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

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

  before do
    def @subject.foobar(*args)
      :original_foobar
    end
    @creator = ProbeCreator.new(@space, @subject) do |c|
      c.foobar(1, 2)
      c.foobar(1)
      c.foobar.with_any_args
    end
  end

  it "creates doubles" do
    @subject.foobar(1, 2).should == :original_foobar
    @subject.foobar(1).should == :original_foobar
    @subject.foobar(:something).should == :original_foobar
    proc {@subject.foobar(:nasty)}.should raise_error
  end
end

describe ProbeCreator, ".new where method takes a block" do
  it_should_behave_like "RR::ProbeCreator"

  before do
    def @subject.foobar(*args, &block)
      yield(*args)
    end
    @creator = ProbeCreator.new(@space, @subject)
  end

  it "calls the block" do
    @creator.foobar(1, 2)
    @subject.foobar(1, 2) {|arg1, arg2| [arg2, arg1]}.should == [2, 1]
  end
end


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

  it "sets expectations on the subject while calling the original method" do
    def @subject.foobar(*args); :baz; end
    @creator.foobar(1, 2).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.1 examples/rr/probe_creator_example.rb
rr-0.1.5 examples/rr/probe_creator_example.rb
rr-0.1.2 examples/rr/probe_creator_example.rb
rr-0.1.3 examples/rr/probe_creator_example.rb
rr-0.1.4 examples/rr/probe_creator_example.rb