Class: Cachier::Matchers::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/cachier/matchers.rb

Instance Method Summary collapse

Instance Method Details

#failure_message_for_shouldObject



20
21
22
23
24
25
26
27
# File 'lib/cachier/matchers.rb', line 20

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

#failure_message_for_should_notObject



29
30
31
32
33
34
35
36
# File 'lib/cachier/matchers.rb', line 29

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

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'lib/cachier/matchers.rb', line 9

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