@@ -133,37 +133,42 @@ def test_file_fragment_cache_store
133133 end
134134
135135 def test_mem_cache_fragment_cache_store
136- Dalli ::Client . expects ( :new ) . with ( %w[ localhost ] , { } )
137- store = ActiveSupport ::Cache . lookup_store :mem_cache_store , "localhost"
138- assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
136+ assert_called_with ( Dalli ::Client , :new , [ %w[ localhost ] , { } ] ) do
137+ store = ActiveSupport ::Cache . lookup_store :mem_cache_store , "localhost"
138+ assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
139+ end
139140 end
140141
141142 def test_mem_cache_fragment_cache_store_with_given_mem_cache
142143 mem_cache = Dalli ::Client . new
143- Dalli ::Client . expects ( :new ) . never
144- store = ActiveSupport ::Cache . lookup_store :mem_cache_store , mem_cache
145- assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
144+ assert_not_called ( Dalli ::Client , :new ) do
145+ store = ActiveSupport ::Cache . lookup_store :mem_cache_store , mem_cache
146+ assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
147+ end
146148 end
147149
148150 def test_mem_cache_fragment_cache_store_with_not_dalli_client
149- Dalli ::Client . expects ( :new ) . never
150- memcache = Object . new
151- assert_raises ( ArgumentError ) do
152- ActiveSupport ::Cache . lookup_store :mem_cache_store , memcache
151+ assert_not_called ( Dalli ::Client , :new ) do
152+ memcache = Object . new
153+ assert_raises ( ArgumentError ) do
154+ ActiveSupport ::Cache . lookup_store :mem_cache_store , memcache
155+ end
153156 end
154157 end
155158
156159 def test_mem_cache_fragment_cache_store_with_multiple_servers
157- Dalli ::Client . expects ( :new ) . with ( %w[ localhost 192.168.1.1 ] , { } )
158- store = ActiveSupport ::Cache . lookup_store :mem_cache_store , "localhost" , '192.168.1.1'
159- assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
160+ assert_called_with ( Dalli ::Client , :new , [ %w[ localhost 192.168.1.1 ] , { } ] ) do
161+ store = ActiveSupport ::Cache . lookup_store :mem_cache_store , "localhost" , '192.168.1.1'
162+ assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
163+ end
160164 end
161165
162166 def test_mem_cache_fragment_cache_store_with_options
163- Dalli ::Client . expects ( :new ) . with ( %w[ localhost 192.168.1.1 ] , { :timeout => 10 } )
164- store = ActiveSupport ::Cache . lookup_store :mem_cache_store , "localhost" , '192.168.1.1' , :namespace => 'foo' , :timeout => 10
165- assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
166- assert_equal 'foo' , store . options [ :namespace ]
167+ assert_called_with ( Dalli ::Client , :new , [ %w[ localhost 192.168.1.1 ] , { :timeout => 10 } ] ) do
168+ store = ActiveSupport ::Cache . lookup_store :mem_cache_store , "localhost" , '192.168.1.1' , :namespace => 'foo' , :timeout => 10
169+ assert_kind_of ( ActiveSupport ::Cache ::MemCacheStore , store )
170+ assert_equal 'foo' , store . options [ :namespace ]
171+ end
167172 end
168173
169174 def test_object_assigned_fragment_cache_store
@@ -224,13 +229,15 @@ def test_should_overwrite
224229
225230 def test_fetch_without_cache_miss
226231 @cache . write ( 'foo' , 'bar' )
227- @cache . expects ( :write ) . never
228- assert_equal 'bar' , @cache . fetch ( 'foo' ) { 'baz' }
232+ assert_not_called ( @cache , :write ) do
233+ assert_equal 'bar' , @cache . fetch ( 'foo' ) { 'baz' }
234+ end
229235 end
230236
231237 def test_fetch_with_cache_miss
232- @cache . expects ( :write ) . with ( 'foo' , 'baz' , @cache . options )
233- assert_equal 'baz' , @cache . fetch ( 'foo' ) { 'baz' }
238+ assert_called_with ( @cache , :write , [ 'foo' , 'baz' , @cache . options ] ) do
239+ assert_equal 'baz' , @cache . fetch ( 'foo' ) { 'baz' }
240+ end
234241 end
235242
236243 def test_fetch_with_cache_miss_passes_key_to_block
@@ -245,15 +252,18 @@ def test_fetch_with_cache_miss_passes_key_to_block
245252
246253 def test_fetch_with_forced_cache_miss
247254 @cache . write ( 'foo' , 'bar' )
248- @cache . expects ( :read ) . never
249- @cache . expects ( :write ) . with ( 'foo' , 'bar' , @cache . options . merge ( :force => true ) )
250- @cache . fetch ( 'foo' , :force => true ) { 'bar' }
255+ assert_not_called ( @cache , :read ) do
256+ assert_called_with ( @cache , :write , [ 'foo' , 'bar' , @cache . options . merge ( :force => true ) ] ) do
257+ @cache . fetch ( 'foo' , :force => true ) { 'bar' }
258+ end
259+ end
251260 end
252261
253262 def test_fetch_with_cached_nil
254263 @cache . write ( 'foo' , nil )
255- @cache . expects ( :write ) . never
256- assert_nil @cache . fetch ( 'foo' ) { 'baz' }
264+ assert_not_called ( @cache , :write ) do
265+ assert_nil @cache . fetch ( 'foo' ) { 'baz' }
266+ end
257267 end
258268
259269 def test_should_read_and_write_hash
@@ -304,8 +314,9 @@ def test_fetch_multi
304314 end
305315
306316 def test_multi_with_objects
307- foo = stub ( :title => 'FOO!' , :cache_key => 'foo' )
308- bar = stub ( :cache_key => 'bar' )
317+ cache_struct = Struct . new ( :cache_key , :title )
318+ foo = cache_struct . new ( 'foo' , 'FOO!' )
319+ bar = cache_struct . new ( 'bar' )
309320
310321 @cache . write ( 'bar' , 'BAM!' )
311322
@@ -774,9 +785,10 @@ def test_delete_does_not_delete_empty_parent_dir
774785 end
775786
776787 def test_log_exception_when_cache_read_fails
777- File . expects ( :exist? ) . raises ( StandardError , "failed" )
778- @cache . send ( :read_entry , "winston" , { } )
779- assert @buffer . string . present?
788+ File . stub ( :exist? , -> { raise StandardError . new ( "failed" ) } ) do
789+ @cache . send ( :read_entry , "winston" , { } )
790+ assert @buffer . string . present?
791+ end
780792 end
781793
782794 def test_cleanup_removes_all_expired_entries
0 commit comments