Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix specs again, ruby 1.9.3 is required to run the specs now.

  • Loading branch information...
commit 423a1b59874826e7385479567c76234a74a70107 1 parent 8a2c31f
orslumen authored
2  Gemfile.lock
View
@@ -90,7 +90,7 @@ GEM
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
+ tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
3  lib/record_cache.rb
View
@@ -1,5 +1,6 @@
# Record Cache files
-["version", "query", "version_store", "multi_read",
+require "record_cache/version"
+["query", "version_store", "multi_read",
"strategy/util", "strategy/base", "strategy/request_cache", "strategy/unique_index_cache", "strategy/full_table_cache", "strategy/index_cache",
"statistics", "dispatcher", "base"].each do |file|
require File.dirname(__FILE__) + "/record_cache/#{file}.rb"
3  spec/lib/base_spec.rb
View
@@ -1,5 +1,4 @@
-# coding: utf-8
-$KCODE = 'UTF8'
+# encoding: utf-8
require 'spec_helper'
describe RecordCache::Base do
3  spec/lib/strategy/base_spec.rb
View
@@ -1,5 +1,4 @@
-# coding: utf-8
-$KCODE = 'UTF8'
+# encoding: utf-8
require 'spec_helper'
describe RecordCache::Strategy::Base do
6 spec/lib/strategy/index_cache_spec.rb
View
@@ -24,13 +24,11 @@
end
it "should write hit to the debug log" do
- mock(RecordCache::Base.logger).debug(/IndexCache hit for rc\/apl\/store_id=1v\d+: found 5 ids|^(?!IndexCache)/).times(any_times)
- Apple.where(:store_id => 1).all
+ lambda { Apple.where(:store_id => 1).all }.should log(:debug, /IndexCache hit for rc\/apl\/store_id=1v\d+: found 5 ids/)
end
it "should write miss to the debug log" do
- mock(RecordCache::Base.logger).debug(/IndexCache miss for rc\/apl\/store_id=2v\d+: found no ids|^(?!IndexCache)/).times(any_times)
- Apple.where(:store_id => 2).all
+ lambda { Apple.where(:store_id => 2).all }.should log(:debug, /IndexCache miss for rc\/apl\/store_id=2v\d+: found no ids/)
end
end
6 spec/lib/strategy/request_cache_spec.rb
View
@@ -20,13 +20,11 @@
end
it "should write hit to the debug log" do
- mock(RecordCache::Base.logger).debug(/RequestCache hit for 1\?id=1|^(?!RequestCache)/).times(any_times)
- Store.find(1)
+ lambda { Store.find(1) }.should log(:debug, %(RequestCache hit for 1?id=1))
end
it "should write miss to the debug log" do
- mock(RecordCache::Base.logger).debug(/^RequestCache miss for 1\?id=2|^(?!RequestCache)/).times(any_times)
- Store.find(2)
+ lambda { Store.find(2) }.should log(:debug, %(RequestCache miss for 1?id=2))
end
end
9 spec/lib/strategy/unique_index_on_id_cache_spec.rb
View
@@ -20,18 +20,15 @@
end
it "should write full hits to the debug log" do
- mock(RecordCache::Base.logger).debug(/UniqueIndexCache on 'id' hit for ids 1|^(?!UniqueIndexCache)/).times(any_times)
- Apple.find(1)
+ lambda { Apple.find(1) }.should log(:debug, %(UniqueIndexCache on 'id' hit for ids 1))
end
it "should write full miss to the debug log" do
- mock(RecordCache::Base.logger).debug(/UniqueIndexCache on 'id' miss for ids 2|^(?!UniqueIndexCache)/).times(any_times)
- Apple.find(2)
+ lambda { Apple.find(2) }.should log(:debug, %(UniqueIndexCache on 'id' miss for ids 2))
end
it "should write partial hits to the debug log" do
- mock(RecordCache::Base.logger).debug(/UniqueIndexCache on 'id' partial hit for ids \[1, 2\]: missing \[2\]|^(?!UniqueIndexCache)/).times(any_times)
- Apple.where(:id => [1,2]).all
+ lambda { Apple.where(:id => [1,2]).all }.should log(:debug, %(UniqueIndexCache on 'id' partial hit for ids [1, 2]: missing [2]))
end
end
9 spec/lib/strategy/unique_index_on_string_cache_spec.rb
View
@@ -20,18 +20,15 @@
end
it "should write full hits to the debug log" do
- mock(RecordCache::Base.logger).debug(/UniqueIndexCache on 'name' hit for ids "Fry"|^(?!UniqueIndexCache)/).times(any_times)
- Person.find_by_name("Fry")
+ lambda { Person.find_by_name("Fry") }.should log(:debug, %(UniqueIndexCache on 'name' hit for ids "Fry"))
end
it "should write full miss to the debug log" do
- mock(RecordCache::Base.logger).debug(/UniqueIndexCache on 'name' miss for ids "Chase"|^(?!UniqueIndexCache)/).times(any_times)
- Person.find_by_name("Chase")
+ lambda { Person.find_by_name("Chase") }.should log(:debug, %(UniqueIndexCache on 'name' miss for ids "Chase"))
end
it "should write partial hits to the debug log" do
- mock(RecordCache::Base.logger).debug(/UniqueIndexCache on 'name' partial hit for ids \["Fry", "Chase"\]: missing \["Chase"\]|^(?!UniqueIndexCache)/).times(any_times)
- Person.where(:name => ["Fry", "Chase"]).all
+ lambda { Person.where(:name => ["Fry", "Chase"]).all }.should log(:debug, %(UniqueIndexCache on 'name' partial hit for ids ["Fry", "Chase"]: missing ["Chase"]))
end
end
3  spec/lib/strategy/util_spec.rb
View
@@ -1,5 +1,4 @@
-# coding: utf-8
-$KCODE = 'UTF8'
+# encoding: utf-8
require 'spec_helper'
describe RecordCache::Strategy::Util do
15 spec/lib/version_store_spec.rb
View
@@ -51,10 +51,7 @@
end
it "should write to the debug log" do
- mock(RecordCache::Base.logger).debug?{ true }
- mock(RecordCache::Base.logger).debug(/Version Store: renew key1: nil => \d+/)
- @version_store.renew("key1")
- stub(RecordCache::Base.logger).debug?{ false } # to prevent the ResettableVersionStore from logging in +after(:each)+
+ lambda { @version_store.renew("key1") }.should log(:debug, /Version Store: renew key1: nil => \d+/)
end
end
@@ -73,10 +70,7 @@
end
it "should write to the debug log" do
- mock(RecordCache::Base.logger).debug?{ true }
- mock(RecordCache::Base.logger).debug("Version Store: incremented key1: 1000 => 1001")
- @version_store.increment("key1")
- stub(RecordCache::Base.logger).debug?{ false } # to prevent the ResettableVersionStore from logging in +after(:each)+
+ lambda { @version_store.increment("key1") }.should log(:debug, %(Version Store: incremented key1: 1000 => 1001))
end
end
@@ -94,10 +88,7 @@
end
it "should write to the debug log" do
- mock(RecordCache::Base.logger).debug?{ true }
- mock(RecordCache::Base.logger).debug("Version Store: deleted key1")
- @version_store.delete("key1")
- stub(RecordCache::Base.logger).debug?{ false } # to prevent the ResettableVersionStore from logging in +after(:each)+
+ lambda { @version_store.delete("key1") }.should log(:debug, %(Version Store: deleted key1))
end
end
41 spec/support/matchers/log.rb
View
@@ -0,0 +1,41 @@
+# Examples:
+# 1) lambda{ Person.find(22) }.should log(:debug, %(UniqueIndexCache on 'id' hit for ids 1)
+# _should have at least one debug log statement as given above_
+#
+# 2) lambda{ Person.find(22) }.should log(:debug, /^UniqueIndexCache/)
+# _should have at least one debug log statement starting with UniqueIndexCache_
+RSpec::Matchers.define :log do |severity, expected|
+
+ match do |proc|
+ logger = RecordCache::Base.logger
+ # override the debug/info/warn/error method
+ logger.instance_variable_set(:@found_messages, [])
+ logger.instance_variable_set(:@found, false)
+ logger.class.send(:alias_method, "orig_#{severity}", severity)
+ logger.class.send(:define_method, severity) do |progname = nil, &block|
+ unless @found
+ actual= progname.is_a?(String) ? progname : block ? block.call : nil
+ unless actual.blank?
+ @found = actual.is_a?(String) && expected.is_a?(Regexp) ? actual =~ expected : actual == expected
+ @found_messages << actual
+ end
+ end
+ end
+ # call the given proc
+ proc.call
+ # redefine
+ logger.class.send(:alias_method, severity, "orig_#{severity}")
+ # the result
+ @found_messages = logger.instance_variable_get(:@found_messages)
+ @found = logger.instance_variable_get(:@found)
+ end
+
+ failure_message_for_should do |proc|
+ "Expected #{@found_messages.inspect} to include #{expected.inspect}"
+ end
+
+ failure_message_for_should_not do |proc|
+ "Expected #{@found_messages.inspect} not to include #{expected.inspect}"
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.