Sha256: cd70f77aa72e48706e7024e61cad934c1ad10fa8e8e6786c0a0de5e87924689c

Contents?: true

Size: 1.85 KB

Versions: 4

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'
require 'active_support'
require 'napa/deprecations/napa_setup'

describe Napa::Deprecations do
  before do
    allow(File).to receive(:exists?).and_return(true)

    @apprb_stub = [
      "require 'bundler/setup'",
      "Bundler.setup(:default)",
      "require 'napa/setup'",
      "Bundler.require(:default, Napa.env.to_sym)",
      "require 'napa'",
      "Napa.load_environment",
      "Dir['./config/initializers/**/*.rb'].map { |file| require file }",
      "Dir['./config/middleware/**/*.rb'].map { |file| require file }",
      "relative_load_paths = %w(app/apis app/entities app/models app/workers app/representers lib)",
      "ActiveSupport::Dependencies.autoload_paths += relative_load_paths"
    ]
  end

  describe '.napa_setup_check' do
    it 'does not raise a deprecation warning if all the required_patterns are matched' do
      allow(File).to receive(:readlines).with('./app.rb').and_return(@apprb_stub)
      expect(ActiveSupport::Deprecation).to_not receive(:warn)
      Napa::Deprecations.napa_setup_check
    end

    it 'raises a deprecation warning if any of the required_patterns are missing' do
      (0..@apprb_stub.count - 1).each do |line_num|
        apprb_missing_line = @apprb_stub
        apprb_missing_line.delete_at(line_num)
        allow(File).to receive(:readlines).with('./app.rb').and_return(apprb_missing_line)
        expect(ActiveSupport::Deprecation).to receive(:warn)

        Napa::Deprecations.napa_setup_check
      end
    end

    it 'raises a deprecation warning if any of the expired_patterns are matched' do
      Napa::Deprecations::EXPIRED_PATTERNS.each do |pattern|
        app_rb_stub = [pattern]

        allow(File).to receive(:readlines).with('./app.rb').and_return(app_rb_stub)
        expect(ActiveSupport::Deprecation).to receive(:warn)

        Napa::Deprecations.napa_setup_check
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
napa-0.5.0 spec/deprecations/napa_setup_spec.rb
napa-0.4.3 spec/deprecations/napa_setup_spec.rb
napa-0.4.1 spec/deprecations/napa_setup_spec.rb
napa-0.4.0 spec/deprecations/napa_setup_spec.rb