Sha256: ff84e328b55837f7e2551382a28f736d8ac6e5267f5086238af0ac9019fca008

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Cachier
  module Matchers

    def be_cached
      Cache.new
    end

    class Cache
      def matches?(target)
        @target = target

        @test_results = Cachier.keys_for(@target).inject({}) do |hash, key|
          hash.merge(key => Rails.cache.exist?(key))
        end

        flag = @test_results.values.inject(true) { |f, v| f && v }
        flag && Cachier.keys_for(@target).present?
      end

      def failure_message_for_should
        <<-msg
          expected the Rails.cache to include all these keys:
          #{Cachier.keys_for(@target).to_sentence}, but
          it did not include these keys:
          #{@test_results.keys.select {|k| @test_results[k] == false }.to_sentence}
        msg
      end

      def failure_message_for_should_not
        <<-msg
          expected the Rails.cache to not include all these keys:
          #{Cachier.keys_for(@target).to_sentence}, but
          it did include these keys:
          #{@test_results.keys.select {|k| @test_results[k] == true }.to_sentence}
        msg
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cachier-0.0.1 lib/cachier/matchers.rb