rspec-solr 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +53 -0
- data/.travis.yml +1 -3
- data/.yardopts +1 -1
- data/Gemfile +2 -0
- data/MATCHERS.md +168 -0
- data/{README.rdoc → README.md} +31 -26
- data/Rakefile +4 -4
- data/lib/rspec-solr.rb +6 -7
- data/lib/rspec-solr/compare_num_docs_matcher.rb +32 -49
- data/lib/rspec-solr/have_documents_matcher.rb +10 -19
- data/lib/rspec-solr/have_facet_field_matcher.rb +16 -24
- data/lib/rspec-solr/include_documents_matcher.rb +65 -46
- data/lib/rspec-solr/solr_response_hash.rb +52 -55
- data/lib/rspec-solr/version.rb +1 -1
- data/lib/tasks/ci.rake +4 -4
- data/lib/tasks/doc.rake +8 -8
- data/lib/tasks/spec.rake +1 -1
- data/rspec-solr.gemspec +20 -20
- data/spec/comparing_num_docs_in_2_resp_spec.rb +205 -217
- data/spec/have_documents_spec.rb +37 -39
- data/spec/have_facet_field_spec.rb +69 -74
- data/spec/include_before_spec.rb +69 -77
- data/spec/include_document_spec.rb +317 -340
- data/spec/include_in_each_of_first_n_spec.rb +76 -79
- data/spec/include_in_first_n_spec.rb +188 -192
- data/spec/number_of_documents_spec.rb +192 -201
- data/spec/solr_response_hash_spec.rb +85 -92
- data/spec/spec_helper.rb +5 -16
- metadata +44 -31
- data/MATCHERS.rdoc +0 -169
- data/spec/support/matchers.rb +0 -22
@@ -2,157 +2,154 @@ require 'spec_helper'
|
|
2
2
|
require 'rspec-solr'
|
3
3
|
|
4
4
|
describe RSpecSolr do
|
5
|
-
|
6
5
|
context "shouldn't break RSpec #have matcher" do
|
7
|
-
it
|
8
|
-
[1,2,3].
|
9
|
-
[1,2,3].
|
10
|
-
[1,2,3].
|
11
|
-
[1,2,3].
|
12
|
-
[1,2,3].
|
13
|
-
end
|
14
|
-
|
15
|
-
it
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
it
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
it
|
28
|
-
target =
|
29
|
-
target.
|
30
|
-
target.
|
31
|
-
end
|
32
|
-
it
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
6
|
+
it 'for Array' do
|
7
|
+
expect([1, 2, 3]).to have(3).items
|
8
|
+
expect([1, 2, 3]).not_to have(4).items
|
9
|
+
expect([1, 2, 3]).to have_at_least(2).items
|
10
|
+
expect([1, 2, 3]).to have_at_least(1).item
|
11
|
+
expect([1, 2, 3]).to have_at_most(5).items
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'for Hash' do
|
15
|
+
expect(k1: 'v1', k2: 'v2', k3: 'v3').to have_exactly(3).items
|
16
|
+
expect(k1: 'v1', k2: 'v2', k3: 'v3').not_to have(4).items
|
17
|
+
expect(k1: 'v1', k2: 'v2', k3: 'v3').to have_at_least(2).items
|
18
|
+
expect(k1: 'v1', k2: 'v2', k3: 'v3').to have_at_most(5).items
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'for String' do
|
22
|
+
expect('this string').to have(11).characters
|
23
|
+
expect('this string').not_to have(12).characters
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'passes args to target' do
|
27
|
+
target = double('target')
|
28
|
+
expect(target).to receive(:items).with('arg1', 'arg2').and_return([1, 2, 3])
|
29
|
+
expect(target).to have(3).items('arg1', 'arg2')
|
30
|
+
end
|
31
|
+
it 'passes block to target' do
|
32
|
+
target = double('target')
|
33
|
+
block = -> { 5 }
|
34
|
+
expect(target).to receive(:items).with('arg1', 'arg2', block).and_return([1, 2, 3])
|
35
|
+
expect(target).to have(3).items('arg1', 'arg2', block)
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
38
|
+
|
40
39
|
# fixtures at end of this file
|
41
40
|
|
42
|
-
context
|
43
|
-
|
41
|
+
context 'should have(n).documents' do
|
44
42
|
it "pluralizes 'documents'" do
|
45
|
-
@solr_resp_1_doc.
|
46
|
-
end
|
47
|
-
|
48
|
-
it
|
49
|
-
@solr_resp_5_docs.
|
50
|
-
@solr_resp_no_docs.
|
51
|
-
end
|
52
|
-
|
53
|
-
it
|
54
|
-
@solr_resp_no_docs.
|
55
|
-
end
|
56
|
-
|
57
|
-
it
|
58
|
-
@solr_resp_5_docs.
|
59
|
-
end
|
60
|
-
|
61
|
-
it
|
62
|
-
|
63
|
-
@solr_resp_5_docs.
|
64
|
-
|
65
|
-
|
66
|
-
@solr_resp_no_docs.
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
it
|
71
|
-
|
72
|
-
@solr_resp_5_docs.
|
73
|
-
|
74
|
-
|
75
|
-
@solr_resp_1_doc.
|
76
|
-
|
77
|
-
end
|
78
|
-
|
43
|
+
expect(@solr_resp_1_doc).to have(1).document
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'passes if target response has n documents' do
|
47
|
+
expect(@solr_resp_5_docs).to have(5).documents
|
48
|
+
expect(@solr_resp_no_docs).to have(0).documents
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'converts :no to 0' do
|
52
|
+
expect(@solr_resp_no_docs).to have(:no).documents
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'converts a String argument to Integer' do
|
56
|
+
expect(@solr_resp_5_docs).to have('5').documents
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'fails if target response has < n documents' do
|
60
|
+
expect do
|
61
|
+
expect(@solr_resp_5_docs).to have(6).documents
|
62
|
+
end.to raise_error.with_message 'expected 6 documents, got 5'
|
63
|
+
expect do
|
64
|
+
expect(@solr_resp_no_docs).to have(1).document
|
65
|
+
end.to raise_error.with_message 'expected 1 document, got 0'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'fails if target response has > n documents' do
|
69
|
+
expect do
|
70
|
+
expect(@solr_resp_5_docs).to have(4).documents
|
71
|
+
end.to raise_error.with_message 'expected 4 documents, got 5'
|
72
|
+
expect do
|
73
|
+
expect(@solr_resp_1_doc).to have(0).documents
|
74
|
+
end.to raise_error.with_message 'expected 0 documents, got 1'
|
75
|
+
end
|
79
76
|
end
|
80
|
-
|
81
|
-
context
|
82
|
-
it
|
83
|
-
@solr_resp_5_docs.
|
84
|
-
@solr_resp_1_doc.
|
85
|
-
@solr_resp_no_docs.
|
86
|
-
end
|
87
|
-
|
88
|
-
it
|
89
|
-
@solr_resp_5_docs.
|
90
|
-
@solr_resp_1_doc.
|
91
|
-
@solr_resp_no_docs.
|
92
|
-
end
|
93
|
-
|
94
|
-
it
|
95
|
-
|
96
|
-
@solr_resp_5_docs.
|
97
|
-
|
77
|
+
|
78
|
+
context 'should_not have(n).documents' do
|
79
|
+
it 'passes if target response has < n documents' do
|
80
|
+
expect(@solr_resp_5_docs).not_to have(6).documents
|
81
|
+
expect(@solr_resp_1_doc).not_to have(2).documents
|
82
|
+
expect(@solr_resp_no_docs).not_to have(1).document
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'passes if target response has > n documents' do
|
86
|
+
expect(@solr_resp_5_docs).not_to have(4).documents
|
87
|
+
expect(@solr_resp_1_doc).not_to have(0).documents
|
88
|
+
expect(@solr_resp_no_docs).not_to have(-1).documents
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'fails if target response has n documents' do
|
92
|
+
expect do
|
93
|
+
expect(@solr_resp_5_docs).not_to have(5).documents
|
94
|
+
end.to raise_error.with_message 'expected target not to have 5 documents, got 5'
|
98
95
|
end
|
99
96
|
end
|
100
|
-
|
101
|
-
context
|
102
|
-
it
|
103
|
-
@solr_resp_5_docs.
|
104
|
-
@solr_resp_no_docs.
|
105
|
-
end
|
106
|
-
it
|
107
|
-
@solr_resp_no_docs.
|
108
|
-
end
|
109
|
-
it
|
110
|
-
|
111
|
-
@solr_resp_5_docs.
|
112
|
-
|
113
|
-
|
114
|
-
@solr_resp_no_docs.
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
it
|
119
|
-
|
120
|
-
@solr_resp_5_docs.
|
121
|
-
|
122
|
-
|
123
|
-
@solr_resp_1_doc.
|
124
|
-
|
97
|
+
|
98
|
+
context 'should have_exactly(n).documents' do
|
99
|
+
it 'passes if target response has n documents' do
|
100
|
+
expect(@solr_resp_5_docs).to have_exactly(5).documents
|
101
|
+
expect(@solr_resp_no_docs).to have_exactly(0).documents
|
102
|
+
end
|
103
|
+
it 'converts :no to 0' do
|
104
|
+
expect(@solr_resp_no_docs).to have_exactly(:no).documents
|
105
|
+
end
|
106
|
+
it 'fails if target response has < n documents' do
|
107
|
+
expect do
|
108
|
+
expect(@solr_resp_5_docs).to have_exactly(6).documents
|
109
|
+
end.to raise_error.with_message 'expected 6 documents, got 5'
|
110
|
+
expect do
|
111
|
+
expect(@solr_resp_no_docs).to have_exactly(1).document
|
112
|
+
end.to raise_error.with_message 'expected 1 document, got 0'
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'fails if target response has > n documents' do
|
116
|
+
expect do
|
117
|
+
expect(@solr_resp_5_docs).to have_exactly(4).documents
|
118
|
+
end.to raise_error.with_message 'expected 4 documents, got 5'
|
119
|
+
expect do
|
120
|
+
expect(@solr_resp_1_doc).to have_exactly(0).documents
|
121
|
+
end.to raise_error.with_message 'expected 0 documents, got 1'
|
125
122
|
end
|
126
123
|
end
|
127
|
-
|
128
|
-
context
|
129
|
-
it
|
130
|
-
@solr_resp_5_docs.
|
131
|
-
@solr_resp_1_doc.
|
132
|
-
@solr_resp_no_docs.
|
133
|
-
end
|
134
|
-
|
135
|
-
it
|
136
|
-
@solr_resp_5_docs.
|
137
|
-
@solr_resp_1_doc.
|
138
|
-
end
|
139
|
-
|
140
|
-
it
|
141
|
-
|
142
|
-
@solr_resp_5_docs.
|
143
|
-
|
144
|
-
|
145
|
-
@solr_resp_no_docs.
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
it
|
124
|
+
|
125
|
+
context 'should have_at_least(n).documents' do
|
126
|
+
it 'passes if target response has n documents' do
|
127
|
+
expect(@solr_resp_5_docs).to have_at_least(5).documents
|
128
|
+
expect(@solr_resp_1_doc).to have_at_least(1).document
|
129
|
+
expect(@solr_resp_no_docs).to have_at_least(0).documents
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'passes if target response has > n documents' do
|
133
|
+
expect(@solr_resp_5_docs).to have_at_least(4).documents
|
134
|
+
expect(@solr_resp_1_doc).to have_at_least(0).documents
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'fails if target response has < n documents' do
|
138
|
+
expect do
|
139
|
+
expect(@solr_resp_5_docs).to have_at_least(6).documents
|
140
|
+
end.to raise_error.with_message 'expected at least 6 documents, got 5'
|
141
|
+
expect do
|
142
|
+
expect(@solr_resp_no_docs).to have_at_least(1).document
|
143
|
+
end.to raise_error.with_message 'expected at least 1 document, got 0'
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'provides educational negative failure messages' do
|
150
147
|
# given
|
151
148
|
my_matcher = have_at_least(6).documents
|
152
149
|
# when
|
153
150
|
my_matcher.matches?(@solr_resp_5_docs)
|
154
|
-
# then
|
155
|
-
my_matcher.failure_message_for_should_not.
|
151
|
+
# then
|
152
|
+
expect(my_matcher.failure_message_for_should_not).to eq <<-EOF
|
156
153
|
Isn't life confusing enough?
|
157
154
|
Instead of having to figure out the meaning of this:
|
158
155
|
expect(actual).not_to have_at_least(6).documents
|
@@ -161,35 +158,35 @@ We recommend that you use this instead:
|
|
161
158
|
EOF
|
162
159
|
end
|
163
160
|
end
|
164
|
-
|
165
|
-
context
|
166
|
-
it
|
167
|
-
@solr_resp_5_docs.
|
168
|
-
@solr_resp_1_doc.
|
169
|
-
@solr_resp_no_docs.
|
161
|
+
|
162
|
+
context 'should have_at_most(n).documents' do
|
163
|
+
it 'passes if target response has n documents' do
|
164
|
+
expect(@solr_resp_5_docs).to have_at_most(5).documents
|
165
|
+
expect(@solr_resp_1_doc).to have_at_most(1).document
|
166
|
+
expect(@solr_resp_no_docs).to have_at_most(0).documents
|
170
167
|
end
|
171
168
|
|
172
|
-
it
|
173
|
-
@solr_resp_5_docs.
|
174
|
-
@solr_resp_no_docs.
|
169
|
+
it 'passes if target response has < n documents' do
|
170
|
+
expect(@solr_resp_5_docs).to have_at_most(6).documents
|
171
|
+
expect(@solr_resp_no_docs).to have_at_most(1).document
|
175
172
|
end
|
176
173
|
|
177
|
-
it
|
178
|
-
|
179
|
-
@solr_resp_5_docs.
|
180
|
-
|
181
|
-
|
182
|
-
@solr_resp_1_doc.
|
183
|
-
|
174
|
+
it 'fails if target response has > n documents' do
|
175
|
+
expect do
|
176
|
+
expect(@solr_resp_5_docs).to have_at_most(4).documents
|
177
|
+
end.to raise_error.with_message 'expected at most 4 documents, got 5'
|
178
|
+
expect do
|
179
|
+
expect(@solr_resp_1_doc).to have_at_most(0).documents
|
180
|
+
end.to raise_error.with_message 'expected at most 0 documents, got 1'
|
184
181
|
end
|
185
182
|
|
186
|
-
it
|
183
|
+
it 'provides educational negative failure messages' do
|
187
184
|
# given
|
188
185
|
my_matcher = have_at_most(4).documents
|
189
186
|
# when
|
190
187
|
my_matcher.matches?(@solr_resp_5_docs)
|
191
|
-
# then
|
192
|
-
my_matcher.failure_message_for_should_not.
|
188
|
+
# then
|
189
|
+
expect(my_matcher.failure_message_for_should_not).to eq <<-EOF
|
193
190
|
Isn't life confusing enough?
|
194
191
|
Instead of having to figure out the meaning of this:
|
195
192
|
expect(actual).not_to have_at_most(4).documents
|
@@ -198,53 +195,47 @@ We recommend that you use this instead:
|
|
198
195
|
EOF
|
199
196
|
end
|
200
197
|
end
|
201
|
-
|
202
|
-
it
|
203
|
-
solr_resp = RSpecSolr::SolrResponseHash.new(
|
204
|
-
{
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
}
|
209
|
-
|
210
|
-
solr_resp.
|
211
|
-
solr_resp.
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
})
|
218
|
-
solr_resp.should have(3).documents
|
198
|
+
|
199
|
+
it 'should pass according to total Solr docs matching the query, not the number of docs in THIS response' do
|
200
|
+
solr_resp = RSpecSolr::SolrResponseHash.new('response' =>
|
201
|
+
{ 'numFound' => 3,
|
202
|
+
'start' => 0,
|
203
|
+
'rows' => 1,
|
204
|
+
'docs' => [{ 'id' => '111' }]
|
205
|
+
})
|
206
|
+
expect(solr_resp).to have(3).documents
|
207
|
+
expect(solr_resp).not_to have(1).document
|
208
|
+
solr_resp = RSpecSolr::SolrResponseHash.new('response' =>
|
209
|
+
{ 'numFound' => 3,
|
210
|
+
'start' => 0,
|
211
|
+
'rows' => 0
|
212
|
+
})
|
213
|
+
expect(solr_resp).to have(3).documents
|
219
214
|
end
|
220
|
-
|
215
|
+
|
221
216
|
before(:all) do
|
222
|
-
@solr_resp_1_doc = RSpecSolr::SolrResponseHash.new(
|
223
|
-
{
|
224
|
-
|
225
|
-
|
226
|
-
}
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
{"id"=>"555"}
|
217
|
+
@solr_resp_1_doc = RSpecSolr::SolrResponseHash.new('response' =>
|
218
|
+
{ 'numFound' => 1,
|
219
|
+
'start' => 0,
|
220
|
+
'docs' => [{ 'id' => '111' }]
|
221
|
+
})
|
222
|
+
|
223
|
+
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new('response' =>
|
224
|
+
{ 'numFound' => 5,
|
225
|
+
'start' => 0,
|
226
|
+
'docs' =>
|
227
|
+
[{ 'id' => '111' },
|
228
|
+
{ 'id' => '222' },
|
229
|
+
{ 'id' => '333' },
|
230
|
+
{ 'id' => '444' },
|
231
|
+
{ 'id' => '555' }
|
238
232
|
]
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
}
|
247
|
-
})
|
233
|
+
})
|
234
|
+
|
235
|
+
@solr_resp_no_docs = RSpecSolr::SolrResponseHash.new('response' =>
|
236
|
+
{ 'numFound' => 0,
|
237
|
+
'start' => 0,
|
238
|
+
'docs' => []
|
239
|
+
})
|
248
240
|
end
|
249
|
-
|
250
|
-
end
|
241
|
+
end
|
@@ -2,114 +2,107 @@ require 'spec_helper'
|
|
2
2
|
require 'rspec-solr'
|
3
3
|
|
4
4
|
describe RSpecSolr::SolrResponseHash do
|
5
|
-
|
6
|
-
context "id field" do
|
5
|
+
context 'id field' do
|
7
6
|
before(:all) do
|
8
|
-
@srh = RSpecSolr::SolrResponseHash.new(
|
9
|
-
{
|
10
|
-
[
|
11
|
-
|
12
|
-
|
7
|
+
@srh = RSpecSolr::SolrResponseHash.new('response' =>
|
8
|
+
{ 'docs' =>
|
9
|
+
[{ 'id' => '111' },
|
10
|
+
{ 'not_id' => '222' },
|
11
|
+
{ 'id' => '333' }
|
13
12
|
]
|
14
|
-
}
|
15
|
-
})
|
13
|
+
})
|
16
14
|
end
|
17
15
|
it "should default to 'id'" do
|
18
|
-
RSpecSolr::SolrResponseHash.new({}).id_field.
|
19
|
-
@srh.id_field.
|
16
|
+
expect(RSpecSolr::SolrResponseHash.new({}).id_field).to eq('id')
|
17
|
+
expect(@srh.id_field).to eq('id')
|
20
18
|
end
|
21
|
-
it
|
22
|
-
@srh.id_field='new'
|
23
|
-
@srh.id_field.
|
24
|
-
@srh.id_field='newer'
|
25
|
-
@srh.id_field.
|
19
|
+
it 'should be changable to whatever' do
|
20
|
+
@srh.id_field = 'new'
|
21
|
+
expect(@srh.id_field).to eq('new')
|
22
|
+
@srh.id_field = 'newer'
|
23
|
+
expect(@srh.id_field).to eq('newer')
|
26
24
|
end
|
27
25
|
end
|
28
|
-
|
26
|
+
|
29
27
|
# fixture below
|
30
|
-
|
31
|
-
context
|
32
|
-
it
|
33
|
-
@solr_resp_5_docs.
|
34
|
-
@solr_resp_5_docs.
|
35
|
-
end
|
36
|
-
|
37
|
-
it
|
38
|
-
@solr_resp_5_docs.
|
39
|
-
end
|
40
|
-
|
41
|
-
it
|
42
|
-
@solr_resp_5_docs.
|
43
|
-
end
|
44
|
-
|
45
|
-
it
|
46
|
-
@solr_resp_5_docs.
|
47
|
-
end
|
48
|
-
|
49
|
-
it
|
50
|
-
@solr_resp_5_docs.
|
51
|
-
end
|
52
|
-
|
53
|
-
it
|
54
|
-
@solr_resp_5_docs.
|
55
|
-
end
|
56
|
-
|
28
|
+
|
29
|
+
context 'has_document?' do
|
30
|
+
it 'should be true when single document meets expectation' do
|
31
|
+
expect(@solr_resp_5_docs).to have_document('id' => '222')
|
32
|
+
expect(@solr_resp_5_docs).to have_document('id' => '111', 'fld' => 'val')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should be true when at least one doc meets expectation' do
|
36
|
+
expect(@solr_resp_5_docs).to have_document('fld' => 'val')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should be false when no docs meet expectation' do
|
40
|
+
expect(@solr_resp_5_docs).not_to have_document('id' => 'not_there')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be false when only part of expectation is met' do
|
44
|
+
expect(@solr_resp_5_docs).not_to have_document('id' => '222', 'fld' => 'val')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should be true when document is < = expected position in results' do
|
48
|
+
expect(@solr_resp_5_docs).to have_document({ 'id' => '222' }, 2)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should be false when document is > expected position in results' do
|
52
|
+
expect(@solr_resp_5_docs).not_to have_document({ 'id' => '222' }, 1)
|
53
|
+
end
|
57
54
|
end # has_document?
|
58
|
-
|
59
|
-
context
|
60
|
-
it
|
61
|
-
@solr_resp_5_docs.get_first_doc_index(
|
62
|
-
@solr_resp_5_docs.get_first_doc_index(
|
63
|
-
end
|
64
|
-
|
65
|
-
it
|
66
|
-
@solr_resp_5_docs.get_first_doc_index(
|
67
|
-
@solr_resp_5_docs.get_first_doc_index(
|
68
|
-
end
|
69
|
-
|
70
|
-
it
|
71
|
-
@solr_resp_5_docs.get_first_doc_index([
|
72
|
-
@solr_resp_5_docs.get_first_doc_index(
|
73
|
-
end
|
74
|
-
|
55
|
+
|
56
|
+
context 'get_first_doc_index' do
|
57
|
+
it 'should get the right document index with an id String argument' do
|
58
|
+
expect(@solr_resp_5_docs.get_first_doc_index('333')).to eq(2)
|
59
|
+
expect(@solr_resp_5_docs.get_first_doc_index('111')).to eq(0)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should get the first occurrence of a doc meeting a Hash argument' do
|
63
|
+
expect(@solr_resp_5_docs.get_first_doc_index('fld' => 'val')).to eq(0)
|
64
|
+
expect(@solr_resp_5_docs.get_first_doc_index('id' => '333')).to eq(2)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should get the index of the doc occurring first in the results from an Array argument' do
|
68
|
+
expect(@solr_resp_5_docs.get_first_doc_index(['fld' => 'val'])).to eq(0)
|
69
|
+
expect(@solr_resp_5_docs.get_first_doc_index(%w(222 444))).to eq(1)
|
70
|
+
end
|
71
|
+
|
75
72
|
it "should return nil when the expectation argument isn't met" do
|
76
|
-
@solr_resp_5_docs.get_first_doc_index(
|
77
|
-
@solr_resp_5_docs.get_first_doc_index(
|
78
|
-
@solr_resp_5_docs.get_first_doc_index(
|
73
|
+
expect(@solr_resp_5_docs.get_first_doc_index('666')).to be_nil
|
74
|
+
expect(@solr_resp_5_docs.get_first_doc_index('not_there' => 'not_there')).to be_nil
|
75
|
+
expect(@solr_resp_5_docs.get_first_doc_index(%w(222 666))).to be_nil
|
79
76
|
end
|
80
|
-
|
81
77
|
end
|
82
|
-
|
83
|
-
context
|
84
|
-
it
|
85
|
-
@solr_resp_5_docs.send(:get_min_index, nil, nil).
|
78
|
+
|
79
|
+
context 'get_min_index' do
|
80
|
+
it 'should return nil when both arguments are nil' do
|
81
|
+
expect(@solr_resp_5_docs.send(:get_min_index, nil, nil)).to be_nil
|
86
82
|
end
|
87
|
-
it
|
88
|
-
@solr_resp_5_docs.send(:get_min_index, 3, nil).
|
83
|
+
it 'should return the first argument when the second argument is nil' do
|
84
|
+
expect(@solr_resp_5_docs.send(:get_min_index, 3, nil)).to eq(3)
|
89
85
|
end
|
90
|
-
it
|
91
|
-
@solr_resp_5_docs.send(:get_min_index, nil, 5).
|
86
|
+
it 'should return the second argument when the first argument is nil' do
|
87
|
+
expect(@solr_resp_5_docs.send(:get_min_index, nil, 5)).to eq(5)
|
88
|
+
end
|
89
|
+
it 'should return the minimum of the two arguments when neither of them is nil' do
|
90
|
+
expect(@solr_resp_5_docs.send(:get_min_index, 2, 5)).to eq(2)
|
91
|
+
expect(@solr_resp_5_docs.send(:get_min_index, 5, 2)).to eq(2)
|
92
92
|
end
|
93
|
-
it "should return the minimum of the two arguments when neither of them is nil" do
|
94
|
-
@solr_resp_5_docs.send(:get_min_index, 2, 5).should == 2
|
95
|
-
@solr_resp_5_docs.send(:get_min_index, 5, 2).should == 2
|
96
|
-
end
|
97
93
|
end
|
98
|
-
|
99
|
-
|
94
|
+
|
100
95
|
before(:all) do
|
101
|
-
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new(
|
102
|
-
{
|
103
|
-
|
104
|
-
|
105
|
-
[
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
96
|
+
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new('response' =>
|
97
|
+
{ 'numFound' => 5,
|
98
|
+
'start' => 0,
|
99
|
+
'docs' =>
|
100
|
+
[{ 'id' => '111', 'fld' => 'val' },
|
101
|
+
{ 'id' => '222' },
|
102
|
+
{ 'id' => '333', 'fld' => 'val' },
|
103
|
+
{ 'id' => '444' },
|
104
|
+
{ 'id' => '555' }
|
110
105
|
]
|
111
|
-
}
|
112
|
-
})
|
106
|
+
})
|
113
107
|
end
|
114
|
-
|
115
|
-
end
|
108
|
+
end
|