Sha256: 5e840b8424400e3b47a293f887507785883aa992103d85280e7b31f89f669c7c

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Cashier
  module Matchers
    def be_cached
      Cache.new
    end

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

        @test_results = Cashier.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 && Cashier.keys_for(@target).present?
      end

      def failure_message_for_should
        <<-msg
          expected the Rails.cache to include all these keys:
          #{Cashier.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:
          #{Cashier.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

3 entries across 3 versions & 2 rubygems

Version Path
cashier-ftbpro-0.5.0 lib/cashier/matchers.rb
cashier-0.4.1 lib/cashier/matchers.rb
cashier-0.4.0 lib/cashier/matchers.rb