Skip to content

Commit

Permalink
upgrading to rspec 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Stephens committed Aug 22, 2014
1 parent 40ce8f9 commit f04fcde
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions spec/with_timed_cache/cache_spec.rb
Expand Up @@ -2,16 +2,16 @@

describe WithTimedCache::Cache do
it "knows it's local class name" do
WithTimedCache::Cache.local_class_name.should == "Cache"
expect(WithTimedCache::Cache.local_class_name).to eql("Cache")
end

it "has an empty file extension" do
WithTimedCache::Cache.file_extension.should be_empty
expect(WithTimedCache::Cache.file_extension).to be_empty
end

it "should have a filename with no extension by default" do
cache = WithTimedCache::Cache.new(:foo)
(cache.filename =~ /^.+\..+$/).should be_false
expect(!!(cache.filename =~ /^.+\..+$/)).to be false
end
end

14 changes: 7 additions & 7 deletions spec/with_timed_cache/caches_spec.rb
Expand Up @@ -6,22 +6,22 @@
key = :find_or_create
first_ref = WithTimedCache::Caches.find_or_create(key)
second_ref = WithTimedCache::Caches.find_or_create(key)
first_ref.eql?(second_ref).should be_true
expect(first_ref.eql?(second_ref)).to be true
end
end

describe ".cache_class" do
it "will return the constant of the cache class for the given format" do
WithTimedCache::Caches.cache_class(:json).should == WithTimedCache::JSONCache
WithTimedCache::Caches.cache_class("json").should == WithTimedCache::JSONCache
WithTimedCache::Caches.cache_class(:yaml).should == WithTimedCache::YAMLCache
WithTimedCache::Caches.cache_class("").should == WithTimedCache::Cache
WithTimedCache::Caches.cache_class.should == WithTimedCache::Cache
expect(WithTimedCache::Caches.cache_class(:json)).to eql(WithTimedCache::JSONCache)
expect(WithTimedCache::Caches.cache_class("json")).to eql(WithTimedCache::JSONCache)
expect(WithTimedCache::Caches.cache_class(:yaml)).to eql(WithTimedCache::YAMLCache)
expect(WithTimedCache::Caches.cache_class("")).to eql(WithTimedCache::Cache)
expect(WithTimedCache::Caches.cache_class).to eql(WithTimedCache::Cache)
end

it "will return the constant of the cache class for the given format" do
expect {
WithTimedCache::Caches.cache_class(:foobar).should == WithTimedCache::JSONCache
WithTimedCache::Caches.cache_class(:foobar)
}.to raise_error WithTimedCache::InvalidCacheFormatException
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/with_timed_cache/json_cache_spec.rb
Expand Up @@ -2,16 +2,16 @@

describe WithTimedCache::JSONCache do
it "knows it's local class name" do
WithTimedCache::JSONCache.local_class_name.should == "JSONCache"
expect(WithTimedCache::JSONCache.local_class_name).to eql("JSONCache")
end

it "has a file_extension" do
WithTimedCache::JSONCache.file_extension.should == "json"
expect(WithTimedCache::JSONCache.file_extension).to eql("json")
end

it "should have a filename with the '.json' extension" do
cache = WithTimedCache::JSONCache.new(:foo)
(cache.filename =~ /^.+\.json$/).should be_true
expect(!!(cache.filename =~ /^.+\.json$/)).to be true
end
end

6 changes: 3 additions & 3 deletions spec/with_timed_cache/yaml_cache_spec.rb
Expand Up @@ -2,16 +2,16 @@

describe WithTimedCache::YAMLCache do
it "knows it's local class name" do
WithTimedCache::YAMLCache.local_class_name.should == "YAMLCache"
expect(WithTimedCache::YAMLCache.local_class_name).to eql("YAMLCache")
end

it "has a file_extension" do
WithTimedCache::YAMLCache.file_extension.should == "yml"
expect(WithTimedCache::YAMLCache.file_extension).to eql("yml")
end

it "should have a filename with the '.yml' extension" do
cache = WithTimedCache::YAMLCache.new(:foo)
(cache.filename =~ /^.+\.yml$/).should be_true
expect(!!(cache.filename =~ /^.+\.yml$/)).to be true
end
end

28 changes: 14 additions & 14 deletions spec/with_timed_cache_spec.rb
Expand Up @@ -19,7 +19,7 @@
data = with_timed_cache(:max_age_1, location: @cache_directory, max_age: 1.minute) do
i == 0 ? original_val : updated_val
end
data.should == original_val
expect(data).to eql(original_val)
end
end

Expand All @@ -32,11 +32,11 @@
i == 0 ? original_val : updated_val
end
if i == 0
data.should == original_val
expect(data).to eql(original_val)
sleep 1.5 # sleep longer than max_age
end
end
data.should == updated_val
expect(data).to eql(updated_val)
end

it "caches marshaled data to a file" do
Expand All @@ -45,11 +45,11 @@
data = [1, 2, 3]

cached_data = with_timed_cache(key, location: @cache_directory) { data }
cached_data.should == data
File.exists?(File.join(@cache_directory, filename)).should be_true
expect(cached_data).to eql(data)
expect(File.exists?(File.join(@cache_directory, filename))).to be true

raw_cache_data = File.read(File.join(@cache_directory, filename))
Marshal.load(raw_cache_data).should == data
expect(Marshal.load(raw_cache_data)).to eql(data)
end

it "lets you store cache data as json" do
Expand All @@ -59,11 +59,11 @@
data = { foo: 'bar', baz: 'qux' }

cached_data = with_timed_cache(key, location: @cache_directory, format: :json) { data }
cached_data.should == data
File.exists?(filepath).should be_true
expect(cached_data).to eql(data)
expect(File.exists?(filepath)).to be true

raw_cache_data = File.read(filepath)
JSON.parse(raw_cache_data, symbolize_names: true).should == data
expect(JSON.parse(raw_cache_data, symbolize_names: true)).to eql(data)
end

it "lets you store cache data as yaml" do
Expand All @@ -73,11 +73,11 @@
data = { foo: 'bar', baz: 'qux' }

cached_data = with_timed_cache(key, location: @cache_directory, format: :yaml) { data }
cached_data.should == data
File.exists?(filepath).should be_true
expect(cached_data).to eql(data)
expect(File.exists?(filepath)).to be true

raw_cache_data = File.read(filepath)
YAML.load_file(filepath).should == data
expect(YAML.load_file(filepath)).to eql(data)
end

it "returns last cached data if present when an exception is raised" do
Expand All @@ -93,14 +93,14 @@
end
sleep 1.5 if i == 0
end
data.should == string
expect(data).to eql(string)
end

it "returns nil when an exception is raised if no previous cache is present" do
data = with_timed_cache(:exception_nil, location: @cache_directory, max_age: 1.second) do
raise Exception
end
data.should be_nil
expect(data).to be nil
end

def clean_cache_directory
Expand Down
2 changes: 1 addition & 1 deletion with_timed_cache.gemspec
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "guard-rspec"
spec.add_dependency "activesupport"
spec.add_dependency "json"
Expand Down

0 comments on commit f04fcde

Please sign in to comment.