Permalink
Browse files

convert cache tests to specs

  • Loading branch information...
1 parent 73548fa commit 31ab7b9de05589abf73f359739d4586af54a846f @olbrich committed Feb 25, 2012
Showing with 31 additions and 26 deletions.
  1. +31 −0 spec/ruby-units/cache_spec.rb
  2. +0 −26 test/test_cache.rb
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Unit::Cache do
+ subject { Unit::Cache }
+ let(:unit) { Unit('1 m') }
+
+ before(:each) do
+ subject.clear
+ subject.set("m", unit)
+ end
+
+ context ".clear" do
+ it "should clear the cache" do
+ subject.clear
+ subject.get('m').should be_nil
+ end
+ end
+
+ context ".get" do
+ it "should retrieve values already in the cache" do
+ subject.get['m'].should == unit
+ end
+ end
+
+ context ".set" do
+ it "should put a unit into the cache" do
+ subject.set('kg', Unit('1 kg'))
+ subject.get['kg'].should == Unit('1 kg')
+ end
+ end
+end
View
@@ -1,26 +0,0 @@
-require 'rubygems'
-require 'test/unit'
-require 'ruby-units'
-
-class TestCache < Test::Unit::TestCase
- def setup
- Unit::Cache.clear
- end
-
- def test_clear
- Unit::Cache.set("m", "m".unit)
- Unit::Cache.clear
- assert_nil(Unit::Cache.get('m'))
- end
-
- def test_set_cache
- assert_nothing_raised { Unit::Cache.set("m", "m".unit) }
- assert Unit::Cache.get.keys.include?('m')
- end
-
- def test_get_cache
- Unit::Cache.set("m", "m".unit)
- assert_equal("m".unit, Unit::Cache.get['m'])
- end
-
-end

0 comments on commit 31ab7b9

Please sign in to comment.