iiif-presentation 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +8 -1
- data/.standard.yml +1 -0
- data/Gemfile +5 -5
- data/README.md +1 -1
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/bin/standardrb +16 -0
- data/iiif-presentation.gemspec +23 -23
- data/lib/iiif/hash_behaviours.rb +29 -33
- data/lib/iiif/ordered_hash.rb +33 -33
- data/lib/iiif/presentation/abstract_resource.rb +17 -22
- data/lib/iiif/presentation/annotation.rb +9 -11
- data/lib/iiif/presentation/annotation_list.rb +8 -10
- data/lib/iiif/presentation/canvas.rb +11 -13
- data/lib/iiif/presentation/collection.rb +7 -9
- data/lib/iiif/presentation/image_resource.rb +33 -35
- data/lib/iiif/presentation/layer.rb +8 -10
- data/lib/iiif/presentation/manifest.rb +9 -12
- data/lib/iiif/presentation/range.rb +8 -10
- data/lib/iiif/presentation/resource.rb +5 -7
- data/lib/iiif/presentation/sequence.rb +8 -11
- data/lib/iiif/presentation/service.rb +1 -2
- data/lib/iiif/presentation.rb +7 -7
- data/lib/iiif/service.rb +121 -102
- data/lib/iiif/v3/abstract_resource.rb +132 -144
- data/lib/iiif/v3/presentation/annotation.rb +20 -21
- data/lib/iiif/v3/presentation/annotation_collection.rb +7 -9
- data/lib/iiif/v3/presentation/annotation_page.rb +14 -15
- data/lib/iiif/v3/presentation/canvas.rb +21 -22
- data/lib/iiif/v3/presentation/choice.rb +14 -15
- data/lib/iiif/v3/presentation/collection.rb +7 -8
- data/lib/iiif/v3/presentation/image_resource.rb +21 -22
- data/lib/iiif/v3/presentation/manifest.rb +18 -19
- data/lib/iiif/v3/presentation/nav_place.rb +125 -29
- data/lib/iiif/v3/presentation/range.rb +10 -10
- data/lib/iiif/v3/presentation/resource.rb +4 -5
- data/lib/iiif/v3/presentation/sequence.rb +10 -11
- data/lib/iiif/v3/presentation/service.rb +12 -13
- data/lib/iiif/v3/presentation.rb +8 -8
- data/spec/integration/iiif/presentation/image_resource_spec.rb +54 -58
- data/spec/integration/iiif/service_spec.rb +76 -77
- data/spec/integration/iiif/v3/abstract_resource_spec.rb +73 -73
- data/spec/integration/iiif/v3/presentation/image_resource_spec.rb +53 -56
- data/spec/spec_helper.rb +56 -64
- data/spec/unit/iiif/hash_behaviours_spec.rb +384 -387
- data/spec/unit/iiif/ordered_hash_spec.rb +86 -91
- data/spec/unit/iiif/presentation/abstract_resource_spec.rb +64 -70
- data/spec/unit/iiif/presentation/annotation_list_spec.rb +1 -3
- data/spec/unit/iiif/presentation/annotation_spec.rb +1 -3
- data/spec/unit/iiif/presentation/canvas_spec.rb +11 -14
- data/spec/unit/iiif/presentation/collection_spec.rb +26 -33
- data/spec/unit/iiif/presentation/image_resource_spec.rb +4 -6
- data/spec/unit/iiif/presentation/layer_spec.rb +16 -20
- data/spec/unit/iiif/presentation/manifest_spec.rb +45 -48
- data/spec/unit/iiif/presentation/range_spec.rb +18 -22
- data/spec/unit/iiif/presentation/resource_spec.rb +3 -6
- data/spec/unit/iiif/presentation/sequence_spec.rb +58 -63
- data/spec/unit/iiif/presentation/shared_examples/abstract_resource_only_keys.rb +4 -10
- data/spec/unit/iiif/presentation/shared_examples/any_type_keys.rb +5 -9
- data/spec/unit/iiif/presentation/shared_examples/array_only_keys.rb +9 -17
- data/spec/unit/iiif/presentation/shared_examples/int_only_keys.rb +6 -14
- data/spec/unit/iiif/presentation/shared_examples/string_only_keys.rb +6 -13
- data/spec/unit/iiif/service_spec.rb +8 -13
- data/spec/unit/iiif/v3/abstract_resource_define_methods_for_spec.rb +39 -37
- data/spec/unit/iiif/v3/abstract_resource_spec.rb +128 -143
- data/spec/unit/iiif/v3/presentation/annotation_collection_spec.rb +14 -17
- data/spec/unit/iiif/v3/presentation/annotation_page_spec.rb +71 -69
- data/spec/unit/iiif/v3/presentation/annotation_spec.rb +249 -233
- data/spec/unit/iiif/v3/presentation/canvas_spec.rb +211 -193
- data/spec/unit/iiif/v3/presentation/choice_spec.rb +81 -77
- data/spec/unit/iiif/v3/presentation/collection_spec.rb +24 -29
- data/spec/unit/iiif/v3/presentation/image_resource_spec.rb +70 -71
- data/spec/unit/iiif/v3/presentation/manifest_spec.rb +248 -237
- data/spec/unit/iiif/v3/presentation/nav_place_spec.rb +249 -49
- data/spec/unit/iiif/v3/presentation/range_spec.rb +28 -29
- data/spec/unit/iiif/v3/presentation/resource_spec.rb +83 -82
- data/spec/unit/iiif/v3/presentation/sequence_spec.rb +126 -120
- data/spec/unit/iiif/v3/presentation/service_spec.rb +123 -124
- data/spec/unit/iiif/v3/presentation/shared_examples/abstract_resource_only_keys.rb +4 -8
- data/spec/unit/iiif/v3/presentation/shared_examples/any_type_keys.rb +5 -7
- data/spec/unit/iiif/v3/presentation/shared_examples/array_only_keys.rb +9 -13
- data/spec/unit/iiif/v3/presentation/shared_examples/hash_only_keys.rb +9 -13
- data/spec/unit/iiif/v3/presentation/shared_examples/int_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/numeric_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/string_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/uri_only_keys.rb +9 -13
- metadata +27 -69
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
|
2
|
-
require
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../../spec_helper")
|
|
2
|
+
require "active_support/ordered_hash"
|
|
3
3
|
describe IIIF::HashBehaviours do
|
|
4
|
-
|
|
5
4
|
let(:hash_like_class) do
|
|
6
5
|
Class.new do
|
|
7
6
|
include IIIF::HashBehaviours
|
|
7
|
+
|
|
8
8
|
attr_accessor :data # Accessible for easier expects...not sure you'd do this in a real class
|
|
9
|
-
def initialize
|
|
9
|
+
def initialize
|
|
10
10
|
@data = IIIF::OrderedHash.new
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -15,291 +15,290 @@ describe IIIF::HashBehaviours do
|
|
|
15
15
|
# TODO: let(:init_data)...rather than repeating so much below
|
|
16
16
|
subject { hash_like_class.new }
|
|
17
17
|
|
|
18
|
-
describe
|
|
19
|
-
it
|
|
20
|
-
subject[
|
|
21
|
-
expect(subject.data).to eq({
|
|
22
|
-
end
|
|
23
|
-
it
|
|
24
|
-
subject[
|
|
25
|
-
subject[
|
|
26
|
-
subject[
|
|
27
|
-
expect(subject.data[subject.data.keys.last]).to eq
|
|
28
|
-
end
|
|
29
|
-
it
|
|
30
|
-
subject[
|
|
31
|
-
subject[
|
|
32
|
-
subject[
|
|
33
|
-
subject[
|
|
34
|
-
expect(subject.data.
|
|
18
|
+
describe "#[]=" do
|
|
19
|
+
it "assigns a new k and value to the node" do
|
|
20
|
+
subject["foo"] = "bar"
|
|
21
|
+
expect(subject.data).to eq({"foo" => "bar"})
|
|
22
|
+
end
|
|
23
|
+
it "always puts new entries at the end" do
|
|
24
|
+
subject["baz"] = "qux"
|
|
25
|
+
subject["quux"] = "corge"
|
|
26
|
+
subject["grault"] = "garply"
|
|
27
|
+
expect(subject.data[subject.data.keys.last]).to eq "garply"
|
|
28
|
+
end
|
|
29
|
+
it "replaces keys that already exist in the same place" do
|
|
30
|
+
subject["waldo"] = "fred"
|
|
31
|
+
subject["plugh"] = "xyzzy"
|
|
32
|
+
subject["thud"] = "wibble"
|
|
33
|
+
subject["plugh"] = "wobble"
|
|
34
|
+
expect(subject.data.slice("plugh")).to eq({"plugh" => "wobble"})
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
describe
|
|
39
|
-
it
|
|
40
|
-
subject[
|
|
41
|
-
subject[
|
|
42
|
-
expect(subject[
|
|
38
|
+
describe "#[]" do
|
|
39
|
+
it "retrieves the expected value" do
|
|
40
|
+
subject["wibble"] = "wobble"
|
|
41
|
+
subject["wubble"] = "fred"
|
|
42
|
+
expect(subject["wibble"]).to eq "wobble"
|
|
43
43
|
end
|
|
44
|
-
it
|
|
45
|
-
subject[
|
|
46
|
-
subject[
|
|
47
|
-
expect(subject[
|
|
44
|
+
it "returns nil if the key is not found" do
|
|
45
|
+
subject["wibble"] = "wobble"
|
|
46
|
+
subject["wubble"] = "fred"
|
|
47
|
+
expect(subject["flob"]).to be_nil
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
describe
|
|
52
|
-
it
|
|
53
|
-
subject[
|
|
54
|
-
subject[
|
|
51
|
+
describe "#clear" do
|
|
52
|
+
it "clears all properties" do
|
|
53
|
+
subject["wibble"] = "wobble"
|
|
54
|
+
subject["wubble"] = "fred"
|
|
55
55
|
subject.clear
|
|
56
56
|
expect(subject.keys).to eq []
|
|
57
57
|
end
|
|
58
|
-
it
|
|
59
|
-
subject[
|
|
60
|
-
subject[
|
|
58
|
+
it "returns the instance on which it was called" do
|
|
59
|
+
subject["wibble"] = "wobble"
|
|
60
|
+
subject["wubble"] = "fred"
|
|
61
61
|
expect(subject.clear).to eq subject
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
describe
|
|
66
|
-
it
|
|
67
|
-
subject[
|
|
68
|
-
subject[
|
|
69
|
-
subject.delete(
|
|
70
|
-
expect(subject.data).to eq({
|
|
71
|
-
end
|
|
72
|
-
it
|
|
73
|
-
subject[
|
|
74
|
-
subject[
|
|
75
|
-
expect(subject.delete(
|
|
76
|
-
end
|
|
77
|
-
it
|
|
78
|
-
subject[
|
|
79
|
-
subject[
|
|
80
|
-
expect { |b| subject.delete(
|
|
81
|
-
expect(subject.delete(
|
|
65
|
+
describe "#delete" do
|
|
66
|
+
it "removes an entry from the object" do
|
|
67
|
+
subject["waldo"] = "fred"
|
|
68
|
+
subject["plugh"] = "xyzzy"
|
|
69
|
+
subject.delete("waldo")
|
|
70
|
+
expect(subject.data).to eq({"plugh" => "xyzzy"})
|
|
71
|
+
end
|
|
72
|
+
it "returns the value of the entry that was removed" do
|
|
73
|
+
subject["waldo"] = "fred"
|
|
74
|
+
subject["plugh"] = "xyzzy"
|
|
75
|
+
expect(subject.delete("waldo")).to eq "fred"
|
|
76
|
+
end
|
|
77
|
+
it "can take a block as well" do
|
|
78
|
+
subject["waldo"] = "fred"
|
|
79
|
+
subject["plugh"] = "xyzzy"
|
|
80
|
+
expect { |b| subject.delete("wubble", &b) }.to yield_with_args
|
|
81
|
+
expect(subject.delete("foo") { |e| e.reverse }).to eq "oof"
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
describe
|
|
86
|
-
it
|
|
87
|
-
subject[
|
|
88
|
-
subject[
|
|
89
|
-
subject[
|
|
90
|
-
expect { |b| subject.delete_if(&b) }.to yield_successive_args([
|
|
91
|
-
end
|
|
92
|
-
it
|
|
93
|
-
subject[
|
|
94
|
-
subject[
|
|
95
|
-
subject[
|
|
96
|
-
expect(
|
|
97
|
-
end
|
|
98
|
-
it
|
|
99
|
-
subject[
|
|
100
|
-
subject[
|
|
101
|
-
subject[
|
|
102
|
-
subject.delete_if { |k,v| k.start_with?(
|
|
103
|
-
expect(subject.data).to eq({
|
|
104
|
-
end
|
|
105
|
-
it
|
|
106
|
-
subject[
|
|
107
|
-
subject[
|
|
108
|
-
subject[
|
|
85
|
+
describe "#delete_if" do
|
|
86
|
+
it "can take a block" do
|
|
87
|
+
subject["wibble"] = "foo"
|
|
88
|
+
subject["waldo"] = "fred"
|
|
89
|
+
subject["plugh"] = "xyzzy"
|
|
90
|
+
expect { |b| subject.delete_if(&b) }.to yield_successive_args(["wibble", "foo"], ["waldo", "fred"], ["plugh", "xyzzy"])
|
|
91
|
+
end
|
|
92
|
+
it "returns the instance" do
|
|
93
|
+
subject["wibble"] = "foo"
|
|
94
|
+
subject["waldo"] = "fred"
|
|
95
|
+
subject["plugh"] = "xyzzy"
|
|
96
|
+
expect(subject.delete_if { |k, v| k.start_with?("w") }).to eq subject
|
|
97
|
+
end
|
|
98
|
+
it "works" do
|
|
99
|
+
subject["wibble"] = "foo"
|
|
100
|
+
subject["waldo"] = "fred"
|
|
101
|
+
subject["plugh"] = "xyzzy"
|
|
102
|
+
subject.delete_if { |k, v| k.start_with?("w") }
|
|
103
|
+
expect(subject.data).to eq({"plugh" => "xyzzy"})
|
|
104
|
+
end
|
|
105
|
+
it "returns an enumerator if no block is supplied" do
|
|
106
|
+
subject["wibble"] = "foo"
|
|
107
|
+
subject["waldo"] = "fred"
|
|
108
|
+
subject["plugh"] = "xyzzy"
|
|
109
109
|
expect(subject.delete_if).to be_a Enumerator
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
-
describe
|
|
114
|
-
it
|
|
115
|
-
subject[
|
|
113
|
+
describe "#each" do
|
|
114
|
+
it "yields" do
|
|
115
|
+
subject["plugh"] = "xyzzy"
|
|
116
116
|
expect { |b| subject.each(&b) }.to yield_with_args
|
|
117
117
|
end
|
|
118
|
-
it
|
|
119
|
-
subject.data[
|
|
120
|
-
subject.data[
|
|
121
|
-
expect(subject.each { |k,v| nil }).to eq subject
|
|
118
|
+
it "returns the instance" do
|
|
119
|
+
subject.data["waldo"] = "fred"
|
|
120
|
+
subject.data["plugh"] = "xyzzy"
|
|
121
|
+
expect(subject.each { |k, v| nil }).to eq subject
|
|
122
122
|
end
|
|
123
|
-
it
|
|
124
|
-
subject.data[
|
|
125
|
-
subject.data[
|
|
126
|
-
subject.data[
|
|
123
|
+
it "loops as expected" do
|
|
124
|
+
subject.data["wibble"] = "foo"
|
|
125
|
+
subject.data["waldo"] = "fred"
|
|
126
|
+
subject.data["plugh"] = "xyzzy"
|
|
127
127
|
capped_keys = []
|
|
128
|
-
subject.each { |k,v| capped_keys << k.capitalize }
|
|
129
|
-
expect(capped_keys).to eq [
|
|
128
|
+
subject.each { |k, v| capped_keys << k.capitalize }
|
|
129
|
+
expect(capped_keys).to eq ["Wibble", "Waldo", "Plugh"]
|
|
130
130
|
end
|
|
131
|
-
it
|
|
132
|
-
subject[
|
|
133
|
-
subject[
|
|
134
|
-
subject[
|
|
131
|
+
it "returns an enumerator if no block is supplied" do
|
|
132
|
+
subject["wibble"] = "foo"
|
|
133
|
+
subject["waldo"] = "fred"
|
|
134
|
+
subject["plugh"] = "xyzzy"
|
|
135
135
|
expect(subject.delete_if).to be_a Enumerator
|
|
136
136
|
end
|
|
137
137
|
end
|
|
138
138
|
|
|
139
|
-
describe
|
|
140
|
-
it
|
|
141
|
-
subject[
|
|
139
|
+
describe "#each_key" do
|
|
140
|
+
it "yields" do
|
|
141
|
+
subject["plugh"] = "xyzzy"
|
|
142
142
|
expect { |b| subject.each_key(&b) }.to yield_with_args
|
|
143
143
|
end
|
|
144
|
-
it
|
|
145
|
-
subject.data[
|
|
146
|
-
subject.data[
|
|
144
|
+
it "returns the instance" do
|
|
145
|
+
subject.data["waldo"] = "fred"
|
|
146
|
+
subject.data["plugh"] = "xyzzy"
|
|
147
147
|
expect(subject.each_key { |k| nil }).to eq subject
|
|
148
148
|
end
|
|
149
|
-
it
|
|
150
|
-
subject[
|
|
151
|
-
subject[
|
|
152
|
-
subject[
|
|
149
|
+
it "loops as expected" do
|
|
150
|
+
subject["wibble"] = "foo"
|
|
151
|
+
subject["waldo"] = "fred"
|
|
152
|
+
subject["plugh"] = "xyzzy"
|
|
153
153
|
key_accumulator = []
|
|
154
154
|
subject.each_key { |k| key_accumulator << k }
|
|
155
|
-
expect(key_accumulator).to eq [
|
|
155
|
+
expect(key_accumulator).to eq ["wibble", "waldo", "plugh"]
|
|
156
156
|
end
|
|
157
|
-
it
|
|
158
|
-
subject[
|
|
159
|
-
subject[
|
|
160
|
-
subject[
|
|
157
|
+
it "returns an enumerator if no block is supplied" do
|
|
158
|
+
subject["wibble"] = "foo"
|
|
159
|
+
subject["waldo"] = "fred"
|
|
160
|
+
subject["plugh"] = "xyzzy"
|
|
161
161
|
expect(subject.each_key).to be_a Enumerator
|
|
162
162
|
end
|
|
163
163
|
end
|
|
164
164
|
|
|
165
|
-
describe
|
|
166
|
-
it
|
|
167
|
-
subject[
|
|
165
|
+
describe "#each_value" do
|
|
166
|
+
it "yields" do
|
|
167
|
+
subject["plugh"] = "xyzzy"
|
|
168
168
|
expect { |b| subject.each_value(&b) }.to yield_with_args
|
|
169
169
|
end
|
|
170
|
-
it
|
|
171
|
-
subject.data[
|
|
172
|
-
subject.data[
|
|
170
|
+
it "returns the instance" do
|
|
171
|
+
subject.data["waldo"] = "fred"
|
|
172
|
+
subject.data["plugh"] = "xyzzy"
|
|
173
173
|
expect(subject.each_value { |v| nil }).to eq subject
|
|
174
174
|
end
|
|
175
|
-
it
|
|
176
|
-
subject[
|
|
177
|
-
subject[
|
|
178
|
-
subject[
|
|
175
|
+
it "loops as expected" do
|
|
176
|
+
subject["wibble"] = "foo"
|
|
177
|
+
subject["waldo"] = "fred"
|
|
178
|
+
subject["plugh"] = "xyzzy"
|
|
179
179
|
value_accumulator = []
|
|
180
180
|
subject.each_value { |v| value_accumulator << v }
|
|
181
|
-
expect(value_accumulator).to eq [
|
|
181
|
+
expect(value_accumulator).to eq ["foo", "fred", "xyzzy"]
|
|
182
182
|
end
|
|
183
|
-
it
|
|
184
|
-
subject[
|
|
185
|
-
subject[
|
|
186
|
-
subject[
|
|
183
|
+
it "returns an enumerator if no block is supplied" do
|
|
184
|
+
subject["wibble"] = "foo"
|
|
185
|
+
subject["waldo"] = "fred"
|
|
186
|
+
subject["plugh"] = "xyzzy"
|
|
187
187
|
expect(subject.each_value).to be_a Enumerator
|
|
188
188
|
end
|
|
189
|
-
|
|
190
189
|
end
|
|
191
190
|
|
|
192
|
-
describe
|
|
193
|
-
it
|
|
191
|
+
describe "#empty" do
|
|
192
|
+
it "returns true when there are no entries" do
|
|
194
193
|
expect(subject.empty?).to be_truthy
|
|
195
194
|
end
|
|
196
|
-
it
|
|
197
|
-
subject[
|
|
195
|
+
it "returns false when we have data" do
|
|
196
|
+
subject["waldo"] = "fred"
|
|
198
197
|
expect(subject.empty?).to be_falsey
|
|
199
198
|
end
|
|
200
199
|
end
|
|
201
200
|
|
|
202
|
-
describe
|
|
203
|
-
it
|
|
204
|
-
subject[
|
|
205
|
-
subject[
|
|
206
|
-
expect(subject.fetch(
|
|
207
|
-
end
|
|
208
|
-
it
|
|
209
|
-
subject[
|
|
210
|
-
subject[
|
|
211
|
-
expect(subject.fetch(
|
|
212
|
-
end
|
|
213
|
-
it
|
|
214
|
-
expect { subject.fetch(
|
|
215
|
-
end
|
|
216
|
-
it
|
|
217
|
-
subject[
|
|
218
|
-
subject[
|
|
219
|
-
expect(subject.fetch(
|
|
220
|
-
expect { |b| subject.fetch(
|
|
221
|
-
expect(subject.fetch(
|
|
201
|
+
describe "#fetch" do
|
|
202
|
+
it "retrieves the expected value" do
|
|
203
|
+
subject["wibble"] = "wobble"
|
|
204
|
+
subject["wubble"] = "fred"
|
|
205
|
+
expect(subject.fetch("wibble")).to eq "wobble"
|
|
206
|
+
end
|
|
207
|
+
it "returns the default if the key is not found and one is supplied" do
|
|
208
|
+
subject["wibble"] = "wobble"
|
|
209
|
+
subject["wubble"] = "fred"
|
|
210
|
+
expect(subject.fetch("flob", "waldo")).to eq "waldo"
|
|
211
|
+
end
|
|
212
|
+
it "raises a KeyError if the key is not found and no default is supplied" do
|
|
213
|
+
expect { subject.fetch("flob") }.to raise_error KeyError
|
|
214
|
+
end
|
|
215
|
+
it "can take a block as well" do
|
|
216
|
+
subject["wibble"] = "wobble"
|
|
217
|
+
subject["wubble"] = "fred"
|
|
218
|
+
expect(subject.fetch("wubble") { |e| e.capitalize }).to eq "fred" # value takes precence
|
|
219
|
+
expect { |b| subject.fetch("foo", &b) }.to yield_with_args
|
|
220
|
+
expect(subject.fetch("foo") { |e| e.reverse }).to eq "oof"
|
|
222
221
|
end
|
|
223
222
|
end
|
|
224
223
|
|
|
225
|
-
describe
|
|
226
|
-
it
|
|
227
|
-
subject[
|
|
228
|
-
expect(subject.has_key?
|
|
224
|
+
describe "#has_key? (and aliases)" do
|
|
225
|
+
it "is true when the key exists" do
|
|
226
|
+
subject["wibble"] = "wobble"
|
|
227
|
+
expect(subject.has_key?("wibble")).to be_truthy
|
|
229
228
|
end
|
|
230
|
-
it
|
|
231
|
-
expect(subject.has_key?
|
|
229
|
+
it "is false when the key does not exist" do
|
|
230
|
+
expect(subject.has_key?("wibble")).to be_falsey
|
|
232
231
|
end
|
|
233
232
|
end
|
|
234
233
|
|
|
235
|
-
describe
|
|
236
|
-
it
|
|
237
|
-
subject[
|
|
238
|
-
expect(subject.has_value?
|
|
234
|
+
describe "#has_value? (and aliases)" do
|
|
235
|
+
it "is true when the value exists" do
|
|
236
|
+
subject["wibble"] = "wobble"
|
|
237
|
+
expect(subject.has_value?("wobble")).to be_truthy
|
|
239
238
|
end
|
|
240
|
-
it
|
|
241
|
-
expect(subject.has_value?
|
|
239
|
+
it "is false when the value does not exist" do
|
|
240
|
+
expect(subject.has_value?("wobble")).to be_falsey
|
|
242
241
|
end
|
|
243
242
|
end
|
|
244
243
|
|
|
245
|
-
describe
|
|
246
|
-
it
|
|
247
|
-
subject[
|
|
248
|
-
subject[
|
|
249
|
-
subject[
|
|
250
|
-
expect { |b| subject.keep_if(&b) }.to yield_successive_args([
|
|
251
|
-
end
|
|
252
|
-
it
|
|
253
|
-
subject[
|
|
254
|
-
subject[
|
|
255
|
-
subject[
|
|
256
|
-
expect(
|
|
257
|
-
end
|
|
258
|
-
it
|
|
259
|
-
subject[
|
|
260
|
-
subject[
|
|
261
|
-
subject[
|
|
262
|
-
subject.keep_if { |k,v| k.start_with?(
|
|
263
|
-
expect(subject.data).to eq({
|
|
244
|
+
describe "#keep_if" do
|
|
245
|
+
it "can take a block" do
|
|
246
|
+
subject["wibble"] = "foo"
|
|
247
|
+
subject["waldo"] = "fred"
|
|
248
|
+
subject["plugh"] = "xyzzy"
|
|
249
|
+
expect { |b| subject.keep_if(&b) }.to yield_successive_args(["wibble", "foo"], ["waldo", "fred"], ["plugh", "xyzzy"])
|
|
250
|
+
end
|
|
251
|
+
it "returns the instance" do
|
|
252
|
+
subject["wibble"] = "foo"
|
|
253
|
+
subject["waldo"] = "fred"
|
|
254
|
+
subject["plugh"] = "xyzzy"
|
|
255
|
+
expect(subject.keep_if { |k, v| k.start_with?("w") }).to eq subject
|
|
256
|
+
end
|
|
257
|
+
it "works" do
|
|
258
|
+
subject["wibble"] = "foo"
|
|
259
|
+
subject["waldo"] = "fred"
|
|
260
|
+
subject["plugh"] = "xyzzy"
|
|
261
|
+
subject.keep_if { |k, v| k.start_with?("w") }
|
|
262
|
+
expect(subject.data).to eq({"wibble" => "foo", "waldo" => "fred"})
|
|
264
263
|
end
|
|
265
264
|
end
|
|
266
265
|
|
|
267
|
-
describe
|
|
268
|
-
it
|
|
269
|
-
subject[
|
|
270
|
-
subject[
|
|
271
|
-
expect(subject.key
|
|
272
|
-
expect(subject.key
|
|
273
|
-
end
|
|
274
|
-
it
|
|
275
|
-
subject[
|
|
276
|
-
subject[
|
|
277
|
-
expect(subject.key
|
|
266
|
+
describe "#key" do
|
|
267
|
+
it "is the key associated with a value" do
|
|
268
|
+
subject["thud"] = "wibble"
|
|
269
|
+
subject["plugh"] = "wobble"
|
|
270
|
+
expect(subject.key("wibble")).to eq "thud"
|
|
271
|
+
expect(subject.key("wobble")).to eq "plugh"
|
|
272
|
+
end
|
|
273
|
+
it "is nil if the value is not found" do
|
|
274
|
+
subject["thud"] = "wibble"
|
|
275
|
+
subject["plugh"] = "wobble"
|
|
276
|
+
expect(subject.key("foo")).to be_nil
|
|
278
277
|
end
|
|
279
278
|
end
|
|
280
279
|
|
|
281
|
-
describe
|
|
282
|
-
it
|
|
283
|
-
subject[
|
|
284
|
-
subject[
|
|
285
|
-
subject[
|
|
286
|
-
expect(subject.keys).to eq [
|
|
280
|
+
describe "#keys" do
|
|
281
|
+
it "is an array of all of the keys in the object" do
|
|
282
|
+
subject["foo"] = "bar"
|
|
283
|
+
subject["waldo"] = "fred"
|
|
284
|
+
subject["plugh"] = "xyzzy"
|
|
285
|
+
expect(subject.keys).to eq ["foo", "waldo", "plugh"]
|
|
287
286
|
end
|
|
288
287
|
end
|
|
289
288
|
|
|
290
|
-
describe
|
|
291
|
-
it
|
|
292
|
-
subject[
|
|
293
|
-
subject[
|
|
289
|
+
describe "#length" do
|
|
290
|
+
it "works" do
|
|
291
|
+
subject["wibble"] = "foo"
|
|
292
|
+
subject["waldo"] = "fred"
|
|
294
293
|
expect(subject.length).to eq 2
|
|
295
294
|
end
|
|
296
295
|
end
|
|
297
296
|
|
|
298
|
-
describe
|
|
299
|
-
it
|
|
300
|
-
subject[
|
|
297
|
+
describe "#merge" do
|
|
298
|
+
it "returns a new instance of the calling class" do
|
|
299
|
+
subject["wibble"] = "foo"
|
|
301
300
|
another = hash_like_class.new
|
|
302
|
-
another[
|
|
301
|
+
another["waldo"] = "fred"
|
|
303
302
|
merged = subject.merge(another)
|
|
304
303
|
# clear them all to confirm we're not testing equality of anything other
|
|
305
304
|
# than that we have different instances
|
|
@@ -318,33 +317,33 @@ describe IIIF::HashBehaviours do
|
|
|
318
317
|
# new_instance = subject.merge(another)
|
|
319
318
|
# expect(new_instance.data.last).to eq ['waldo', 'fred']
|
|
320
319
|
# end
|
|
321
|
-
it
|
|
322
|
-
subject[
|
|
323
|
-
subject[
|
|
324
|
-
subject[
|
|
320
|
+
it "retains the index position for existing entries, replacing the value" do
|
|
321
|
+
subject["wibble"] = "foo"
|
|
322
|
+
subject["plugh"] = "xyzzy"
|
|
323
|
+
subject["foo"] = "bar"
|
|
325
324
|
another = hash_like_class.new
|
|
326
|
-
another[
|
|
325
|
+
another["plugh"] = "fred"
|
|
327
326
|
new_instance = subject.merge(another)
|
|
328
|
-
expect(new_instance[
|
|
329
|
-
expect(new_instance[new_instance.keys[1]]).to eq
|
|
327
|
+
expect(new_instance["plugh"]).to eq "fred"
|
|
328
|
+
expect(new_instance[new_instance.keys[1]]).to eq "fred"
|
|
330
329
|
end
|
|
331
|
-
it
|
|
332
|
-
subject[
|
|
333
|
-
subject[
|
|
334
|
-
subject[
|
|
330
|
+
it "takes a block" do
|
|
331
|
+
subject["wibble"] = "foo"
|
|
332
|
+
subject["plugh"] = "xyzzy"
|
|
333
|
+
subject["foo"] = "bar"
|
|
335
334
|
another = hash_like_class.new
|
|
336
|
-
another[
|
|
335
|
+
another["plugh"] = "fred"
|
|
337
336
|
# e.g. give a block that turns common keys into an Array
|
|
338
|
-
new_instance = subject.merge(another) { |k, old_val,new_val| [old_val, new_val] }
|
|
339
|
-
expect(new_instance[
|
|
340
|
-
expect(new_instance[
|
|
341
|
-
expect(new_instance[
|
|
342
|
-
expect(new_instance.data).to eq({
|
|
343
|
-
end
|
|
344
|
-
describe
|
|
345
|
-
it
|
|
346
|
-
subject[
|
|
347
|
-
another = {
|
|
337
|
+
new_instance = subject.merge(another) { |k, old_val, new_val| [old_val, new_val] }
|
|
338
|
+
expect(new_instance["wibble"]).to eq "foo"
|
|
339
|
+
expect(new_instance["plugh"]).to eq ["xyzzy", "fred"]
|
|
340
|
+
expect(new_instance["foo"]).to eq "bar"
|
|
341
|
+
expect(new_instance.data).to eq({"wibble" => "foo", "plugh" => ["xyzzy", "fred"], "foo" => "bar"})
|
|
342
|
+
end
|
|
343
|
+
describe "takes anything that implements `#each { |k,v| block }` and #has_key?" do
|
|
344
|
+
it "returns a new instance of the calling class" do
|
|
345
|
+
subject["wibble"] = "foo"
|
|
346
|
+
another = {"waldo" => "fred"}
|
|
348
347
|
merged = subject.merge(another)
|
|
349
348
|
# clear them all to confirm we're not testing equality of anything other
|
|
350
349
|
# than that we have different instances
|
|
@@ -362,208 +361,206 @@ describe IIIF::HashBehaviours do
|
|
|
362
361
|
# new_instance = subject.merge(another)
|
|
363
362
|
# expect(new_instance.data.last).to eq ['waldo', 'fred']
|
|
364
363
|
# end
|
|
365
|
-
it
|
|
366
|
-
subject[
|
|
367
|
-
subject[
|
|
368
|
-
subject[
|
|
369
|
-
another = {
|
|
370
|
-
another[
|
|
364
|
+
it "retains the index position for existing entries, replacing the value" do
|
|
365
|
+
subject["wibble"] = "foo"
|
|
366
|
+
subject["plugh"] = "xyzzy"
|
|
367
|
+
subject["foo"] = "bar"
|
|
368
|
+
another = {"plugh" => "fred"}
|
|
369
|
+
another["plugh"] = "fred"
|
|
371
370
|
new_instance = subject.merge(another)
|
|
372
|
-
expect(new_instance[
|
|
373
|
-
expect(new_instance[new_instance.keys[1]]).to eq
|
|
371
|
+
expect(new_instance["plugh"]).to eq "fred"
|
|
372
|
+
expect(new_instance[new_instance.keys[1]]).to eq "fred"
|
|
374
373
|
end
|
|
375
|
-
it
|
|
376
|
-
subject[
|
|
377
|
-
subject[
|
|
378
|
-
subject[
|
|
379
|
-
another = {
|
|
374
|
+
it "takes a block" do
|
|
375
|
+
subject["wibble"] = "foo"
|
|
376
|
+
subject["plugh"] = "xyzzy"
|
|
377
|
+
subject["foo"] = "bar"
|
|
378
|
+
another = {"plugh" => "fred"}
|
|
380
379
|
# e.g. give a block that turns common keys into an Array
|
|
381
|
-
new_instance = subject.merge(another) { |k, old_val,new_val| [old_val, new_val] }
|
|
382
|
-
expect(new_instance[
|
|
383
|
-
expect(new_instance[
|
|
384
|
-
expect(new_instance[
|
|
385
|
-
expect(new_instance.data).to eq({
|
|
380
|
+
new_instance = subject.merge(another) { |k, old_val, new_val| [old_val, new_val] }
|
|
381
|
+
expect(new_instance["wibble"]).to eq "foo"
|
|
382
|
+
expect(new_instance["plugh"]).to eq ["xyzzy", "fred"]
|
|
383
|
+
expect(new_instance["foo"]).to eq "bar"
|
|
384
|
+
expect(new_instance.data).to eq({"wibble" => "foo", "plugh" => ["xyzzy", "fred"], "foo" => "bar"})
|
|
386
385
|
end
|
|
387
386
|
end
|
|
388
387
|
end
|
|
389
388
|
|
|
390
|
-
describe
|
|
391
|
-
it
|
|
392
|
-
subject[
|
|
389
|
+
describe "#merge!" do
|
|
390
|
+
it "returns the instance on which is was called" do
|
|
391
|
+
subject["wibble"] = "foo"
|
|
393
392
|
another = hash_like_class.new
|
|
394
|
-
another[
|
|
393
|
+
another["waldo"] = "fred"
|
|
395
394
|
expect(subject.merge!(another)).to eq subject # same instance
|
|
396
395
|
end
|
|
397
|
-
it
|
|
398
|
-
subject[
|
|
399
|
-
subject[
|
|
396
|
+
it "adds new entries to the end" do
|
|
397
|
+
subject["wibble"] = "foo"
|
|
398
|
+
subject["plugh"] = "xyzzy"
|
|
400
399
|
another = hash_like_class.new
|
|
401
|
-
another[
|
|
400
|
+
another["waldo"] = "fred"
|
|
402
401
|
subject.merge!(another)
|
|
403
|
-
expect(subject.data[subject.data.keys.last]).to eq
|
|
402
|
+
expect(subject.data[subject.data.keys.last]).to eq "fred"
|
|
404
403
|
end
|
|
405
|
-
it
|
|
406
|
-
subject[
|
|
407
|
-
subject[
|
|
408
|
-
subject[
|
|
404
|
+
it "retains the index position for existing entries, replacing the value" do
|
|
405
|
+
subject["wibble"] = "foo"
|
|
406
|
+
subject["plugh"] = "xyzzy"
|
|
407
|
+
subject["foo"] = "bar"
|
|
409
408
|
another = hash_like_class.new
|
|
410
|
-
another[
|
|
409
|
+
another["plugh"] = "fred"
|
|
411
410
|
subject.merge!(another)
|
|
412
|
-
expect(subject[
|
|
413
|
-
expect(subject.data[subject.keys[1]]).to eq
|
|
411
|
+
expect(subject["plugh"]).to eq "fred"
|
|
412
|
+
expect(subject.data[subject.keys[1]]).to eq "fred"
|
|
414
413
|
end
|
|
415
|
-
it
|
|
416
|
-
subject[
|
|
417
|
-
subject[
|
|
418
|
-
subject[
|
|
414
|
+
it "takes a block" do
|
|
415
|
+
subject["wibble"] = "foo"
|
|
416
|
+
subject["plugh"] = "xyzzy"
|
|
417
|
+
subject["foo"] = "bar"
|
|
419
418
|
another = hash_like_class.new
|
|
420
|
-
another[
|
|
419
|
+
another["plugh"] = "fred"
|
|
421
420
|
# e.g. give a block that turns common keys into an Array
|
|
422
|
-
subject.merge!(another) { |k, old_val,new_val| [old_val, new_val] }
|
|
423
|
-
expect(subject[
|
|
424
|
-
expect(subject[
|
|
425
|
-
expect(subject[
|
|
426
|
-
expect(subject.data).to eq({
|
|
427
|
-
end
|
|
428
|
-
describe
|
|
429
|
-
it
|
|
430
|
-
subject[
|
|
431
|
-
another = {
|
|
421
|
+
subject.merge!(another) { |k, old_val, new_val| [old_val, new_val] }
|
|
422
|
+
expect(subject["wibble"]).to eq "foo"
|
|
423
|
+
expect(subject["plugh"]).to eq ["xyzzy", "fred"]
|
|
424
|
+
expect(subject["foo"]).to eq "bar"
|
|
425
|
+
expect(subject.data).to eq({"wibble" => "foo", "plugh" => ["xyzzy", "fred"], "foo" => "bar"})
|
|
426
|
+
end
|
|
427
|
+
describe "takes anything that implements `#each { |k,v| block }` and #has_key?" do
|
|
428
|
+
it "returns a new instance of the calling class" do
|
|
429
|
+
subject["wibble"] = "foo"
|
|
430
|
+
another = {"waldo" => "fred"}
|
|
432
431
|
expect(subject.merge!(another)).to eq subject # same instance
|
|
433
432
|
end
|
|
434
|
-
it
|
|
435
|
-
subject[
|
|
436
|
-
subject[
|
|
437
|
-
another = {
|
|
433
|
+
it "adds new entries to the end" do
|
|
434
|
+
subject["wibble"] = "foo"
|
|
435
|
+
subject["plugh"] = "xyzzy"
|
|
436
|
+
another = {"waldo" => "fred"}
|
|
438
437
|
subject.merge!(another)
|
|
439
|
-
expect(subject.data[subject.data.keys.last]).to eq
|
|
438
|
+
expect(subject.data[subject.data.keys.last]).to eq "fred"
|
|
440
439
|
end
|
|
441
|
-
it
|
|
442
|
-
subject[
|
|
443
|
-
subject[
|
|
444
|
-
subject[
|
|
445
|
-
another = {
|
|
440
|
+
it "retains the index position for existing entries, replacing the value" do
|
|
441
|
+
subject["wibble"] = "foo"
|
|
442
|
+
subject["plugh"] = "xyzzy"
|
|
443
|
+
subject["foo"] = "bar"
|
|
444
|
+
another = {"plugh" => "fred"}
|
|
446
445
|
subject.merge!(another)
|
|
447
|
-
expect(subject[
|
|
448
|
-
expect(subject.data[subject.keys[1]]).to eq
|
|
446
|
+
expect(subject["plugh"]).to eq "fred"
|
|
447
|
+
expect(subject.data[subject.keys[1]]).to eq "fred"
|
|
449
448
|
end
|
|
450
|
-
it
|
|
451
|
-
subject[
|
|
452
|
-
subject[
|
|
453
|
-
subject[
|
|
454
|
-
another = {
|
|
455
|
-
subject.merge!(another) { |k, old_val,new_val| "#{k}, #{old_val}, #{new_val}" }
|
|
456
|
-
expect(subject[
|
|
457
|
-
expect(subject[
|
|
458
|
-
expect(subject[
|
|
459
|
-
expect(subject.data).to eq({
|
|
449
|
+
it "takes a block" do
|
|
450
|
+
subject["wibble"] = "foo"
|
|
451
|
+
subject["plugh"] = "xyzzy"
|
|
452
|
+
subject["foo"] = "bar"
|
|
453
|
+
another = {"plugh" => "fred"}
|
|
454
|
+
subject.merge!(another) { |k, old_val, new_val| "#{k}, #{old_val}, #{new_val}" }
|
|
455
|
+
expect(subject["wibble"]).to eq "foo"
|
|
456
|
+
expect(subject["plugh"]).to eq "plugh, xyzzy, fred"
|
|
457
|
+
expect(subject["foo"]).to eq "bar"
|
|
458
|
+
expect(subject.data).to eq({"wibble" => "foo", "plugh" => "plugh, xyzzy, fred", "foo" => "bar"})
|
|
460
459
|
end
|
|
461
460
|
end
|
|
462
461
|
end
|
|
463
462
|
|
|
464
|
-
describe
|
|
465
|
-
it
|
|
466
|
-
subject[
|
|
467
|
-
subject[
|
|
468
|
-
subject[
|
|
469
|
-
expect { |b| subject.reject!(&b) }.to yield_successive_args([
|
|
470
|
-
end
|
|
471
|
-
it
|
|
472
|
-
subject[
|
|
473
|
-
subject[
|
|
474
|
-
subject[
|
|
475
|
-
expect(
|
|
476
|
-
end
|
|
477
|
-
it
|
|
478
|
-
subject[
|
|
479
|
-
subject[
|
|
480
|
-
subject[
|
|
481
|
-
expect(
|
|
482
|
-
end
|
|
483
|
-
it
|
|
484
|
-
subject[
|
|
485
|
-
subject[
|
|
486
|
-
subject[
|
|
487
|
-
subject.reject! { |k| k.start_with?(
|
|
488
|
-
expect(subject.data).to eq({
|
|
463
|
+
describe "#reject!" do
|
|
464
|
+
it "can take a block" do
|
|
465
|
+
subject["wibble"] = "foo"
|
|
466
|
+
subject["waldo"] = "fred"
|
|
467
|
+
subject["plugh"] = "xyzzy"
|
|
468
|
+
expect { |b| subject.reject!(&b) }.to yield_successive_args(["wibble", "foo"], ["waldo", "fred"], ["plugh", "xyzzy"])
|
|
469
|
+
end
|
|
470
|
+
it "returns the instance if there were changes" do
|
|
471
|
+
subject["wibble"] = "foo"
|
|
472
|
+
subject["waldo"] = "fred"
|
|
473
|
+
subject["plugh"] = "xyzzy"
|
|
474
|
+
expect(subject.reject! { |k| k.start_with?("w") }).to be subject
|
|
475
|
+
end
|
|
476
|
+
it "returns nil if there were no changes" do
|
|
477
|
+
subject["wibble"] = "foo"
|
|
478
|
+
subject["waldo"] = "fred"
|
|
479
|
+
subject["plugh"] = "xyzzy"
|
|
480
|
+
expect(subject.reject! { |k| k.start_with?("X") }).to be_nil
|
|
481
|
+
end
|
|
482
|
+
it "works" do
|
|
483
|
+
subject["wibble"] = "foo"
|
|
484
|
+
subject["waldo"] = "fred"
|
|
485
|
+
subject["plugh"] = "xyzzy"
|
|
486
|
+
subject.reject! { |k| k.start_with?("w") }
|
|
487
|
+
expect(subject.data).to eq({"plugh" => "xyzzy"})
|
|
489
488
|
end
|
|
490
489
|
end
|
|
491
490
|
|
|
492
|
-
describe
|
|
493
|
-
it
|
|
494
|
-
subject[
|
|
495
|
-
subject[
|
|
496
|
-
subject[
|
|
497
|
-
expect { |b| subject.select(&b) }.to yield_successive_args([
|
|
498
|
-
end
|
|
499
|
-
it
|
|
500
|
-
subject[
|
|
501
|
-
subject[
|
|
502
|
-
subject[
|
|
503
|
-
expect(
|
|
504
|
-
expect(
|
|
505
|
-
end
|
|
506
|
-
it
|
|
507
|
-
subject[
|
|
508
|
-
subject[
|
|
509
|
-
subject[
|
|
510
|
-
expect(
|
|
511
|
-
expect(
|
|
491
|
+
describe "#select" do
|
|
492
|
+
it "yields" do
|
|
493
|
+
subject["thud"] = "wibble"
|
|
494
|
+
subject["plugh"] = "wobble"
|
|
495
|
+
subject["waldo"] = "fred"
|
|
496
|
+
expect { |b| subject.select(&b) }.to yield_successive_args(["thud", "wibble"], ["plugh", "wobble"], ["waldo", "fred"])
|
|
497
|
+
end
|
|
498
|
+
it "returns a new instance of the class" do
|
|
499
|
+
subject["thud"] = "wibble"
|
|
500
|
+
subject["plugh"] = "wobble"
|
|
501
|
+
subject["waldo"] = "fred"
|
|
502
|
+
expect(subject.select { |k, v| true }.class).to eq subject.class
|
|
503
|
+
expect(subject.select { |k, v| true }).to_not eq subject
|
|
504
|
+
end
|
|
505
|
+
it "selects but doesn't delete from the original instance" do
|
|
506
|
+
subject["thud"] = "wibble"
|
|
507
|
+
subject["plugh"] = "wobble"
|
|
508
|
+
subject["waldo"] = "fred"
|
|
509
|
+
expect(subject.select { |k, v| k.include?("u") }.data).to eq({"thud" => "wibble", "plugh" => "wobble"})
|
|
510
|
+
expect(subject.data).to eq subject.data
|
|
512
511
|
end
|
|
513
512
|
end
|
|
514
513
|
|
|
515
|
-
describe
|
|
516
|
-
it
|
|
517
|
-
subject[
|
|
518
|
-
subject[
|
|
519
|
-
subject[
|
|
520
|
-
expect { |b| subject.select!(&b) }.to yield_successive_args([
|
|
521
|
-
end
|
|
522
|
-
it
|
|
523
|
-
subject[
|
|
524
|
-
subject[
|
|
525
|
-
subject[
|
|
526
|
-
expect(
|
|
527
|
-
end
|
|
528
|
-
it
|
|
529
|
-
subject[
|
|
530
|
-
subject[
|
|
531
|
-
subject[
|
|
532
|
-
expect(
|
|
533
|
-
end
|
|
534
|
-
it
|
|
535
|
-
subject[
|
|
536
|
-
subject[
|
|
537
|
-
subject[
|
|
538
|
-
subject.select! { |k,v| k.start_with?(
|
|
539
|
-
expect(subject.data).to eq({
|
|
514
|
+
describe "#select!" do
|
|
515
|
+
it "can take a block" do
|
|
516
|
+
subject["wibble"] = "foo"
|
|
517
|
+
subject["waldo"] = "fred"
|
|
518
|
+
subject["plugh"] = "xyzzy"
|
|
519
|
+
expect { |b| subject.select!(&b) }.to yield_successive_args(["wibble", "foo"], ["waldo", "fred"], ["plugh", "xyzzy"])
|
|
520
|
+
end
|
|
521
|
+
it "returns nil if there were no changes" do
|
|
522
|
+
subject["wibble"] = "foo"
|
|
523
|
+
subject["waldo"] = "fred"
|
|
524
|
+
subject["wobble"] = "xyzzy"
|
|
525
|
+
expect(subject.select! { |k, v| k.start_with?("w") }).to be_nil
|
|
526
|
+
end
|
|
527
|
+
it "returns the instance if there were changes" do
|
|
528
|
+
subject["wibble"] = "foo"
|
|
529
|
+
subject["waldo"] = "fred"
|
|
530
|
+
subject["plugh"] = "xyzzy"
|
|
531
|
+
expect(subject.select! { |k, v| k.start_with?("w") }).to eq subject
|
|
532
|
+
end
|
|
533
|
+
it "works" do
|
|
534
|
+
subject["wibble"] = "foo"
|
|
535
|
+
subject["waldo"] = "fred"
|
|
536
|
+
subject["plugh"] = "xyzzy"
|
|
537
|
+
subject.select! { |k, v| k.start_with?("p") }
|
|
538
|
+
expect(subject.data).to eq({"plugh" => "xyzzy"})
|
|
540
539
|
end
|
|
541
540
|
end
|
|
542
541
|
|
|
543
|
-
describe
|
|
544
|
-
it
|
|
545
|
-
subject[
|
|
546
|
-
subject[
|
|
547
|
-
expect(subject.shift).to eq [
|
|
548
|
-
expect(subject.data).to eq({
|
|
542
|
+
describe "#shift" do
|
|
543
|
+
it "returns the first element in the hash without a param" do
|
|
544
|
+
subject["thud"] = "wibble"
|
|
545
|
+
subject["plugh"] = "wobble"
|
|
546
|
+
expect(subject.shift).to eq ["thud", "wibble"]
|
|
547
|
+
expect(subject.data).to eq({"plugh" => "wobble"})
|
|
549
548
|
end
|
|
550
549
|
end
|
|
551
550
|
|
|
552
|
-
describe
|
|
553
|
-
it
|
|
554
|
-
subject.store(
|
|
555
|
-
expect(subject.data).to eq({
|
|
551
|
+
describe "store" do
|
|
552
|
+
it "works as an alias for []=" do
|
|
553
|
+
subject.store("foo", "bar")
|
|
554
|
+
expect(subject.data).to eq({"foo" => "bar"})
|
|
556
555
|
end
|
|
557
556
|
end
|
|
558
557
|
|
|
559
|
-
describe
|
|
560
|
-
it
|
|
561
|
-
subject[
|
|
562
|
-
subject[
|
|
563
|
-
subject[
|
|
564
|
-
expect(subject.values).to eq [
|
|
558
|
+
describe "#values" do
|
|
559
|
+
it "is an array of all of the keys in the object" do
|
|
560
|
+
subject["foo"] = "bar"
|
|
561
|
+
subject["waldo"] = "fred"
|
|
562
|
+
subject["plugh"] = "xyzzy"
|
|
563
|
+
expect(subject.values).to eq ["bar", "fred", "xyzzy"]
|
|
565
564
|
end
|
|
566
565
|
end
|
|
567
|
-
|
|
568
566
|
end
|
|
569
|
-
|