Sha256: a7de51000c60582775d6653e2632778e95379132271967f5ba734bcb4034085c

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

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

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

      it "sends the message to the target" do
        expect(target).to 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
          subject.add_interceptor(:greet, interceptor)
          subject.greet("blah")
        end
        it "allows the interceptor to intercept the call" do
          expect(interceptor).to have_received(:intercept)
        end
      end

      context "when invoking a method with a block" do
        it "passes the block to the target" do
          proxy = Proxy.new([])
          expect do
            proxy.each do |x|
              raise StandardError
            end
          end.to raise_error(StandardError)
        end
      end
    end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spank-1.1.0 spec/unit/proxy_spec.rb
spank-1.0.1441140881 spec/unit/proxy_spec.rb
spank-1.0.1441140857 spec/unit/proxy_spec.rb
spank-1.0.1441140848 spec/unit/proxy_spec.rb
spank-1.0.1441140841 spec/unit/proxy_spec.rb
spank-1.0.1441140834 spec/unit/proxy_spec.rb
spank-1.0.1441140824 spec/unit/proxy_spec.rb
spank-1.0.1441140809 spec/unit/proxy_spec.rb
spank-1.0.1441140804 spec/unit/proxy_spec.rb
spank-1.0.1441140793 spec/unit/proxy_spec.rb