bagit 0.4.3 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bagit/valid.rb CHANGED
@@ -1,7 +1,9 @@
1
- require 'validatable'
2
- require 'open-uri'
3
- require 'cgi'
4
- require 'logger'
1
+ # frozen_string_literal: true
2
+
3
+ require "validatable"
4
+ require "open-uri"
5
+ require "cgi"
6
+ require "logger"
5
7
 
6
8
  module BagIt
7
9
  class Bag
@@ -12,8 +14,8 @@ module BagIt
12
14
 
13
15
  module Validity
14
16
  def decode_filename(s)
15
- s = s.gsub('%0D', "\r")
16
- s = s.gsub('%0A', "\n")
17
+ s = s.gsub("%0D", "\r")
18
+ s = s.gsub("%0A", "\n")
17
19
  s
18
20
  end
19
21
 
@@ -88,52 +90,52 @@ module BagIt
88
90
 
89
91
  protected
90
92
 
91
- # Returns all files in the instance that are not manifested
92
- def unmanifested_files
93
- mfs = manifested_files.map { |f| File.join bag_dir, f }
94
- bag_files.reject { |f| mfs.member? f }
95
- end
93
+ # Returns all files in the instance that are not manifested
94
+ def unmanifested_files
95
+ mfs = manifested_files.map { |f| File.join bag_dir, f }
96
+ bag_files.reject { |f| mfs.member? f }
97
+ end
96
98
 
97
- # Returns a list of manifested files that are not present
98
- def empty_manifests
99
- bfs = bag_files
100
- manifested_files.reject { |f| bfs.member? File.join(bag_dir, f) }
101
- end
99
+ # Returns a list of manifested files that are not present
100
+ def empty_manifests
101
+ bfs = bag_files
102
+ manifested_files.reject { |f| bfs.member? File.join(bag_dir, f) }
103
+ end
102
104
 
103
- # Returns a list of tag manifested files that are not present
104
- def tag_empty_manifests
105
- empty = []
106
- tag_manifested_files.each do |f|
107
- empty.push f unless File.exist?(File.join(bag_dir, f))
108
- end
109
- empty
105
+ # Returns a list of tag manifested files that are not present
106
+ def tag_empty_manifests
107
+ empty = []
108
+ tag_manifested_files.each do |f|
109
+ empty.push f unless File.exist?(File.join(bag_dir, f))
110
110
  end
111
+ empty
112
+ end
111
113
 
112
- # Returns a list of all files present in the manifest files
113
- def manifested_files
114
- manifest_files.inject([]) do |acc, mf|
115
- files = File.open(mf) do |io|
116
- io.readlines.map do |line|
117
- _digest, path = line.chomp.split(/\s+/, 2)
118
- decode_filename(path)
119
- end
114
+ # Returns a list of all files present in the manifest files
115
+ def manifested_files
116
+ manifest_files.inject([]) do |acc, mf|
117
+ files = File.open(mf) { |io|
118
+ io.readlines.map do |line|
119
+ _digest, path = line.chomp.split(/\s+/, 2)
120
+ decode_filename(path)
120
121
  end
122
+ }
121
123
 
122
- (acc + files).uniq
123
- end
124
+ (acc + files).uniq
124
125
  end
126
+ end
125
127
 
126
- # Returns a list of all files in the tag manifest files
127
- def tag_manifested_files
128
- tagmanifest_files.inject([]) do |acc, mf|
129
- files = File.open(mf) do |io|
130
- io.readlines.map do |line|
131
- _digest, path = line.chomp.split(/\s+/, 2)
132
- path
133
- end
128
+ # Returns a list of all files in the tag manifest files
129
+ def tag_manifested_files
130
+ tagmanifest_files.inject([]) do |acc, mf|
131
+ files = File.open(mf) { |io|
132
+ io.readlines.map do |line|
133
+ _digest, path = line.chomp.split(/\s+/, 2)
134
+ path
134
135
  end
135
- (acc + files).uniq
136
- end
136
+ }
137
+ (acc + files).uniq
137
138
  end
139
+ end
138
140
  end
139
141
  end
data/lib/bagit/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BagIt
2
- VERSION = "0.4.3".freeze
4
+ VERSION = "0.4.5"
3
5
  end
data/lib/bagit.rb CHANGED
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # == About bagit.rb
2
4
  # Author:: Francesco Lazzarino (mailto:flazzarino@gmail.com)
3
5
  # Functionality conforms to the BagIt Spec v0.96:
4
6
  # http://www.cdlib.org/inside/diglib/bagit/bagitspec.html
5
7
 
6
- require 'bagit/bag'
7
- require 'bagit/version'
8
- require 'fileutils'
9
- require 'date'
10
- require 'logger'
8
+ require "bagit/bag"
9
+ require "bagit/version"
10
+ require "fileutils"
11
+ require "date"
12
+ require "logger"
11
13
  module BagIt
12
14
  # The version of the BagIt specification the code is conforming to.
13
- SPEC_VERSION = '0.97'.freeze
15
+ SPEC_VERSION = "0.97"
14
16
  end
data/spec/bagit_spec.rb CHANGED
@@ -1,13 +1,14 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
3
4
 
4
5
  # based on v0.96 http://www.cdlib.org/inside/diglib/bagit/bagitspec.html
5
6
  RSpec.describe BagIt::Bag do
6
- describe 'empty bag' do
7
+ describe "empty bag" do
7
8
  before do
8
9
  @sandbox = Sandbox.new
9
10
  # make the bag
10
- @bag_path = File.join @sandbox.to_s, 'the_bag'
11
+ @bag_path = File.join @sandbox.to_s, "the_bag"
11
12
  @bag = described_class.new @bag_path
12
13
  end
13
14
 
@@ -20,16 +21,16 @@ RSpec.describe BagIt::Bag do
20
21
  end
21
22
  end
22
23
 
23
- describe 'bag with files' do
24
+ describe "bag with files" do
24
25
  before do
25
26
  @sandbox = Sandbox.new
26
27
 
27
28
  # make the bag
28
- @bag_path = File.join @sandbox.to_s, 'the_bag'
29
+ @bag_path = File.join @sandbox.to_s, "the_bag"
29
30
  @bag = described_class.new @bag_path
30
31
 
31
32
  # add some files
32
- File.open('/dev/urandom') do |rio|
33
+ File.open("/dev/urandom") do |rio|
33
34
  10.times do |n|
34
35
  @bag.add_file("file-#{n}-💩
35
36
  ") { |io| io.write rio.read(16) }
@@ -50,39 +51,39 @@ RSpec.describe BagIt::Bag do
50
51
  end
51
52
 
52
53
  it "has a sub-directory called data" do
53
- data_path = File.join @bag_path, 'data'
54
+ data_path = File.join @bag_path, "data"
54
55
  expect(File.directory?(data_path)).to be true
55
56
  end
56
57
 
57
58
  describe "#add_file" do
58
59
  it "allows addition of files via io" do
59
- @bag.add_file("foo") { |io| io.puts 'all alone' }
60
+ @bag.add_file("foo") { |io| io.puts "all alone" }
60
61
  expect(File.join(@bag_path, "data", "foo")).to exist_on_fs
61
62
  end
62
63
 
63
64
  it "allows addition of files via copy" do
64
- src_path = File.join @sandbox.to_s, 'somefile'
65
- File.open(src_path, 'w') { |io| io.puts "something" }
66
- @bag.add_file("foo", src_path) { |io| io.puts 'all alone' }
65
+ src_path = File.join @sandbox.to_s, "somefile"
66
+ File.open(src_path, "w") { |io| io.puts "something" }
67
+ @bag.add_file("foo", src_path) { |io| io.puts "all alone" }
67
68
  expect(File.join(@bag_path, "data", "foo")).to exist_on_fs
68
69
  end
69
70
 
70
71
  it "allows addition of files with deep paths" do
71
- @bag.add_file("deep/dir/structure/file") { |io| io.puts 'all alone' }
72
+ @bag.add_file("deep/dir/structure/file") { |io| io.puts "all alone" }
72
73
  expect(File.join(@bag_path, "data", "deep/dir/structure/file")).to exist_on_fs
73
74
  end
74
75
 
75
76
  it "does not allow overwriting of files" do
76
- expect do
77
+ expect {
77
78
  @bag.add_file("file-0-💩
78
- ") { |io| io.puts 'overwrite!' }
79
- end.to raise_error(RuntimeError)
79
+ ") { |io| io.puts "overwrite!" }
80
+ }.to raise_error(RuntimeError)
80
81
  end
81
82
 
82
83
  it "updates the payload oxum" do
83
- oxum_count = @bag.bag_info["Payload-Oxum"].split('.')[1].to_i
84
- @bag.add_file("foo") { |io| io.puts 'all alone' }
85
- expect(@bag.bag_info["Payload-Oxum"].split('.')[1].to_i).to eq(oxum_count + 1)
84
+ oxum_count = @bag.bag_info["Payload-Oxum"].split(".")[1].to_i
85
+ @bag.add_file("foo") { |io| io.puts "all alone" }
86
+ expect(@bag.bag_info["Payload-Oxum"].split(".")[1].to_i).to eq(oxum_count + 1)
86
87
  end
87
88
  end
88
89
 
@@ -95,14 +96,14 @@ RSpec.describe BagIt::Bag do
95
96
  describe "#get" do
96
97
  describe "file not in bag" do
97
98
  it "returns nil" do
98
- expect(@bag.get('foobar')).to be_nil
99
+ expect(@bag.get("foobar")).to be_nil
99
100
  end
100
101
  end
101
102
 
102
103
  describe "file in bag" do
103
104
  before do
104
- @contents = 'all alone'
105
- @bag.add_file("foo") { |io| io << 'all alone' }
105
+ @contents = "all alone"
106
+ @bag.add_file("foo") { |io| io << "all alone" }
106
107
  @file = @bag.get("foo")
107
108
  end
108
109
 
@@ -135,10 +136,10 @@ RSpec.describe BagIt::Bag do
135
136
  end
136
137
 
137
138
  it "returns relative paths to all files in the data directory" do
138
- expect(@paths).to match_array((0..9).collect do |x|
139
+ expect(@paths).to match_array((0..9).collect { |x|
139
140
  "file-#{x}-💩
140
141
  "
141
- end)
142
+ })
142
143
  end
143
144
  end
144
145
 
@@ -148,19 +149,19 @@ RSpec.describe BagIt::Bag do
148
149
  end
149
150
 
150
151
  it "accurately specifys the number of payload files" do
151
- @bag.add_tag_file('non-payload') { |f| f.puts "I shouldn't count in the oxum" }
152
- @bag.payload_oxum.split('.')[1] == @bag.bag_files.count
152
+ @bag.add_tag_file("non-payload") { |f| f.puts "I shouldn't count in the oxum" }
153
+ @bag.payload_oxum.split(".")[1] == @bag.bag_files.count
153
154
  end
154
155
  end
155
156
 
156
157
  describe "#gc!" do
157
158
  it "cleans up empty directories" do
158
159
  f = File.join "1", "2", "3", "file"
159
- @bag.add_file(f) { |io| io.puts 'all alone' }
160
+ @bag.add_file(f) { |io| io.puts "all alone" }
160
161
  @bag.remove_file f
161
- expect(File.exist?(File.dirname(File.join(@bag_path, 'data', f)))).to be true
162
+ expect(File.exist?(File.dirname(File.join(@bag_path, "data", f)))).to be true
162
163
  @bag.gc!
163
- expect(File.exist?(File.dirname(File.join(@bag_path, 'data', f)))).to be false
164
+ expect(File.exist?(File.dirname(File.join(@bag_path, "data", f)))).to be false
164
165
  end
165
166
  end
166
167
  end
data/spec/fetch_spec.rb CHANGED
@@ -1,15 +1,16 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
3
4
 
4
5
  describe BagIt::Bag do
5
6
  before do
6
7
  @sandbox = Sandbox.new
7
8
  # make the bag
8
- @bag_path = File.join @sandbox.to_s, 'the_bag'
9
+ @bag_path = File.join @sandbox.to_s, "the_bag"
9
10
  @bag = described_class.new(@bag_path)
10
11
 
11
12
  # add some files
12
- File.open('/dev/urandom') do |rio|
13
+ File.open("/dev/urandom") do |rio|
13
14
  10.times do |n|
14
15
  @bag.add_file("file-#{n}-💩
15
16
  end
@@ -21,11 +22,11 @@ describe BagIt::Bag do
21
22
  end
22
23
 
23
24
  before do
24
- @bag.add_remote_file('http://www.gnu.org/graphics/heckert_gnu.small.png', 'gnu.png', 6322,
25
- '390c0a30976f899cbdf951eab5cce60fe9743ac9',
26
- 'a3bd7ab2442028bb91b51d9f6722ec98')
25
+ @bag.add_remote_file("http://www.gnu.org/graphics/heckert_gnu.small.png", "gnu.png", 6322,
26
+ "390c0a30976f899cbdf951eab5cce60fe9743ac9",
27
+ "a3bd7ab2442028bb91b51d9f6722ec98")
27
28
 
28
- path = File.join @bag_path, 'fetch.txt'
29
+ path = File.join @bag_path, "fetch.txt"
29
30
  @lines = File.open(path, &:readlines)
30
31
  end
31
32
 
@@ -34,18 +35,18 @@ describe BagIt::Bag do
34
35
  end
35
36
 
36
37
  it "only contains lines of the format URL LENGTH FILENAME" do
37
- @lines.each { |line| expect(line.chomp).to match(/^[^\s]+\s+(\d+|\-)\s+[^\s]+$/) }
38
+ @lines.each { |line| expect(line.chomp).to match(/^[^\s]+\s+(\d+|-)\s+[^\s]+$/) }
38
39
  end
39
40
 
40
41
  it "contains manifested files" do
41
- path = File.join @bag_path, 'manifest-sha1.txt'
42
+ path = File.join @bag_path, "manifest-sha1.txt"
42
43
  data = File.open(path, &:read)
43
- expect(data).to include('gnu.png')
44
+ expect(data).to include("gnu.png")
44
45
  end
45
46
 
46
47
  it "is gone when fetch is complete" do
47
48
  @bag.fetch!
48
- expect(File.exist?(File.join(@bag_path, 'fetch.txt'))).not_to be true
49
+ expect(File.exist?(File.join(@bag_path, "fetch.txt"))).not_to be true
49
50
  end
50
51
  end
51
52
  end
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
3
4
 
4
5
  describe BagIt::Bag do
5
6
  describe "BagIt Manifests" do
@@ -7,13 +8,14 @@ describe BagIt::Bag do
7
8
  @sandbox = Sandbox.new
8
9
 
9
10
  # make the bag
10
- @bag_path = File.join @sandbox.to_s, 'the_bag'
11
+ @bag_path = File.join @sandbox.to_s, "the_bag"
11
12
  @bag = described_class.new @bag_path
12
13
 
13
14
  # add some files
14
- File.open('/dev/urandom') do |rio|
15
+ File.open("/dev/urandom") do |rio|
15
16
  10.times do |n|
16
- @bag.add_file("file-#{n}-💩
17
+ @bag.add_file("file-#{n}-💩
18
+ ") { |io| io.write rio.read(16) }
17
19
  @bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
18
20
  end
19
21
  end
@@ -25,13 +27,16 @@ describe BagIt::Bag do
25
27
 
26
28
  shared_examples_for "a manifest file" do
27
29
  before do
28
- pattern = File.join @bag_path, '*manifest-*.txt'
30
+ pattern = File.join @bag_path, "*manifest-*.txt"
29
31
  @manifest_files = Dir.glob pattern
30
32
  end
31
33
 
32
34
  it "has a valid algorithm in the name (at least md5 or sha1)" do
33
- algorithms = @manifest_files.map { |mf| mf =~ /manifest-(.*).txt$/; Regexp.last_match(1) }
34
- algorithms.each { |a| expect(a).to be_in('md5', 'sha1') }
35
+ algorithms = @manifest_files.map { |mf|
36
+ mf =~ /manifest-(.*).txt$/
37
+ Regexp.last_match(1)
38
+ }
39
+ algorithms.each { |a| expect(a).to be_in("md5", "sha1") }
35
40
  end
36
41
 
37
42
  it "is not an empty file" do
@@ -47,7 +52,7 @@ describe BagIt::Bag do
47
52
  end
48
53
 
49
54
  it "validates after adding a file and remanifesting" do
50
- @bag.add_file('newfile.txt') { |io| io.puts("new file to remanifest") }
55
+ @bag.add_file("newfile.txt") { |io| io.puts("new file to remanifest") }
51
56
  @bag.manifest!
52
57
  expect(@bag).to be_valid
53
58
  end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,27 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'coveralls'
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+ require "coveralls"
4
6
 
5
7
  Bundler.require(:default, :test)
6
8
 
7
9
  Coveralls.wear!
8
10
 
9
- require File.expand_path('./util/bagit_matchers', File.dirname(__FILE__))
11
+ require File.expand_path("./util/bagit_matchers", File.dirname(__FILE__))
10
12
 
11
13
  RSpec.configure do |config|
12
14
  config.include(BagitMatchers)
13
15
  end
14
16
 
15
- $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
16
- require 'bagit'
17
+ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
18
+ require "bagit"
17
19
 
18
- require 'tempfile'
20
+ require "tempfile"
19
21
 
20
22
  class Sandbox
21
23
  def initialize
22
- tf = Tempfile.open 'sandbox'
24
+ tf = Tempfile.open "sandbox"
23
25
  @path = tf.path
24
26
  tf.close!
25
27
  FileUtils.mkdir @path
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
3
4
 
4
5
  describe BagIt::Bag do
5
6
  describe "Tag Info Files" do
@@ -7,11 +8,11 @@ describe BagIt::Bag do
7
8
  @sandbox = Sandbox.new
8
9
 
9
10
  # make the bag
10
- @bag_path = File.join @sandbox.to_s, 'the_bag'
11
+ @bag_path = File.join @sandbox.to_s, "the_bag"
11
12
  @bag = described_class.new @bag_path
12
13
 
13
14
  # add some files
14
- File.open('/dev/urandom') do |rio|
15
+ File.open("/dev/urandom") do |rio|
15
16
  10.times do |n|
16
17
  @bag.add_file("file-#{n}-💩
17
18
  end
@@ -24,12 +25,12 @@ describe BagIt::Bag do
24
25
 
25
26
  describe "bagit.txt" do
26
27
  before do
27
- path = File.join @bag_path, 'bagit.txt'
28
+ path = File.join @bag_path, "bagit.txt"
28
29
  @lines = File.open(path, &:readlines)
29
30
  end
30
31
 
31
32
  it "creates a file bagit.txt on bag initialization" do
32
- expect(File.join(@bag_path, 'bagit.txt')).to exist_on_fs
33
+ expect(File.join(@bag_path, "bagit.txt")).to exist_on_fs
33
34
  end
34
35
 
35
36
  it "has exactly two lines" do
@@ -49,7 +50,7 @@ describe BagIt::Bag do
49
50
 
50
51
  describe "bag-info.txt" do
51
52
  before do
52
- path = File.join @bag_path, 'bag-info.txt'
53
+ path = File.join @bag_path, "bag-info.txt"
53
54
  @lines = File.open(path, &:readlines)
54
55
  end
55
56
 
@@ -62,20 +63,20 @@ describe BagIt::Bag do
62
63
  end
63
64
 
64
65
  it "is case insensitive with respect to LABELs" do
65
- expect { @bag.write_bag_info 'foo' => 'lowercase', 'Foo' => 'capital' }.to raise_error(/Multiple labels/)
66
+ expect { @bag.write_bag_info "foo" => "lowercase", "Foo" => "capital" }.to raise_error(/Multiple labels/)
66
67
  end
67
68
 
68
69
  it "folds long VALUEs" do
69
- longline = <<LOREM
70
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
71
- eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad
72
- minim veniam, quis nostrud exercitation ullamco laboris nisi ut
73
- aliquip ex ea commodo consequat. Duis aute irure dolor in
74
- reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
75
- pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
76
- culpa qui officia deserunt mollit anim id est laborum.
77
- LOREM
78
- @bag.write_bag_info 'Lorem' => longline
70
+ longline = <<~LOREM
71
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
72
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad
73
+ minim veniam, quis nostrud exercitation ullamco laboris nisi ut
74
+ aliquip ex ea commodo consequat. Duis aute irure dolor in
75
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
76
+ pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
77
+ culpa qui officia deserunt mollit anim id est laborum.
78
+ LOREM
79
+ @bag.write_bag_info "Lorem" => longline
79
80
  expect(@bag.bag_info.keys.length).to eq(4) # this isn't a great test. Changed it from 1 to 4 because unrelated changes caused failure.
80
81
  end
81
82
 
@@ -92,10 +93,10 @@ LOREM
92
93
  expect(@bag.bag_info.keys).to include("Payload-Oxum")
93
94
  end
94
95
  it "does not override any previous values" do
95
- path = File.join @bag_path, 'bag-info.txt'
96
- @bag.write_bag_info 'Bag-Software-Agent' => 'Some Other Agent'
97
- @bag.write_bag_info 'Source-Organization' => 'Awesome Inc.'
98
- @bag.write_bag_info 'Bagging-Date' => '1901-01-01'
96
+ path = File.join @bag_path, "bag-info.txt"
97
+ @bag.write_bag_info "Bag-Software-Agent" => "Some Other Agent"
98
+ @bag.write_bag_info "Source-Organization" => "Awesome Inc."
99
+ @bag.write_bag_info "Bagging-Date" => "1901-01-01"
99
100
  @bag.write_bag_info
100
101
  contents = File.open(path).read
101
102
  expect(contents).to include "Some Other Agent"
@@ -103,19 +104,19 @@ LOREM
103
104
  expect(contents).to include "1901-01-01"
104
105
  end
105
106
  it "overrides previous tags when they collide with new ones" do
106
- path = File.join @bag_path, 'bag-info.txt'
107
- @bag.write_bag_info 'Source-Organization' => 'Awesome Inc.'
108
- @bag.write_bag_info 'Source-Organization' => 'Awesome LLC.'
107
+ path = File.join @bag_path, "bag-info.txt"
108
+ @bag.write_bag_info "Source-Organization" => "Awesome Inc."
109
+ @bag.write_bag_info "Source-Organization" => "Awesome LLC."
109
110
  contents = File.open(path).read
110
111
  expect(contents).to include "Awesome LLC."
111
112
  expect(contents).not_to include "Awesome Inc."
112
113
  end
113
114
  it "contains values passed to bag" do
114
- hash = { "Bag-Software-Agent" => "rspec",
115
- "Bagging-Date" => "2012-11-21",
116
- "Contact-Name" => "Willis Corto",
117
- "Some-Tag" => "Some Value" }
118
- bag_with_info = described_class.new(@bag_path + '2', hash)
115
+ hash = {"Bag-Software-Agent" => "rspec",
116
+ "Bagging-Date" => "2012-11-21",
117
+ "Contact-Name" => "Willis Corto",
118
+ "Some-Tag" => "Some Value"}
119
+ bag_with_info = described_class.new(@bag_path + "2", hash)
119
120
  hash.each do |key, value|
120
121
  expect(bag_with_info.bag_info[key]).to eq(value)
121
122
  end
data/spec/tag_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
3
4
 
4
5
  describe BagIt::Bag do
5
6
  describe "Tag Specs" do
@@ -7,11 +8,11 @@ describe BagIt::Bag do
7
8
  @sandbox = Sandbox.new
8
9
 
9
10
  # make the bag
10
- @bag_path = File.join @sandbox.to_s, 'the_bag'
11
+ @bag_path = File.join @sandbox.to_s, "the_bag"
11
12
  @bag = described_class.new(@bag_path)
12
13
 
13
14
  # add some files
14
- File.open('/dev/urandom') do |rio|
15
+ File.open("/dev/urandom") do |rio|
15
16
  10.times do |n|
16
17
  @bag.add_file("file-#{n}-💩
17
18
  @bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
@@ -24,11 +25,11 @@ describe BagIt::Bag do
24
25
  end
25
26
  describe "#add_tag_file" do
26
27
  it "allows addition of tag files via io" do
27
- @bag.add_tag_file("foo") { |io| io.puts 'all alone' }
28
+ @bag.add_tag_file("foo") { |io| io.puts "all alone" }
28
29
  expect(File.join(@bag_path, "foo")).to exist_on_fs
29
30
  end
30
31
  it "allows addition of bag files within directories using io" do
31
- @bag.add_tag_file("fedora/foo") { |io| io.puts 'all alone' }
32
+ @bag.add_tag_file("fedora/foo") { |io| io.puts "all alone" }
32
33
  expect(File.join(@bag_path, "fedora", "foo")).to exist_on_fs
33
34
  end
34
35
  it "allows addition of deep tag files" do
@@ -36,12 +37,12 @@ describe BagIt::Bag do
36
37
  expect(File.join(@bag_path, "fedora", "foo", "newfoo", "deep")).to exist_on_fs
37
38
  end
38
39
  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
+ expect { @bag.add_tag_file("tag-0") { |io| io.puts "overwrite!" } }.to raise_error(RuntimeError)
40
41
  end
41
42
  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' }
43
+ src_path = File.join @sandbox.to_s, "somefile"
44
+ File.open(src_path, "w") { |io| io.puts "something" }
45
+ @bag.add_tag_file("foo", src_path) { |io| io.puts "all alone" }
45
46
  expect(File.join(@bag_path, "foo")).to exist_on_fs
46
47
  end
47
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BagitMatchers
2
4
  class BeIn
3
5
  def initialize(*expected_collection)