Sha256: 2200627dbbbf5eefeaef5bafd440a6d8b73e54b1d32c72514828d9609b16550d

Contents?: true

Size: 1.34 KB

Versions: 27

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "mime/types"
require "minitest_helper"

describe MIME::Types, "lazy loading" do
  def setup
    ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "true"
  end

  def teardown
    reset_mime_types
    ENV.delete("RUBY_MIME_TYPES_LAZY_LOAD")
  end

  def reset_mime_types
    MIME::Types.instance_variable_set(:@__types__, nil)
    MIME::Types.send(:load_default_mime_types)
  end

  describe ".lazy_load?" do
    it "is true when RUBY_MIME_TYPES_LAZY_LOAD is set" do
      assert_output "", /RUBY_MIME_TYPES_LAZY_LOAD/ do
        assert_equal true, MIME::Types.send(:lazy_load?)
      end
    end

    it "is nil when RUBY_MIME_TYPES_LAZY_LOAD is unset" do
      ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = nil
      assert_output "", "" do
        assert_nil MIME::Types.send(:lazy_load?)
      end
    end

    it "is false when RUBY_MIME_TYPES_LAZY_LOAD is false" do
      ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "false"
      assert_output "", /RUBY_MIME_TYPES_LAZY_LOAD/ do
        assert_equal false, MIME::Types.send(:lazy_load?)
      end
    end
  end

  it "loads lazily when RUBY_MIME_TYPES_LAZY_LOAD is set" do
    MIME::Types.instance_variable_set(:@__types__, nil)
    assert_nil MIME::Types.instance_variable_get(:@__types__)
    refute_nil MIME::Types["text/html"].first
    refute_nil MIME::Types.instance_variable_get(:@__types__)
  end
end

Version data entries

27 entries across 27 versions & 7 rubygems

Version Path
mime-types-3.6.0 test/test_mime_types_lazy.rb
mime-types-3.6.0.beta1 test/test_mime_types_lazy.rb
kinetic_sdk-5.0.27 gems/mime-types-3.5.2/test/test_mime_types_lazy.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mime-types-3.5.2/test/test_mime_types_lazy.rb
kinetic_sdk-5.0.26 gems/mime-types-3.5.2/test/test_mime_types_lazy.rb
kinetic_sdk-5.0.25 gems/mime-types-3.5.2/test/test_mime_types_lazy.rb
kinetic_sdk-5.0.24 gems/mime-types-3.5.2/test/test_mime_types_lazy.rb
kinetic_sdk-5.0.23 gems/mime-types-3.5.2/test/test_mime_types_lazy.rb
mime-types-3.5.2 test/test_mime_types_lazy.rb
kinetic_sdk-5.0.22 gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
mime-types-3.5.1 test/test_mime_types_lazy.rb
mime-types-3.5.0 test/test_mime_types_lazy.rb
kinetic_sdk-5.0.21 gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
kinetic_sdk-5.0.20 gems/mime-types-3.4.1/test/test_mime_types_lazy.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/mime-types-3.4.1/test/test_mime_types_lazy.rb