Sha256: be0ccbcd39c675f29538be0db62a8181fe3a91781ce2df92accb218e3f205d28

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require "spec_helper"

module Chanko
  describe Function do
    let(:unit) do
      Loader.load(:example_unit)
    end

    let(:context) do
      Class.new(ActionView::Base) do
        include Chanko::Invoker

        def current_unit
          units.last
        end

        def units
          @units ||= []
        end

        def path
          view_paths.first.to_s
        end
      end.new
    end

    let(:context_without_view_paths) do
      Class.new do
        include Chanko::Invoker

        def units
          @units ||= []
        end
      end.new
    end

    let(:options) do
      { :type => :plain }
    end

    describe ".invoke" do
      it "invokes block with given context and stacked unit" do
        described_class.new(unit, :label) { current_unit }.invoke(context, options).should == unit
      end

      context "when context is a view" do
        it "invokes with unit's view path" do
          described_class.new(unit, :label) { path }.invoke(context, options).should == unit.view_path
        end
      end

      context "when context does not have view_paths" do
        it "invokes successfully" do
          described_class.new(unit, :label) { "test" }.
            invoke(context_without_view_paths, options).should == "test"
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
chanko-2.0.6 spec/chanko/function_spec.rb
chanko-2.0.5 spec/chanko/function_spec.rb
chanko-2.0.4 spec/chanko/function_spec.rb
chanko-2.0.3 spec/chanko/function_spec.rb
chanko-2.0.2 spec/chanko/function_spec.rb
chanko-2.0.1 spec/chanko/function_spec.rb
chanko-2.0.0 spec/chanko/function_spec.rb