|
4 | 4 |
|
5 | 5 |
|
6 | 6 | RSpec.describe HathiTrust::Pairtree do |
7 | | - TMPDIR = Pathname.new(Dir.mktmpdir) |
8 | | - puts TMPDIR |
9 | | - |
10 | | - idmap = { |
11 | | - 'uc1.c3292592' => 'sdr1/obj/uc1/pairtree_root/c3/29/25/92/c3292592', |
12 | | - 'loc.ark:/13960/t9w09k00s' => 'sdr1/obj/loc/pairtree_root/ar/k+/=1/39/60/=t/9w/09/k0/0s/ark+=13960=t9w09k00s', |
13 | | - 'ia.ark:/13960/t9w10cs7x' => 'sdr1/obj/ia/pairtree_root/ar/k+/=1/39/60/=t/9w/10/cs/7x/ark+=13960=t9w10cs7x' |
14 | | - } |
15 | 7 |
|
| 8 | + let(:idmap) do |
| 9 | + { |
| 10 | + 'uc1.c3292592' => 'sdr1/obj/uc1/pairtree_root/c3/29/25/92/c3292592', |
| 11 | + 'loc.ark:/13960/t9w09k00s' => 'sdr1/obj/loc/pairtree_root/ar/k+/=1/39/60/=t/9w/09/k0/0s/ark+=13960=t9w09k00s', |
| 12 | + 'ia.ark:/13960/t9w10cs7x' => 'sdr1/obj/ia/pairtree_root/ar/k+/=1/39/60/=t/9w/10/cs/7x/ark+=13960=t9w10cs7x' |
| 13 | + } |
| 14 | + end |
16 | 15 |
|
17 | | - before(:context) do |
| 16 | + def make_paths(idmap) |
18 | 17 | idmap.values.each do |subdir| |
19 | | - dir = TMPDIR + subdir |
20 | | - puts "Trying to make #{dir}" |
| 18 | + dir = @tmpdir + subdir |
21 | 19 | FileUtils.mkdir_p(dir) |
22 | | - root = TMPDIR + Pathname.new(subdir.split('/')[0..2].join('/')) |
| 20 | + root = @tmpdir + Pathname.new(subdir.split('/')[0..2].join('/')) |
23 | 21 | prefix = subdir.split('/')[2] |
24 | 22 | File.open(root + 'pairtree_prefix', 'w:utf-8') do |pp| |
25 | 23 | pp.print(prefix + '.') |
|
28 | 26 | end |
29 | 27 | end |
30 | 28 |
|
31 | | - after(:context) do |
32 | | - FileUtils.rm_f(TMPDIR) |
| 29 | + around(:each) do |example| |
| 30 | + Dir.mktmpdir do |d| |
| 31 | + @tmpdir = Pathname.new(d) |
| 32 | + FileUtils.mkdir_p(@tmpdir + "sdr1/obj") |
| 33 | + example.run |
| 34 | + end |
33 | 35 | end |
34 | 36 |
|
35 | | - |
36 | 37 | it "has a version number" do |
37 | 38 | expect(HathiTrust::Pairtree::VERSION).not_to be nil |
38 | 39 | end |
39 | 40 |
|
40 | | - |
41 | | - describe "translates names into directories" do |
42 | | - pt = HathiTrust::Pairtree.new(root: TMPDIR + 'sdr1/obj') |
| 41 | + it "translates names into directories" do |
| 42 | + make_paths(idmap) |
| 43 | + pt = HathiTrust::Pairtree.new(root: @tmpdir + 'sdr1/obj') |
43 | 44 |
|
44 | 45 | idmap.each_pair do |id, dir| |
45 | | - it id do |
46 | | - expect(pt.path_for(id).to_s).to eq((TMPDIR + dir).to_s) |
47 | | - end |
| 46 | + expect(pt.path_for(id).to_s).to eq((@tmpdir + dir).to_s) |
48 | 47 | end |
49 | 48 | end |
50 | 49 |
|
51 | | - it "Can create new object directories" do |
52 | | - pt = HathiTrust::Pairtree.new(root: TMPDIR + 'sdr1/obj') |
53 | | - expect {pt.create('bill.dueber', create_new_namespace: false)}.to raise_error(Pairtree::PathError) |
54 | | - expect(pt.create('bill.dueber', create_new_namespace: true).exists?('.')).to be true |
| 50 | + describe "#create" do |
| 51 | + let(:pt) { HathiTrust::Pairtree.new(root: @tmpdir + 'sdr1/obj') } |
| 52 | + |
| 53 | + it "can create new object directories" do |
| 54 | + expect {pt.create('test.something', new_namespace_allowed: false)}.to raise_error(HathiTrust::Pairtree::NamespaceDoesNotExist) |
| 55 | + expect(pt.create('test.something', new_namespace_allowed: true).exists?('.')).to be true |
| 56 | + end |
| 57 | + |
| 58 | + it "create is idempotent" do |
| 59 | + pt.create('test.something', new_namespace_allowed: true) |
| 60 | + expect(pt.create('test.something').exists?('.')).to be true |
| 61 | + end |
| 62 | + |
| 63 | + it "new_namespace_allowed is idempotent" do |
| 64 | + pt.create('test.something', new_namespace_allowed: true) |
| 65 | + expect(pt.create('test.somethingelse', new_namespace_allowed: true).exists?('.')).to be true |
| 66 | + end |
55 | 67 | end |
56 | 68 |
|
57 | 69 |
|
|
0 commit comments