Sha256: abed1139eedbd0ca765d074171fa911cc7b9fc4763c64a7d6265f36a9e771c01

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require "spec_helper"

module Spank
  describe Proxy do
    let(:sut) { Proxy.new(target) }
    let(:target) { double("target", :greet => nil) }

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

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

    context "when an interceptor is registered" do
      context "when invoking a method" do
        let(:interceptor) { double('interceptor', :intercept => "") }

        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

2 entries across 2 versions & 1 rubygems

Version Path
spank-0.0.1393558686 spec/unit/proxy_spec.rb
spank-0.0.1385937112 spec/unit/proxy_spec.rb