Sha256: 30e6db54aa7c2ffe80df3154e09c9b235bdb33eebb1b26f653ece53ea17dc5a8

Contents?: true

Size: 1.42 KB

Versions: 11

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require "hanami"

RSpec.describe "App view / Context / Assets", :app_integration do
  before do
    module TestApp
      class App < Hanami::App
      end
    end

    Hanami.prepare

    module TestApp
      module Views
        class Context < Hanami::View::Context
        end
      end
    end
  end

  let(:context_class) { TestApp::Views::Context }
  subject(:context) { context_class.new }

  describe "#assets" do
    context "without assets provider" do
      it "raises error" do
        expect { context.assets }
          .to raise_error(Hanami::ComponentLoadError, /hanami-assets/)
      end
    end

    context "with assets provider" do
      before do
        Hanami.app.register_provider(:assets) do
          start do
            register "assets", Object.new
          end
        end
      end

      it "is the app assets by default" do
        expect(context.assets).to be TestApp::App[:assets]
      end

      context "injected assets" do
        subject(:context) {
          context_class.new(assets: assets)
        }

        let(:assets) { double(:assets) }

        it "is the injected assets" do
          expect(context.assets).to be assets
        end

        context "rebuilt context" do
          subject(:new_context) { context.with }

          it "retains the injected assets" do
            expect(new_context.assets).to be assets
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hanami-2.1.0.beta1 spec/integration/view/context/assets_spec.rb
hanami-2.0.3 spec/integration/view/context/assets_spec.rb
hanami-2.0.2 spec/integration/view/context/assets_spec.rb
hanami-2.0.1 spec/integration/view/context/assets_spec.rb
hanami-2.0.0 spec/integration/view/context/assets_spec.rb
hanami-2.0.0.rc1 spec/integration/view/context/assets_spec.rb
hanami-2.0.0.beta4 spec/integration/view/context/assets_spec.rb
hanami-2.0.0.beta3 spec/integration/view/context/assets_spec.rb
hanami-2.0.0.beta2 spec/new_integration/view/context/assets_spec.rb
hanami-2.0.0.beta1.1 spec/new_integration/view/context/assets_spec.rb
hanami-2.0.0.beta1 spec/new_integration/view/context/assets_spec.rb