Sha256: 754c826870139e1f93deb21f3dcf179d521c8cfe7cc5f103f05fdc07e6b65ea0

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'
require 'support/loader'

RSpec.describe Support::Loader do
  before do
    if Object.const_defined?(:ApplicationHelper)
      Object.send(:remove_const, :ApplicationHelper)
    end
  end

  subject { described_class.new(pattern) }

  describe '#find' do
    context 'there are files to process' do
      let(:pattern) { File.join(fixture_path, 'project/app/helpers/*.rb') }

      it 'loads and returns modules' do
        expect(Object.const_defined?(:ApplicationHelper)).to be false

        result = subject.find

        expect(Object.const_defined?(:ApplicationHelper)).to be true
        expect(result).to eq [ApplicationHelper]
      end

      it 'does not reload modules if they have not unchanged' do
        expect(subject.reload?).to be true

        subject.find

        expect(subject.reload?).to be false
      end

      it 'reloads modules if they have changed' do
        expect(subject.reload?).to be true

        subject.find

        expect(File).to receive(:mtime).and_return(Time.now)
        expect(subject.reload?).to be true
      end
    end

    context 'there are no files to process' do
      let(:pattern) { File.join(fixture_path, 'project/app/helpers/*.br') }

      it 'returns an empty array' do
        expect(subject.find).to be_empty
      end

      it 'does not load/reload anything' do
        expect(subject.reload?).to be true

        subject.find

        allow(File).to receive(:mtime).and_return(Time.now)
        expect(subject.reload?).to be false
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rail-0.1.1 spec/lib/support/loader_spec.rb
rail-0.1.0 spec/lib/support/loader_spec.rb
rail-0.0.8 spec/lib/support/loader_spec.rb