Sha256: 8573fa7d60e138b12af23aa9d5ca80cf6266ce39e6aa74d25560c65f78d9517a

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require "spec_helper"

module Spank
  describe Proxy do
    let(:sut) { Proxy.new(target) }
    let(:target) { fake }

    context "when invoking a method" do
      before { sut.greet('blah') }

      it "should send the message to the target" do
        target.should have_received(:greet, 'blah')
      end
    end

    context "when an interceptor is registered" do
      context "when invoking a method" do
        let(:interceptor) { fake }

        before :each do
          sut.add_interceptor(:greet, interceptor)
          sut.greet("blah")
        end
        it "should allow the interceptor to intercept the call" do
          interceptor.should have_received(:intercept)
        end
      end
      context "when invoking a method with a block" do
        it "should pass the block to the target" do
          proxy = Proxy.new([])
          expect do
            proxy.each do |x|
              raise StandardError
            end
          end.to raise_error
        end
      end
    end

    context "when invoking a method that is not defined on the target" do
      it "should raise an error" do
        expect { Proxy.new("blah").goodbye }.to raise_error
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spank-0.0.1369197619 spec/unit/proxy_spec.rb
spank-0.0.1369197478 spec/unit/proxy_spec.rb
spank-0.0.2 spec/unit/proxy_spec.rb
spank-0.0.1 spec/unit/proxy_spec.rb