bagit 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +1,59 @@
1
1
  # coding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "Tag Specs" do
5
-
6
- before(:each) do
7
-
8
- @sandbox = Sandbox.new
9
-
10
- # make the bag
11
- @bag_path = File.join @sandbox.to_s, 'the_bag'
12
- @bag = BagIt::Bag.new @bag_path
13
-
14
- # add some files
15
- File.open('/dev/urandom') do |rio|
16
-
17
- 10.times do |n|
18
- @bag.add_file("file-#{n}-💩
19
- @bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16)}
4
+ describe BagIt::Bag do
5
+ describe "Tag Specs" do
6
+ before do
7
+ @sandbox = Sandbox.new
8
+
9
+ # make the bag
10
+ @bag_path = File.join @sandbox.to_s, 'the_bag'
11
+ @bag = described_class.new(@bag_path)
12
+
13
+ # add some files
14
+ File.open('/dev/urandom') do |rio|
15
+ 10.times do |n|
16
+ @bag.add_file("file-#{n}-💩
17
+ @bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
18
+ end
20
19
  end
21
-
22
20
  end
23
21
 
24
- end
25
-
26
- after(:each) do
27
- @sandbox.cleanup!
28
- end
29
- describe "#add_tag_file" do
30
- it "should allow addition of tag files via io" do
31
- @bag.add_tag_file("foo") { |io| io.puts 'all alone' }
32
- expect(File.join(@bag_path, "foo")).to exist_on_fs
33
- end
34
- it "should allow addition of bag files within directories using io" do
35
- @bag.add_tag_file("fedora/foo") { |io| io.puts 'all alone' }
36
- expect(File.join(@bag_path, "fedora","foo")).to exist_on_fs
37
- end
38
- it "should allow addition of deep tag files" do
39
- @bag.add_tag_file("fedora/foo/newfoo/deep") {|io| io.puts "woah that's deep"}
40
- expect(File.join(@bag_path,"fedora","foo","newfoo","deep")).to exist_on_fs
22
+ after do
23
+ @sandbox.cleanup!
41
24
  end
42
- it "should not allow overwriting of tag files" do
43
- expect { @bag.add_tag_file("tag-0") { |io| io.puts 'overwrite!' } }.to raise_error(RuntimeError)
25
+ describe "#add_tag_file" do
26
+ it "allows addition of tag files via io" do
27
+ @bag.add_tag_file("foo") { |io| io.puts 'all alone' }
28
+ expect(File.join(@bag_path, "foo")).to exist_on_fs
29
+ end
30
+ it "allows addition of bag files within directories using io" do
31
+ @bag.add_tag_file("fedora/foo") { |io| io.puts 'all alone' }
32
+ expect(File.join(@bag_path, "fedora", "foo")).to exist_on_fs
33
+ end
34
+ it "allows addition of deep tag files" do
35
+ @bag.add_tag_file("fedora/foo/newfoo/deep") { |io| io.puts "woah that's deep" }
36
+ expect(File.join(@bag_path, "fedora", "foo", "newfoo", "deep")).to exist_on_fs
37
+ end
38
+ it "does not allow overwriting of tag files" do
39
+ expect { @bag.add_tag_file("tag-0") { |io| io.puts 'overwrite!' } }.to raise_error(RuntimeError)
40
+ end
41
+ it "allows addition of tag files via copy" do
42
+ src_path = File.join @sandbox.to_s, 'somefile'
43
+ File.open(src_path, 'w') { |io| io.puts "something" }
44
+ @bag.add_tag_file("foo", src_path) { |io| io.puts 'all alone' }
45
+ expect(File.join(@bag_path, "foo")).to exist_on_fs
46
+ end
44
47
  end
45
- it "should allow addition of tag files via copy" do
46
- src_path = File.join @sandbox.to_s, 'somefile'
47
- File.open(src_path, 'w') { |io| io.puts "something" }
48
- @bag.add_tag_file("foo", src_path) { |io| io.puts 'all alone' }
49
- expect(File.join(@bag_path, "foo")).to exist_on_fs
48
+ describe "#remove_tag_file" do
49
+ it "raises an error when removing non existant files" do
50
+ expect { @bag.remove_tag_file("file-x") }.to raise_error(RuntimeError)
51
+ end
50
52
  end
51
- end
52
- describe "#remove_tag_file" do
53
- it "should raise an error when removing non existant files" do
54
- expect { @bag.remove_tag_file("file-x") }.to raise_error(RuntimeError)
53
+ describe "#delete_tag_file" do
54
+ it "raises an error when deleting non existant tag files" do
55
+ expect { @bag.delete_tag_file("file-x") }.to raise_error(RuntimeError)
56
+ end
55
57
  end
56
58
  end
57
- describe "#delete_tag_file" do
58
- it "should raise an error when deleting non existant tag files" do
59
- expect { @bag.delete_tag_file("file-x") }.to raise_error(RuntimeError)
60
- end
61
- end
62
59
  end
@@ -1,8 +1,5 @@
1
1
  module BagitMatchers
2
-
3
- class BeIn
4
-
5
-
2
+ class BeIn
6
3
  def initialize(*expected_collection)
7
4
  @expected = expected_collection
8
5
  end
@@ -20,16 +17,13 @@ module BagitMatchers
20
17
  "expected <#{@target}> to not be in collection <#{@expected}>"
21
18
  end
22
19
  alias negative_failure_message failure_message_when_negated
23
-
24
20
  end
25
21
 
26
22
  def be_in(*expected_collection)
27
23
  BeIn.new(*expected_collection)
28
24
  end
29
25
 
30
- class ExistOnFS
31
-
32
-
26
+ class ExistOnFS
33
27
  def matches?(target)
34
28
  @target = target
35
29
  File.exist? target
@@ -43,14 +37,9 @@ module BagitMatchers
43
37
  "expected <#{@target}> to not exist but it does"
44
38
  end
45
39
  alias negative_failure_message failure_message_when_negated
46
-
47
40
  end
48
41
 
49
- def exist_on_fs
42
+ def exist_on_fs
50
43
  ExistOnFS.new
51
44
  end
52
-
53
-
54
-
55
-
56
45
  end
@@ -1,144 +1,141 @@
1
1
  # coding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "a valid bag" do
5
-
6
- before(:each) do
7
-
8
- @sandbox = Sandbox.new
9
-
10
- # make the bag
11
- @bag_path = File.join @sandbox.to_s, 'the_bag'
12
- @bag = BagIt::Bag.new @bag_path
13
-
14
- # add some files
15
- File.open('/dev/urandom') do |rio|
16
-
17
- 10.times do |n|
18
- @bag.add_file("file-#{n}-💩
4
+ describe BagIt::Bag do
5
+ describe "a valid bag" do
6
+ before do
7
+ @sandbox = Sandbox.new
8
+
9
+ # make the bag
10
+ @bag_path = File.join @sandbox.to_s, 'the_bag'
11
+ @bag = described_class.new @bag_path
12
+
13
+ # add some files
14
+ File.open('/dev/urandom') do |rio|
15
+ 10.times do |n|
16
+ @bag.add_file("file-#{n}-💩
19
17
  ") { |io| io.write rio.read(16) }
20
- @bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
18
+ @bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
19
+ end
21
20
  end
22
21
 
22
+ @bag.manifest!
23
23
  end
24
24
 
25
- @bag.manifest!
26
- end
25
+ after do
26
+ @sandbox.cleanup!
27
+ end
27
28
 
28
- after(:each) do
29
- @sandbox.cleanup!
30
- end
29
+ it "validates with no errors" do
30
+ expect(@bag).to be_valid
31
+ end
31
32
 
32
- it "should validate with no errors" do
33
- expect(@bag).to be_valid
34
- end
33
+ it "is invalid if there is a file that's in the bag, but not in the manifest" do
34
+ # add a file into the bag through the back door
35
+ File.open(File.join(@bag.data_dir, 'not-manifested'), 'w') do |io|
36
+ io.puts 'nothing to see here, move along'
37
+ end
35
38
 
36
- it "should be invalid if there is a file that's in the bag, but not in the manifest" do
37
- # add a file into the bag through the back door
38
- File.open(File.join(@bag.data_dir, 'not-manifested'), 'w') do |io|
39
- io.puts 'nothing to see here, move along'
39
+ @bag.validate_only('true_for/completeness')
40
+ expect(@bag.errors.on(:completeness)).not_to be_empty
41
+ expect(@bag).not_to be_valid
40
42
  end
41
43
 
42
- @bag.validate_only('true_for/completeness')
43
- expect(@bag.errors.on(:completeness)).not_to be_empty
44
- expect(@bag).not_to be_valid
45
- end
46
-
47
- it "should be invalid if there are files that are in the manifest but not in the bag" do
48
- # add a file and then remove it through the back door
49
- @bag.add_file("file-k") { |io| io.puts 'time to go' }
50
- @bag.manifest!
44
+ it "is invalid if there are files that are in the manifest but not in the bag" do
45
+ # add a file and then remove it through the back door
46
+ @bag.add_file("file-k") { |io| io.puts 'time to go' }
47
+ @bag.manifest!
51
48
 
52
- FileUtils::rm File.join(@bag.bag_dir, 'data', 'file-k')
49
+ FileUtils.rm File.join(@bag.bag_dir, 'data', 'file-k')
53
50
 
54
- @bag.validate_only('true_for/completeness')
55
- expect(@bag.errors.on(:completeness)).not_to be_empty
56
- expect(@bag).not_to be_valid
57
- end
51
+ @bag.validate_only('true_for/completeness')
52
+ expect(@bag.errors.on(:completeness)).not_to be_empty
53
+ expect(@bag).not_to be_valid
54
+ end
58
55
 
59
- it "should be invalid if there is a fixity problem" do
60
- # tweak a file through the back door
61
- File.open(@bag.bag_files[0], 'a') { |io| io.puts 'oops!' }
56
+ it "is invalid if there is a fixity problem" do
57
+ # tweak a file through the back door
58
+ File.open(@bag.bag_files[0], 'a') { |io| io.puts 'oops!' }
62
59
 
63
- @bag.validate_only('true_for/consistency')
64
- expect(@bag.errors.on(:consistency)).not_to be_empty
65
- expect(@bag).not_to be_valid
66
- end
60
+ @bag.validate_only('true_for/consistency')
61
+ expect(@bag.errors.on(:consistency)).not_to be_empty
62
+ expect(@bag).not_to be_valid
63
+ end
67
64
 
68
- it "should calculate sha1 correctly for a big file" do
69
- @bag.add_file 'big-data-file' do |fh|
70
- count = 0
71
- while count < 1024 * 512 do
72
- fh.write "1" * 1024
73
- count += 1
65
+ it "calculates sha1 correctly for a big file" do
66
+ @bag.add_file 'big-data-file' do |fh|
67
+ count = 0
68
+ while count < 1024 * 512
69
+ fh.write "1" * 1024
70
+ count += 1
71
+ end
74
72
  end
75
- end
76
- @bag.manifest!
77
- sha1_manifest = File.join @bag_path, 'manifest-sha1.txt'
78
- checksums = {}
79
- File.open(sha1_manifest).each_line do |line|
73
+ @bag.manifest!
74
+ sha1_manifest = File.join @bag_path, 'manifest-sha1.txt'
75
+ checksums = {}
76
+ File.open(sha1_manifest).each_line do |line|
80
77
  fixity, path = line.split(' ')
81
78
  checksums[path] = fixity
79
+ end
80
+ expected = checksums['data/big-data-file']
81
+ expect(expected).to eq('12be64c30968bb90136ee695dc58f4b2276968c6')
82
82
  end
83
- expected = checksums['data/big-data-file']
84
- expect(expected).to eq('12be64c30968bb90136ee695dc58f4b2276968c6')
85
- end
86
83
 
87
- it "should validate by oxum when needed" do
88
- expect(@bag.valid_oxum?).to eq(true)
89
- end
84
+ it "validates by oxum when needed" do
85
+ expect(@bag.valid_oxum?).to eq(true)
86
+ end
90
87
 
91
- it "should raise an sensible error when the manifest algorithm is unknown" do
92
- # add a manifest with an unsupported algorithm
93
- File.open(File.join(@bag.bag_dir, 'manifest-sha999.txt'), 'w') do |io|
94
- io.puts "digest-does-not-matter data/file-0\n"
95
- end
96
- expect { @bag.valid? }.to raise_error ArgumentError
97
- end
98
-
99
- it "should validate false by oxum when file count is incorrect" do
100
- # tweak oxum through backdoor
101
- File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: " + @bag.bag_info["Payload-Oxum"].split('.')[0] + '.0' }
102
- expect(@bag.valid_oxum?).to eq(false)
103
- end
88
+ it "raises a sensible error when the manifest algorithm is unknown" do
89
+ # add a manifest with an unsupported algorithm
90
+ File.open(File.join(@bag.bag_dir, 'manifest-sha999.txt'), 'w') do |io|
91
+ io.puts "digest-does-not-matter data/file-0\n"
92
+ end
93
+ expect { @bag.valid? }.to raise_error ArgumentError
94
+ end
104
95
 
105
- it "should validate false by oxum when octetstream size is incorrect" do
106
- # tweak oxum through backdoor
107
- File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: 1." + @bag.bag_info["Payload-Oxum"].split('.')[1] }
108
- expect(@bag.valid_oxum?).to eq(false)
109
- end
96
+ it "validates false by oxum when file count is incorrect" do
97
+ # tweak oxum through backdoor
98
+ File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: " + @bag.bag_info["Payload-Oxum"].split('.')[0] + '.0' }
99
+ expect(@bag.valid_oxum?).to eq(false)
100
+ end
110
101
 
111
- describe "tag manifest validation" do
112
- it "should be invalid if there are no manifest files at all even when there are no files" do
113
- #remove all files, tag/manifest files & tagmanifest files through the back door
114
- @bag.bag_files.each do |bag_file|
115
- FileUtils::rm bag_file
116
- end
117
- @bag.tag_files.each do |tag_file|
118
- FileUtils::rm tag_file
119
- end
120
- @bag.tagmanifest_files.each do |tagmanifest_file|
121
- FileUtils::rm tagmanifest_file
122
- end
102
+ it "validates false by oxum when octetstream size is incorrect" do
103
+ # tweak oxum through backdoor
104
+ File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: 1." + @bag.bag_info["Payload-Oxum"].split('.')[1] }
105
+ expect(@bag.valid_oxum?).to eq(false)
106
+ end
123
107
 
124
- # @bag.should_not be_valid
125
- expect(@bag).not_to be_valid
126
- expect(@bag.errors.on(:completeness)).not_to be_empty
108
+ describe "tag manifest validation" do
109
+ it "is invalid if there are no manifest files at all even when there are no files" do
110
+ # remove all files, tag/manifest files & tagmanifest files through the back door
111
+ @bag.bag_files.each do |bag_file|
112
+ FileUtils.rm bag_file
113
+ end
114
+ @bag.tag_files.each do |tag_file|
115
+ FileUtils.rm tag_file
116
+ end
117
+ @bag.tagmanifest_files.each do |tagmanifest_file|
118
+ FileUtils.rm tagmanifest_file
119
+ end
120
+
121
+ # @bag.should_not be_valid
122
+ expect(@bag).not_to be_valid
123
+ expect(@bag.errors.on(:completeness)).not_to be_empty
124
+ end
127
125
  end
128
- end
129
126
 
130
- describe "tag manifest validation" do
131
- it "should be invalid if listed tag file does not exist" do
132
- # add a file and then remove it through the back door
133
- @bag.add_tag_file("tag-k") { |io| io.puts 'time to go' }
134
- @bag.tagmanifest!
127
+ describe "tag manifest validation" do
128
+ it "is invalid if listed tag file does not exist" do
129
+ # add a file and then remove it through the back door
130
+ @bag.add_tag_file("tag-k") { |io| io.puts 'time to go' }
131
+ @bag.tagmanifest!
135
132
 
136
- FileUtils::rm File.join(@bag.bag_dir, 'tag-k')
133
+ FileUtils.rm File.join(@bag.bag_dir, 'tag-k')
137
134
 
138
- # @bag.should_not be_valid
139
- expect(@bag).not_to be_valid
140
- expect(@bag.errors.on(:completeness)).not_to be_empty
135
+ # @bag.should_not be_valid
136
+ expect(@bag).not_to be_valid
137
+ expect(@bag.errors.on(:completeness)).not_to be_empty
138
+ end
141
139
  end
142
140
  end
143
-
144
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bagit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson, Francesco Lazzarino, Jamie Little
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-14 00:00:00.000000000 Z
11
+ date: 2018-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: validatable
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.5.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: bixby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,35 +53,35 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.4'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.4'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: coveralls
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: coveralls
84
+ name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: pry-byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,19 +109,33 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: pry-byebug
112
+ name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '10.4'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '10.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3'
125
139
  description: Ruby Library and Command Line tools for bagit
126
140
  email: jamie@jamielittle.org
127
141
  executables:
@@ -130,6 +144,7 @@ extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
132
146
  - ".gitignore"
147
+ - ".rubocop.yml"
133
148
  - ".travis.yml"
134
149
  - Gemfile
135
150
  - LICENSE.txt