krikri 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -329,6 +329,21 @@ EOM
329
329
  .and_return(result)
330
330
  subject.send(method, { :skip_set => 'moomin' }).first
331
331
  end
332
+
333
+ it 'skips sets that error' do
334
+ args[:oai].delete(:set)
335
+ invalid = args[:oai].dup
336
+ invalid[:set] = 'invalid'
337
+ valid = args[:oai].dup
338
+ valid[:set] = 'valid'
339
+
340
+ allow(subject).to receive(:sets).and_return(['invalid', 'valid', 'moomin'])
341
+ expect(subject.client).to receive(request_type).with(invalid)
342
+ .and_raise(OAI::Exception, '')
343
+ expect(subject.client).to receive(request_type).with(valid)
344
+ .and_return(result)
345
+ subject.send(method, { :skip_set => 'moomin' }).first
346
+ end
332
347
  end
333
348
  end
334
349
 
@@ -49,6 +49,8 @@ describe Krikri::Parser::ValueArray do
49
49
  .and_return(described_class.new([]))
50
50
  allow(nested_field).to receive(:[]).with(:nested_name)
51
51
  .and_return(:final_value)
52
+ allow(nested_field).to receive(:[]).with(:nonexistent_field)
53
+ .and_return(described_class.new([]))
52
54
  end
53
55
  end
54
56
  end
@@ -84,6 +86,64 @@ describe Krikri::Parser::ValueArray do
84
86
  end
85
87
  end
86
88
 
89
+
90
+ describe '#if' do
91
+ include_context 'with fields'
92
+
93
+ it 'returns self with top set' do
94
+ expect(subject.if).to eq subject
95
+ end
96
+
97
+ context 'with block given' do
98
+ it 'yields a copy of itself' do
99
+ expect { |b| subject.if(&b) }
100
+ .to yield_with_args(a_collection_containing_exactly(*subject))
101
+ end
102
+
103
+ it 'returns result if non-empty' do
104
+ expect(subject.if { |rec| rec.field(:field_name, :nested_name) })
105
+ .to contain_exactly(:final_value, :final_value, :final_value)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#else' do
111
+ include_context 'with fields'
112
+
113
+ it 'raises an argument error if no block is given ' do
114
+ expect { subject.else }.to raise_error ArgumentError
115
+ end
116
+
117
+ it 'evaluates block on root for empty result ' do
118
+ expect(
119
+ subject.field(:nonexistent_field).else do |rec|
120
+ rec.field(:field_name, :nested_name)
121
+ end
122
+ ).to contain_exactly(:final_value, :final_value, :final_value)
123
+ end
124
+
125
+ it 'skips block on root for non-empty result ' do
126
+ expect { |b| subject.field(:field_name).else(&b) }
127
+ .not_to yield_control
128
+ end
129
+
130
+ context 'with #if' do
131
+ it 'recovers from @top set by #if' do
132
+ expect(
133
+ subject.field(:field_name).if.field(:nonexistent_field).else do |rec|
134
+ rec.field(:nested_name)
135
+ end
136
+ ).to contain_exactly(:final_value, :final_value, :final_value)
137
+ end
138
+
139
+ it 'skips block on root for non-empty result ' do
140
+ expect do |b|
141
+ subject.field(:field_name).if.field(:nested_name).else(&b)
142
+ end.not_to yield_control
143
+ end
144
+ end
145
+ end
146
+
87
147
  describe '#field' do
88
148
  include_context 'with fields'
89
149
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krikri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Audrey Altman
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-04 00:00:00.000000000 Z
14
+ date: 2015-11-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails