Sha256: 88b48f1acbb7a8b0b35641a3baedeab83d2b8ef7ac124ffa99e4fc29c676afff

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

module Draper
  describe HelperProxy do
    describe "#initialize" do
      it "sets the view context" do
        view_context = double
        helper_proxy = HelperProxy.new(view_context)

        expect(helper_proxy.send(:view_context)).to be view_context
      end
    end

    describe "#method_missing" do
      protect_class HelperProxy

      it "proxies methods to the view context" do
        view_context = double
        helper_proxy = HelperProxy.new(view_context)

        allow(view_context).to receive(:foo) { |arg| arg }
        expect(helper_proxy.foo(:passed)).to be :passed
      end

      it "passes blocks" do
        view_context = double
        helper_proxy = HelperProxy.new(view_context)

        allow(view_context).to receive(:foo) { |&block| block.call }
        expect(helper_proxy.foo{:yielded}).to be :yielded
      end

      it "defines the method for better performance" do
        helper_proxy = HelperProxy.new(double(foo: "bar"))

        expect(HelperProxy.instance_methods).not_to include :foo
        helper_proxy.foo
        expect(HelperProxy.instance_methods).to include :foo
      end
    end

    describe "#respond_to_missing?" do
      it "allows #method to be called on the view context" do
        helper_proxy = HelperProxy.new(double(foo: "bar"))

        expect(helper_proxy.respond_to?(:foo)).to be_truthy
      end
    end

    describe "proxying methods which are overriding" do
      it "proxies :capture" do
        view_context = double
        helper_proxy = HelperProxy.new(view_context)

        allow(view_context).to receive(:capture) { |*args, &block| [*args, block.call] }
        expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \
          be_eql [:first_arg, :second_arg, :yielded]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
draper-4.0.2 spec/draper/helper_proxy_spec.rb
draper-4.0.1 spec/draper/helper_proxy_spec.rb
draper-4.0.0 spec/draper/helper_proxy_spec.rb
draper-3.1.0 spec/draper/helper_proxy_spec.rb
draper-3.0.1 spec/draper/helper_proxy_spec.rb
draper-3.0.0 spec/draper/helper_proxy_spec.rb