Sha256: 591404384a20773a1899ef9bcf2b8cec680459ab646517975feed92c053b1fff

Contents?: true

Size: 1.99 KB

Versions: 22

Compression:

Stored size: 1.99 KB

Contents

RSpec.describe "App autoloader", :app_integration do
  specify "Classes are autoloaded through direct reference, including through components resolved from the container" do
    with_tmp_directory(Dir.mktmpdir) do
      write "config/app.rb", <<~RUBY
        require "hanami"

        module TestApp
          class App < Hanami::App
            # Use a custom inflection to ensure this is respected by the autoloader
            config.inflections do |inflections|
              inflections.acronym "NBA"
            end
          end
        end
      RUBY

      write "lib/non_app/thing.rb", <<~RUBY
        module NonApp
          class Thing
          end
        end
      RUBY

      write "lib/test_app/nba_jam/get_that_outta_here.rb", <<~RUBY
        module TestApp
          module NBAJam
            class GetThatOuttaHere
            end
          end
        end
      RUBY

      write "slices/admin/lib/operations/create_game.rb", <<~RUBY
        module Admin
          module Operations
            class CreateGame
              def call
                Entities::Game.new
              end
            end
          end
        end
      RUBY

      write "slices/admin/lib/entities/game.rb", <<~RUBY
        # auto_register: false

        module Admin
          module Entities
            class Game
            end
          end
        end
      RUBY

      write "slices/admin/lib/entities/quarter.rb", <<~RUBY
        # auto_register: false

        module Admin
          module Entities
            class Quarter
            end
          end
        end
      RUBY

      require "hanami/prepare"

      expect(require("non_app/thing")).to be true
      expect(NonApp::Thing).to be

      expect(TestApp::NBAJam::GetThatOuttaHere).to be

      expect(Admin::Slice["operations.create_game"]).to be_an_instance_of(Admin::Operations::CreateGame)
      expect(Admin::Slice["operations.create_game"].call).to be_an_instance_of(Admin::Entities::Game)

      expect(Admin::Entities::Quarter).to be
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hanami-2.2.1 spec/integration/container/autoloader_spec.rb
hanami-2.2.0 spec/integration/container/autoloader_spec.rb
hanami-2.2.0.rc1 spec/integration/container/autoloader_spec.rb
hanami-2.2.0.beta2 spec/integration/container/autoloader_spec.rb
hanami-2.2.0.beta1 spec/integration/container/autoloader_spec.rb
hanami-2.1.0 spec/integration/container/autoloader_spec.rb
hanami-2.1.0.rc3 spec/integration/container/autoloader_spec.rb
hanami-2.1.0.rc2 spec/integration/container/autoloader_spec.rb
hanami-2.1.0.rc1 spec/integration/container/autoloader_spec.rb
hanami-2.1.0.beta2.1 spec/integration/container/autoloader_spec.rb
hanami-2.1.0.beta2 spec/integration/container/autoloader_spec.rb
hanami-2.1.0.beta1 spec/integration/container/autoloader_spec.rb
hanami-2.0.3 spec/integration/container/autoloader_spec.rb
hanami-2.0.2 spec/integration/container/autoloader_spec.rb
hanami-2.0.1 spec/integration/container/autoloader_spec.rb
hanami-2.0.0 spec/integration/container/autoloader_spec.rb
hanami-2.0.0.rc1 spec/integration/container/autoloader_spec.rb
hanami-2.0.0.beta4 spec/integration/container/autoloader_spec.rb
hanami-2.0.0.beta3 spec/integration/container/autoloader_spec.rb
hanami-2.0.0.beta2 spec/new_integration/container/autoloader_spec.rb