Sha256: 784ec41713aa7eaa79cbdb0008fdab12d61cf22fae26a1464dc565d0bd26a880

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

require_relative "spec_helper_initializer"

describe "Shakapacker::MtimeStrategy" do
  let(:mtime_strategy) { Shakapacker::MtimeStrategy.new }
  let(:manifest_timestamp) { Time.parse("2021-01-01 12:34:56 UTC") }

  describe "#fresh?" do
    it "returns false when the manifest is missing" do
      latest_timestamp = manifest_timestamp + 3600

      with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
        expect(mtime_strategy.fresh?).to be false
      end
    end

    it "returns false when the manifest is older" do
      latest_timestamp = manifest_timestamp + 3600

      with_stubs(latest_timestamp: latest_timestamp.to_i) do
        expect(mtime_strategy.fresh?).to be false
      end
    end

    it "returns true when the manifest is new" do
      latest_timestamp = manifest_timestamp - 3600

      with_stubs(latest_timestamp: latest_timestamp.to_i) do
        expect(mtime_strategy.fresh?).to be true
      end
    end
  end

  describe "#stale?" do
    it "returns false when #fresh? is true" do
      expect(mtime_strategy).to receive(:fresh?).and_return(true)

      expect(mtime_strategy.stale?).to be false
    end

    it "returns true when #fresh? is false" do
      expect(mtime_strategy).to receive(:fresh?).and_return(false)

      expect(mtime_strategy.stale?).to be true
    end
  end

  private

    def with_stubs(latest_timestamp:, manifest_exists: true)
      allow(mtime_strategy).to receive(:latest_modified_timestamp).and_return(latest_timestamp)
      allow(FileTest).to receive(:exist?).and_return(manifest_exists)
      allow(File).to receive(:mtime).and_return(manifest_timestamp)
      yield
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shakapacker-7.2.3 spec/shakapacker/mtime_strategy_spec.rb
shakapacker-7.3.0.beta.1 spec/shakapacker/mtime_strategy_spec.rb
shakapacker-7.2.2 spec/shakapacker/mtime_strategy_spec.rb
shakapacker-7.2.1 spec/shakapacker/mtime_strategy_spec.rb
shakapacker-7.2.0 spec/shakapacker/mtime_strategy_spec.rb
shakapacker-7.2.0.rc.0 spec/shakapacker/mtime_strategy_spec.rb
shakapacker-7.1.0 spec/shakapacker/mtime_strategy_spec.rb