Sha256: edbf054d9a8c41d8bbc84b3f8d98f86be3525ed8b75b260d4177fb4ab01973dd

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8

require "spec_helper"

module Bunch
  describe SimpleCache do
    let(:input_tree) do
      FileTree.from_hash("a" => "aa", "b" => { "c" => "cc", "d" => "dd" })
    end

    let(:input_tree_2) do
      FileTree.from_hash("a" => "aa", "b" => { "c" => "ce", "d" => "dd" })
    end

    let(:input_tree_3) do
      FileTree.from_hash("a" => "aa", "b" => { "d" => "dd", "c" => "cc" })
    end

    it "delegates to the underlying processor" do
      processor = stub(result: FileTree.from_hash("fff" => "ggg"))
      cache = SimpleCache.new(stub(new: processor))
      cache.new(input_tree).result.to_hash.must_equal "fff" => "ggg"
    end

    it "caches the results" do
      processor = stub
      processor.stubs(:result).
        returns(FileTree.from_hash("fff" => "ggg")).then.
        returns(FileTree.from_hash("hhh" => "jjj"))
      cache  = SimpleCache.new(stub(new: processor))
      cache.new(input_tree).result.to_hash.must_equal "fff" => "ggg"
      cache.new(input_tree).result.to_hash.must_equal "fff" => "ggg"
    end

    it "expires the results if the input tree changes" do
      processor = stub
      processor.stubs(:result).
        returns(FileTree.from_hash("fff" => "ggg")).then.
        returns(FileTree.from_hash("hhh" => "jjj"))
      cache  = SimpleCache.new(stub(new: processor))
      cache.new(input_tree).result.to_hash.must_equal "fff" => "ggg"
      cache.new(input_tree_2).result.to_hash.must_equal "hhh" => "jjj"
    end

    it "isn't order-dependent" do
      processor = stub
      processor.stubs(:result).
        returns(FileTree.from_hash("fff" => "ggg")).then.
        returns(FileTree.from_hash("hhh" => "jjj"))
      cache  = SimpleCache.new(stub(new: processor))
      cache.new(input_tree).result.to_hash.must_equal "fff" => "ggg"
      cache.new(input_tree_3).result.to_hash.must_equal "fff" => "ggg"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bunch-1.0.0pre3 spec/bunch/simple_cache_spec.rb
bunch-1.0.0pre2 spec/bunch/simple_cache_spec.rb
bunch-1.0.0pre1 spec/bunch/simple_cache_spec.rb