Skip to content

Commit

Permalink
Change to rspec expect syntax, thereby fixing all tests and suppressi…
Browse files Browse the repository at this point in the history
…ng warnings.
  • Loading branch information
malakai97 committed May 5, 2015
1 parent 3bebe3d commit 9743907
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 49 deletions.
8 changes: 4 additions & 4 deletions spec/pairtree/pairtree_encoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
def roundtrip(id, expected_encoded=nil, expected_path=nil)
encoded = Pairtree::Identifier.encode(id)
unless expected_encoded.nil?
encoded.should == expected_encoded
expect(encoded).to eql(expected_encoded)
end
unless expected_path.nil?
path = Pairtree::Path.id_to_path(id)
path.should == expected_path
expect(path).to eql(expected_path)
end
str = Pairtree::Identifier.decode(encoded)

if str.respond_to? :force_encoding
str.force_encoding("UTF-8")
end
str.should == id

expect(str).to eql(id)
end

it "should handle a" do
Expand Down
22 changes: 11 additions & 11 deletions spec/pairtree/pairtree_obj_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
end

it "should read a file" do
@obj.read('content.xml').should == '<content/>'
expect(@obj.read('content.xml')).to eql('<content/>')
end

it "should have entries" do
@obj.entries.should == ['content.xml']
expect(@obj.entries).to eql(['content.xml'])
end

it "should glob" do
@obj['*.xml'].should == ['content.xml']
@obj['*.txt'].should == []
expect(@obj['*.xml']).to eql(['content.xml'])
expect(@obj['*.txt']).to eql([])
end

it "should be enumerable" do
block_body = double('block_body')
block_body.should_receive(:yielded).with('content.xml')
expect(block_body).to receive(:yielded).with('content.xml')
@obj.each { |file| block_body.yielded(file) }
end

Expand All @@ -41,29 +41,29 @@
end

it "should open a file" do
File.should_receive(:open).with(@target,'r')
expect(File).to receive(:open).with(@target,'r')
@obj.open('content.xml','r')
end

it "should call delete" do
File.should_receive(:delete).with(@target)
expect(File).to receive(:delete).with(@target)
@obj.delete('content.xml')
end

it "should call link" do
File.should_receive(:link).with(@target,@target + '.2')
expect(File).to receive(:link).with(@target,@target + '.2')
@obj.link('content.xml','content.xml.2')
end

it "should call rename" do
File.should_receive(:rename).with(@target,@target + '.new')
expect(File).to receive(:rename).with(@target,@target + '.new')
@obj.rename('content.xml','content.xml.new')
end

it "should call utime" do
File.should_receive(:utime).with(0,1,@target)
expect(File).to receive(:utime).with(0,1,@target)
@obj.utime(0,1,'content.xml')
end
end

end
end
10 changes: 5 additions & 5 deletions spec/pairtree/pairtree_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
end

it "should generate an encoded id as the leaf path by default" do
Pairtree::Path.leaf('abc/def').should == "abc=def"
expect(Pairtree::Path.leaf('abc/def')).to eql("abc=def")
end

it "should accept a nil override" do
Pairtree::Path.set_leaf nil
Pairtree::Path.leaf('abc/def').should == ""
expect(Pairtree::Path.leaf('abc/def')).to eql("")
end

it "should accept a scalar override" do
Pairtree::Path.set_leaf 'obj'
Pairtree::Path.leaf('abc/def').should == "obj"
expect(Pairtree::Path.leaf('abc/def')).to eql("obj")
end

it "should accept a Proc override" do
lp = Proc.new { |id| id.reverse }
Pairtree::Path.set_leaf(lp)
Pairtree::Path.leaf('abc/def').should == "fed=cba"
expect(Pairtree::Path.leaf('abc/def')).to eql("fed=cba")
end

it "should accept a block override" do
Pairtree::Path.set_leaf { |id| id.reverse }
Pairtree::Path.leaf('abc/def').should == "fed=cba"
expect(Pairtree::Path.leaf('abc/def')).to eql("fed=cba")
end

end
30 changes: 15 additions & 15 deletions spec/pairtree/pairtree_root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,48 @@
end

it "should have the correct prefix" do
@root.prefix.should == 'pfx:'
expect(@root.prefix).to eql('pfx:')
end

it "should be in the correct location" do
File.expand_path(@root.path).should == File.expand_path(@base_path)
File.expand_path(@root.root).should == File.expand_path(File.join(@base_path, "pairtree_root"))
expect(File.expand_path(@root.path)).to eql(File.expand_path(@base_path))
expect(File.expand_path(@root.root)).to eql(File.expand_path(File.join(@base_path, "pairtree_root")))
end

it "should list identifiers" do
@root.list.should == ['pfx:abc123def']
expect(@root.list).to eql(['pfx:abc123def'])
end

it "should verify whether an identifier exists" do
@root.exists?('pfx:abc123def').should be_true
@root.exists?('pfx:abc123jkl').should be_false
expect(@root.exists?('pfx:abc123def')).to be true
expect(@root.exists?('pfx:abc123jkl')).to be false
end

it "should raise an exception if an invalid prefix is used" do
lambda { @root.exists?('xfp:abc123def') }.should raise_error(Pairtree::IdentifierError)
expect { @root.exists?('xfp:abc123def') }.to raise_error(Pairtree::IdentifierError)
end

it "should get a ppath for a valid ID" do
obj = @root.get 'pfx:abc123def'
obj.class.should == Pairtree::Obj
File.expand_path(obj.path).should == File.expand_path(File.join(@base_path, "pairtree_root/ab/c1/23/de/f/abc123def/"))
expect(obj.class).to eql(Pairtree::Obj)
expect(File.expand_path(obj.path)).to eql(File.expand_path(File.join(@base_path, "pairtree_root/ab/c1/23/de/f/abc123def/")))
end

it "should raise an exception when attempting to get a ppath for an invalid ID" do
lambda { @root.get 'pfx:abc123jkl' }.should raise_error(Errno::ENOENT)
expect { @root.get 'pfx:abc123jkl' }.to raise_error(Errno::ENOENT)
end

it "should create a new ppath" do
obj = @root.mk 'pfx:abc123jkl'
obj.class.should == Pairtree::Obj
File.expand_path(obj.path).should == File.expand_path(File.join(@base_path, "pairtree_root/ab/c1/23/jk/l/abc123jkl/"))
@root.exists?('pfx:abc123jkl').should be_true
expect(obj.class).to eql(Pairtree::Obj)
expect(File.expand_path(obj.path)).to eql(File.expand_path(File.join(@base_path, "pairtree_root/ab/c1/23/jk/l/abc123jkl/")))
expect(@root.exists?('pfx:abc123jkl')).to be true
end

it "should delete a ppath" do
@root.exists?('pfx:abc123jkl').should be_true
expect(@root.exists?('pfx:abc123jkl')).to be true
@root.purge!('pfx:abc123jkl')
@root.exists?('pfx:abc123jkl').should be_false
expect(@root.exists?('pfx:abc123jkl')).to be false
end

end
26 changes: 13 additions & 13 deletions spec/pairtree/pairtree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

it "should raise an error if a non-existent is specified without :create" do
lambda { Pairtree.at(@base_path) }.should raise_error(Pairtree::PathError)
expect { Pairtree.at(@base_path) }.to raise_error(Pairtree::PathError)
end

describe "new pairtree" do
Expand All @@ -19,10 +19,10 @@
it "should create a new pairtree" do
prefix = 'my_prefix:'
pt = Pairtree.at(@base_path, :prefix => prefix, :create => true)
pt.prefix.should == prefix
File.read(File.join(@base_path, 'pairtree_prefix')).should == prefix
pt.root.should == File.join(@base_path, 'pairtree_root')
pt.pairtree_version.should == Pairtree::SPEC_VERSION
expect(pt.prefix).to eql(prefix)
expect(File.read(File.join(@base_path,'pairtree_prefix'))).to eql(prefix)
expect(pt.root).to eql(File.join(@base_path, 'pairtree_root'))
expect(pt.pairtree_version).to eql(Pairtree::SPEC_VERSION)
end

end
Expand All @@ -39,29 +39,29 @@
end

it "should raise an error if a regular file is specified as a root" do
lambda { Pairtree.at(File.join(@base_path, "pairtree_prefix"), :create => true) }.should raise_error(Pairtree::PathError)
expect { Pairtree.at(File.join(@base_path, "pairtree_prefix"), :create => true) }.to raise_error(Pairtree::PathError)
end

it "should read the prefix if none is specified" do
Pairtree.at(@base_path).prefix.should == File.read(File.join(@base_path, 'pairtree_prefix'))
expect(Pairtree.at(@base_path).prefix).to eql(File.read(File.join(@base_path, 'pairtree_prefix')))
end

it "should not complain if the given prefix matches the saved prefix" do
Pairtree.at(@base_path, :prefix => 'pfx:').prefix.should == File.read(File.join(@base_path, 'pairtree_prefix'))
expect(Pairtree.at(@base_path, :prefix => 'pfx:').prefix).to eql(File.read(File.join(@base_path, 'pairtree_prefix')))
end

it "should raise an error if the given prefix does not match the saved prefix" do
lambda { Pairtree.at(@base_path, :prefix => 'wrong-prefix:') }.should raise_error(Pairtree::IdentifierError)
expect { Pairtree.at(@base_path, :prefix => 'wrong-prefix:') }.to raise_error(Pairtree::IdentifierError)
end

it "should not complain if the given version matches the saved version" do
Pairtree.at(@base_path, :version => Pairtree::SPEC_VERSION).pairtree_version.should == Pairtree::SPEC_VERSION
Pairtree.at(@base_path, :version => Pairtree::SPEC_VERSION, :create => true).pairtree_version.should == Pairtree::SPEC_VERSION
expect(Pairtree.at(@base_path, :version => Pairtree::SPEC_VERSION).pairtree_version).to eql(Pairtree::SPEC_VERSION)
expect(Pairtree.at(@base_path, :version => Pairtree::SPEC_VERSION, :create => true).pairtree_version).to eql(Pairtree::SPEC_VERSION)
end

it "should raise an error if the given version does not match the saved version" do
lambda { Pairtree.at(@base_path, :version => 0.2) }.should raise_error(Pairtree::VersionMismatch)
lambda { Pairtree.at(@base_path, :version => 0.2, :create => true) }.should raise_error(Pairtree::VersionMismatch)
expect { Pairtree.at(@base_path, :version => 0.2) }.to raise_error(Pairtree::VersionMismatch)
expect { Pairtree.at(@base_path, :version => 0.2, :create => true) }.to raise_error(Pairtree::VersionMismatch)
end

end
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

require 'bundler/setup'
require 'rspec'
require 'rspec/autorun'

if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
require 'simplecov'
Expand Down

0 comments on commit 9743907

Please sign in to comment.