rspec-solr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +5 -0
- data/README.rdoc +31 -0
- data/Rakefile +19 -0
- data/expectation_matchers.rdoc +148 -0
- data/lib/rspec-solr/have_documents_matcher.rb +34 -0
- data/lib/rspec-solr/include_documents_matcher.rb +105 -0
- data/lib/rspec-solr/solr_response_hash.rb +130 -0
- data/lib/rspec-solr/version.rb +3 -0
- data/lib/rspec-solr.rb +7 -0
- data/lib/tasks/ci.rake +5 -0
- data/lib/tasks/doc.rake +21 -0
- data/lib/tasks/spec.rake +5 -0
- data/rspec-solr.gemspec +35 -0
- data/spec/have_documents_spec.rb +60 -0
- data/spec/include_before_spec.rb +107 -0
- data/spec/include_document_spec.rb +423 -0
- data/spec/include_in_first_n_spec.rb +229 -0
- data/spec/number_of_documents_spec.rb +250 -0
- data/spec/solr_response_hash_spec.rb +115 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/matchers.rb +22 -0
- metadata +202 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec-solr'
|
3
|
+
|
4
|
+
describe RSpecSolr do
|
5
|
+
|
6
|
+
# fixtures below
|
7
|
+
|
8
|
+
context "should include().before()" do
|
9
|
+
|
10
|
+
it "passes when criteria are met" do
|
11
|
+
@solr_resp_5_docs.should include("111").before("222")
|
12
|
+
@solr_resp_5_docs.should include("333").before("fld"=>["val1", "val2", "val3"])
|
13
|
+
@solr_resp_5_docs.should include("fld"=>"val").before("fld"=>["val1", "val2", "val3"])
|
14
|
+
@solr_resp_5_docs.should include(["111", "222"]).before(["333", "555"])
|
15
|
+
@solr_resp_5_docs.should include([{"id"=>"111"}, {"id"=>"333"}]).before([{"id"=>"444"}, {"id"=>"555"}])
|
16
|
+
end
|
17
|
+
it "passes when criteria CAN BE met (more than one option)" do
|
18
|
+
@solr_resp_5_docs.should include("111").before("fld"=>"val")
|
19
|
+
end
|
20
|
+
it "fails when docs aren't in expected order" do
|
21
|
+
lambda {
|
22
|
+
@solr_resp_5_docs.should include("222").before("fld2"=>"val2")
|
23
|
+
}.should fail_matching('} to include document "222" before document matching {"fld2"=>"val2"}')
|
24
|
+
lambda {
|
25
|
+
@solr_resp_5_docs.should include("111", "444").before([{"id"=>"333"}, {"id"=>"555"}])
|
26
|
+
}.should fail_matching('} to include documents "111" and "444" before documents matching [{"id"=>"333"}, {"id"=>"555"}]')
|
27
|
+
lambda {
|
28
|
+
@solr_resp_5_docs.should include([{"id"=>"222"}, {"id"=>"444"}]).before([{"id"=>"333"}, {"id"=>"555"}])
|
29
|
+
}.should fail_matching('} to include documents [{"id"=>"222"}, {"id"=>"444"}] before documents matching [{"id"=>"333"}, {"id"=>"555"}]')
|
30
|
+
end
|
31
|
+
it "fails when it can't find a doc matching first argument(s)" do
|
32
|
+
lambda {
|
33
|
+
@solr_resp_5_docs.should include("not_there").before("555")
|
34
|
+
}.should fail_matching('} to include document "not_there" before document matching "555"')
|
35
|
+
end
|
36
|
+
it "fails when it can't find a doc matching second argument(s)" do
|
37
|
+
lambda {
|
38
|
+
@solr_resp_5_docs.should include("222").before("not_there")
|
39
|
+
}.should fail_matching('} to include document "222" before document matching "not_there"')
|
40
|
+
end
|
41
|
+
it "fails when it can't find docs matching first or second argument(s)" do
|
42
|
+
lambda {
|
43
|
+
@solr_resp_5_docs.should include("not_there").before("still_not_there")
|
44
|
+
}.should fail_matching('} to include document "not_there" before document matching "still_not_there"')
|
45
|
+
end
|
46
|
+
|
47
|
+
end # should include().before()
|
48
|
+
|
49
|
+
|
50
|
+
context "should_NOT include().before()" do
|
51
|
+
|
52
|
+
it "fails when criteria are met" do
|
53
|
+
lambda {
|
54
|
+
@solr_resp_5_docs.should_not include("111").before("222")
|
55
|
+
}.should fail_matching('not to include document "111" before document matching "222"')
|
56
|
+
lambda {
|
57
|
+
@solr_resp_5_docs.should_not include("333").before("fld"=>["val1", "val2", "val3"])
|
58
|
+
}.should fail_matching('not to include document "333" before document matching {"fld"=>["val1", "val2", "val3"]}')
|
59
|
+
lambda {
|
60
|
+
@solr_resp_5_docs.should_not include("fld"=>"val").before("fld"=>["val1", "val2", "val3"])
|
61
|
+
}.should fail_matching('not to include document {"fld"=>"val"} before document matching {"fld"=>["val1", "val2", "val3"]}')
|
62
|
+
lambda {
|
63
|
+
@solr_resp_5_docs.should_not include(["111", "222"]).before(["333", "555"])
|
64
|
+
}.should fail_matching('not to include documents ["111", "222"] before documents matching ["333", "555"]')
|
65
|
+
lambda {
|
66
|
+
@solr_resp_5_docs.should_not include([{"id"=>"111"}, {"id"=>"333"}]).before([{"id"=>"444"}, {"id"=>"555"}])
|
67
|
+
}.should fail_matching('not to include documents [{"id"=>"111"}, {"id"=>"333"}] before documents matching [{"id"=>"444"}, {"id"=>"555"}]')
|
68
|
+
end
|
69
|
+
it "fails when criteria CAN BE met (more than one option)" do
|
70
|
+
lambda {
|
71
|
+
@solr_resp_5_docs.should_not include("111").before("fld"=>"val")
|
72
|
+
}.should fail_matching('not to include document "111" before document matching {"fld"=>"val"}')
|
73
|
+
end
|
74
|
+
it "passes when docs aren't in expected order" do
|
75
|
+
@solr_resp_5_docs.should_not include("222").before("fld2"=>"val2")
|
76
|
+
# NOTE: it is picky about the next line include() being ["111", "444"], not just "111", "444"
|
77
|
+
@solr_resp_5_docs.should_not include(["111", "444"]).before([{"id"=>"333"}, {"id"=>"555"}])
|
78
|
+
@solr_resp_5_docs.should_not include([{"id"=>"222"}, {"id"=>"444"}]).before([{"id"=>"333"}, {"id"=>"555"}])
|
79
|
+
end
|
80
|
+
it "passes when it can't find a doc matching first argument(s)" do
|
81
|
+
@solr_resp_5_docs.should_not include("not_there").before("555")
|
82
|
+
end
|
83
|
+
it "passes when it can't find a doc matching second argument(s)" do
|
84
|
+
@solr_resp_5_docs.should_not include("222").before("not_there")
|
85
|
+
end
|
86
|
+
it "passes when it can't find docs matching first or second argument(s)" do
|
87
|
+
@solr_resp_5_docs.should_not include("not_there").before("still_not_there")
|
88
|
+
end
|
89
|
+
|
90
|
+
end # should_NOT include().before()
|
91
|
+
|
92
|
+
before(:all) do
|
93
|
+
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new({ "response" =>
|
94
|
+
{ "numFound" => 5,
|
95
|
+
"start" => 0,
|
96
|
+
"docs" =>
|
97
|
+
[ {"id"=>"111", "fld"=>"val", "fld2"=>"val2"},
|
98
|
+
{"id"=>"222"},
|
99
|
+
{"id"=>"333", "fld"=>"val"},
|
100
|
+
{"id"=>"444", "fld"=>["val1", "val2", "val3"]},
|
101
|
+
{"id"=>"555"}
|
102
|
+
]
|
103
|
+
}
|
104
|
+
})
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,423 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec-solr'
|
3
|
+
|
4
|
+
describe RSpecSolr do
|
5
|
+
|
6
|
+
# fixtures below
|
7
|
+
|
8
|
+
context "RSpecSolr::SolrResponseHash #include matcher" do
|
9
|
+
|
10
|
+
context "should include('fldname'=>'fldval')" do
|
11
|
+
|
12
|
+
it "passes if Solr document in response contains 'fldval' in named field" do
|
13
|
+
@solr_resp_5_docs.should include("id" => "111")
|
14
|
+
@solr_resp_5_docs.should include("fld" => "val") # 2 docs match
|
15
|
+
end
|
16
|
+
it "passes if single value expectation is expressed as an Array" do
|
17
|
+
@solr_resp_5_docs.should include("id" => ["111"])
|
18
|
+
end
|
19
|
+
it "fails if no Solr document in response has 'fldval' for the named field" do
|
20
|
+
lambda {
|
21
|
+
@solr_resp_5_docs.should include("id" => "not_there")
|
22
|
+
}.should fail_matching('} to include {"id"=>"not_there"}')
|
23
|
+
end
|
24
|
+
it "fails if no Solr document in response has the named field" do
|
25
|
+
lambda {
|
26
|
+
@solr_resp_5_docs.should include("not_there" => "anything")
|
27
|
+
}.should fail_matching('} to include {"not_there"=>"anything"}')
|
28
|
+
end
|
29
|
+
end # "should include('fldname'=>'fldval')"
|
30
|
+
|
31
|
+
context "should_NOT include('fldname'=>'fldval')" do
|
32
|
+
|
33
|
+
it "fails if Solr document in response contains 'fldval' in named field" do
|
34
|
+
lambda {
|
35
|
+
@solr_resp_5_docs.should_not include("id" => "111")
|
36
|
+
}.should fail_matching('not to include {"id"=>"111"}')
|
37
|
+
lambda {
|
38
|
+
@solr_resp_5_docs.should_not include("fld" => "val")
|
39
|
+
}.should fail_matching('not to include {"fld"=>"val"}')
|
40
|
+
end
|
41
|
+
it "passes if no Solr document in response has 'fldval' for the named field" do
|
42
|
+
@solr_resp_5_docs.should_not include({"id" => "not_there"})
|
43
|
+
end
|
44
|
+
it "passes if no Solr document in response has the named field" do
|
45
|
+
@solr_resp_5_docs.should_not include({"not_there" => "anything"})
|
46
|
+
end
|
47
|
+
it "passes if single field value is expressed as Array" do
|
48
|
+
@solr_resp_5_docs.should_not include({"id" => ["not_there"]})
|
49
|
+
end
|
50
|
+
end # "should_not include('fldname'=>'fldval')"
|
51
|
+
|
52
|
+
context "should include('fld1'=>'val1', 'fld2'=>'val2')" do
|
53
|
+
|
54
|
+
it "passes if all pairs are included in a Solr document in the response" do
|
55
|
+
@solr_resp_5_docs.should include("id" => "111", "fld" => "val")
|
56
|
+
@solr_resp_5_docs.should include("id" => "333", "fld" => "val")
|
57
|
+
end
|
58
|
+
it "fails if only part of expectation is met" do
|
59
|
+
lambda {
|
60
|
+
@solr_resp_5_docs.should include("id" => "111", "fld" => "not_there")
|
61
|
+
}.should fail_matching('} to include {"id"=>"111", "fld"=>"not_there"}')
|
62
|
+
lambda {
|
63
|
+
@solr_resp_5_docs.should include("id" => "111", "not_there" => "whatever")
|
64
|
+
}.should fail_matching('} to include {"id"=>"111", "not_there"=>"whatever"}')
|
65
|
+
lambda {
|
66
|
+
@solr_resp_5_docs.should include("id" => "222", "fld" => "val")
|
67
|
+
}.should fail_matching('} to include {"id"=>"222", "fld"=>"val"}')
|
68
|
+
end
|
69
|
+
it "fails if no part of expectation is met" do
|
70
|
+
lambda {
|
71
|
+
@solr_resp_5_docs.should include("id" => "not_there", "not_there" => "anything")
|
72
|
+
}.should fail_matching('} to include {"id"=>"not_there", "not_there"=>"anything"}')
|
73
|
+
end
|
74
|
+
end # should include('fld1'=>'val1', 'fld2'=>'val2')
|
75
|
+
|
76
|
+
context "should_NOT include('fld1'=>'val1', 'fld2'=>'val2')" do
|
77
|
+
|
78
|
+
it "fails if a Solr document in the response contains all the key/value pairs" do
|
79
|
+
lambda {
|
80
|
+
@solr_resp_5_docs.should_not include("id" => "333", "fld" => "val")
|
81
|
+
}.should fail_matching('not to include {"id"=>"333", "fld"=>"val"}')
|
82
|
+
end
|
83
|
+
it "passes if a Solr document in the response contains all the key/value pairs among others" do
|
84
|
+
lambda {
|
85
|
+
@solr_resp_5_docs.should_not include("id" => "111", "fld" => "val")
|
86
|
+
}.should fail_matching('not to include {"id"=>"111", "fld"=>"val"}')
|
87
|
+
end
|
88
|
+
it "passes if part of the expectation is not met" do
|
89
|
+
@solr_resp_5_docs.should_not include("id" => "111", "fld" => "not_there")
|
90
|
+
@solr_resp_5_docs.should_not include("id" => "111", "not_there" => "whatever")
|
91
|
+
@solr_resp_5_docs.should_not include("id" => "222", "fld" => "val")
|
92
|
+
end
|
93
|
+
it "passes if no part of the expectatio is met" do
|
94
|
+
@solr_resp_5_docs.should_not include("id" => "not_there", "not_there" => "anything")
|
95
|
+
end
|
96
|
+
end # should_not include('fld1'=>'val1', 'fld2'=>'val2')
|
97
|
+
|
98
|
+
|
99
|
+
context "multi-valued fields and expectations" do
|
100
|
+
|
101
|
+
context "should include(doc_exp)" do
|
102
|
+
it "passes if all the expected values match all the values in a Solr document in the response" do
|
103
|
+
@solr_resp_5_docs.should include("fld" => ["val1", "val2", "val3"])
|
104
|
+
@solr_resp_5_docs.should include("fld" => ["val1", "val2", "val3"], "id" => "444")
|
105
|
+
end
|
106
|
+
it "passes if all the expected values match some of the values in a Solr document in the response" do
|
107
|
+
@solr_resp_5_docs.should include("fld" => ["val1", "val2"])
|
108
|
+
@solr_resp_5_docs.should include("fld" => "val1")
|
109
|
+
@solr_resp_5_docs.should include("fld" => ["val1", "val2"], "id" => "444")
|
110
|
+
end
|
111
|
+
it "fails if none of the expected values match the values in a Solr document in the response" do
|
112
|
+
lambda {
|
113
|
+
@solr_resp_5_docs.should include("fld" => ["not_there", "also_not_there"])
|
114
|
+
}.should fail_matching('} to include {"fld"=>["not_there", "also_not_there"]}')
|
115
|
+
end
|
116
|
+
it "fails if only some of the expected values match the values in a Solr document in the response" do
|
117
|
+
lambda {
|
118
|
+
@solr_resp_5_docs.should include("fld" => ["val1", "val2", "not_there"])
|
119
|
+
}.should fail_matching('} to include {"fld"=>["val1", "val2", "not_there"]}')
|
120
|
+
end
|
121
|
+
end # should
|
122
|
+
|
123
|
+
context "should_NOT include(doc_exp)" do
|
124
|
+
it "fails if all the expected values match all the values in a Solr document in the response" do
|
125
|
+
lambda {
|
126
|
+
@solr_resp_5_docs.should_not include("fld" => ["val1", "val2", "val3"])
|
127
|
+
}.should fail_matching('not to include {"fld"=>["val1", "val2", "val3"]}')
|
128
|
+
lambda {
|
129
|
+
@solr_resp_5_docs.should_not include("fld" => ["val1", "val2", "val3"], "id" => "444")
|
130
|
+
}.should fail_matching('not to include {"fld"=>["val1", "val2", "val3"], "id"=>"444"}')
|
131
|
+
end
|
132
|
+
it "fails if all the expected values match some of the values in a Solr document in the response" do
|
133
|
+
lambda {
|
134
|
+
@solr_resp_5_docs.should_not include("fld" => ["val1", "val2"])
|
135
|
+
}.should fail_matching('not to include {"fld"=>["val1", "val2"]}')
|
136
|
+
lambda {
|
137
|
+
@solr_resp_5_docs.should_not include("fld" => "val1")
|
138
|
+
}.should fail_matching('not to include {"fld"=>"val1"}')
|
139
|
+
lambda {
|
140
|
+
@solr_resp_5_docs.should_not include("fld" => ["val1", "val2"], "id" => "444")
|
141
|
+
}.should fail_matching('not to include {"fld"=>["val1", "val2"], "id"=>"444"}')
|
142
|
+
end
|
143
|
+
it "passes if none of the expected values match the values in a Solr document in the response" do
|
144
|
+
@solr_resp_5_docs.should_not include("fld" => ["not_there", "also_not_there"])
|
145
|
+
@solr_resp_5_docs.should_not include("fld" => ["not_there", "also_not_there"], "id" => "444")
|
146
|
+
end
|
147
|
+
it "passes if only some of the expected values match the values in a Solr document in the response" do
|
148
|
+
@solr_resp_5_docs.should_not include("fld" => ["val1", "val2", "not_there"])
|
149
|
+
@solr_resp_5_docs.should_not include("fld" => ["val1", "val2", "not_there"], "id" => "444")
|
150
|
+
end
|
151
|
+
end # should_not
|
152
|
+
|
153
|
+
end # multi-valued fields in docs
|
154
|
+
|
155
|
+
|
156
|
+
context "single String argument" do
|
157
|
+
|
158
|
+
context "should include(single_string_arg)" do
|
159
|
+
it "passes if string matches default id_field of Solr document in the response" do
|
160
|
+
@solr_resp_5_docs.should include('111')
|
161
|
+
end
|
162
|
+
it "passes if string matches non-default id_field in the SolrResponseHash object" do
|
163
|
+
my_srh = @solr_resp_5_docs.clone
|
164
|
+
my_srh.id_field='fld2'
|
165
|
+
my_srh.should include('val2')
|
166
|
+
end
|
167
|
+
it "fails if string does not match default id_field of Solr document in the response" do
|
168
|
+
lambda {
|
169
|
+
@solr_resp_5_docs.should include('666')
|
170
|
+
}.should fail_matching('} to include "666"')
|
171
|
+
end
|
172
|
+
it "fails if string doesn't match non-default id_field in the SolrResponseHash object" do
|
173
|
+
my_srh = @solr_resp_5_docs.clone
|
174
|
+
my_srh.id_field='fld2'
|
175
|
+
lambda {
|
176
|
+
my_srh.should include('val')
|
177
|
+
}.should fail_matching('} to include "val"')
|
178
|
+
end
|
179
|
+
end # should
|
180
|
+
|
181
|
+
context "should_NOT include(single_string_arg)" do
|
182
|
+
it "fails if string matches default id_field of Solr document in the response" do
|
183
|
+
lambda {
|
184
|
+
@solr_resp_5_docs.should_not include('111')
|
185
|
+
}.should fail_matching('not to include "111"')
|
186
|
+
end
|
187
|
+
it "fails if string matches non-default id_field in the SolrResponseHash object" do
|
188
|
+
my_srh = @solr_resp_5_docs.clone
|
189
|
+
my_srh.id_field='fld2'
|
190
|
+
lambda {
|
191
|
+
my_srh.should_not include('val2')
|
192
|
+
}.should fail_matching('not to include "val2"')
|
193
|
+
end
|
194
|
+
it "passes if string does not match default id_field of Solr document in the response" do
|
195
|
+
@solr_resp_5_docs.should_not include('666')
|
196
|
+
end
|
197
|
+
it "fails if string doesn't match non-default id_field in the SolrResponseHash object" do
|
198
|
+
my_srh = @solr_resp_5_docs.clone
|
199
|
+
my_srh.id_field='fld2'
|
200
|
+
my_srh.should_not include('val')
|
201
|
+
end
|
202
|
+
end # should_not
|
203
|
+
|
204
|
+
end # single String arg
|
205
|
+
|
206
|
+
context "Array argument" do
|
207
|
+
|
208
|
+
context "should include(Array_of_Strings)" do
|
209
|
+
it "passes if all Strings in Array match all Solr documents' id_field in the response" do
|
210
|
+
@solr_resp_5_docs.should include(["111", "222", "333", "444", "555"])
|
211
|
+
my_srh = @solr_resp_5_docs.clone
|
212
|
+
my_srh.id_field='fld2'
|
213
|
+
my_srh.should include(["val2"])
|
214
|
+
end
|
215
|
+
it "passes if all Strings in Array match some Solr documents' id_field in the response" do
|
216
|
+
@solr_resp_5_docs.should include(["111", "222", "333"])
|
217
|
+
@solr_resp_5_docs.should include(["111"])
|
218
|
+
my_srh = @solr_resp_5_docs.clone
|
219
|
+
my_srh.id_field='fld'
|
220
|
+
my_srh.should include(["val"])
|
221
|
+
end
|
222
|
+
it "fails if no Strings in Array match Solr documents' id_field in the response" do
|
223
|
+
lambda {
|
224
|
+
@solr_resp_5_docs.should include(["888", "899"])
|
225
|
+
}.should fail_matching ('} to include ["888", "899"]')
|
226
|
+
my_srh = @solr_resp_5_docs.clone
|
227
|
+
my_srh.id_field='fld2'
|
228
|
+
lambda {
|
229
|
+
my_srh.should include(["val8", "val9"])
|
230
|
+
}.should fail_matching ('} to include ["val8", "val9"]')
|
231
|
+
end
|
232
|
+
it "fails if only some Strings in Array match Solr documents' id_field in the response" do
|
233
|
+
lambda {
|
234
|
+
@solr_resp_5_docs.should include(["111", "222", "999"])
|
235
|
+
}.should fail_matching('} to include ["111", "222", "999"]')
|
236
|
+
lambda {
|
237
|
+
@solr_resp_5_docs.should include(["666", "555"])
|
238
|
+
}.should fail_matching('} to include ["666", "555"]')
|
239
|
+
my_srh = @solr_resp_5_docs.clone
|
240
|
+
my_srh.id_field='fld2'
|
241
|
+
lambda {
|
242
|
+
my_srh.should include(["val2", "val9"])
|
243
|
+
}.should fail_matching('} to include ["val2", "val9"]')
|
244
|
+
end
|
245
|
+
end # should include(Array_of_Strings)
|
246
|
+
|
247
|
+
context "should_NOT include(Array_of_Strings)" do
|
248
|
+
it "fails if all Strings in Array match all Solr documents' id_field in the response" do
|
249
|
+
lambda {
|
250
|
+
@solr_resp_5_docs.should_not include(["111", "222", "333", "444", "555"])
|
251
|
+
}.should fail_matching('not to include ["111", "222", "333", "444", "555"]')
|
252
|
+
my_srh = @solr_resp_5_docs.clone
|
253
|
+
my_srh.id_field='fld2'
|
254
|
+
lambda {
|
255
|
+
my_srh.should_not include(["val2"])
|
256
|
+
}.should fail_matching('not to include ["val2"]')
|
257
|
+
end
|
258
|
+
it "fails if all Strings in Array match some Solr documents' id_field in the response" do
|
259
|
+
lambda {
|
260
|
+
@solr_resp_5_docs.should_not include(["111", "222", "333"])
|
261
|
+
}.should fail_matching('not to include ["111", "222", "333"]')
|
262
|
+
lambda {
|
263
|
+
@solr_resp_5_docs.should_not include(["111"])
|
264
|
+
}.should fail
|
265
|
+
my_srh = @solr_resp_5_docs.clone
|
266
|
+
my_srh.id_field='fld'
|
267
|
+
lambda {
|
268
|
+
my_srh.should_not include(["val"])
|
269
|
+
}.should fail_matching('not to include ["val"]')
|
270
|
+
end
|
271
|
+
it "passes if no Strings in Array match Solr documents' id_field in the response" do
|
272
|
+
@solr_resp_5_docs.should_not include(["888", "899"])
|
273
|
+
my_srh = @solr_resp_5_docs.clone
|
274
|
+
my_srh.id_field='fld2'
|
275
|
+
my_srh.should_not include(["val8", "val9"])
|
276
|
+
end
|
277
|
+
it "passes if only some Strings in Array match Solr documents' id_field in the response" do
|
278
|
+
@solr_resp_5_docs.should_not include(["111", "222", "999"])
|
279
|
+
@solr_resp_5_docs.should_not include(["666", "555"])
|
280
|
+
my_srh = @solr_resp_5_docs.clone
|
281
|
+
my_srh.id_field='fld2'
|
282
|
+
my_srh.should_not include(["val2", "val9"])
|
283
|
+
end
|
284
|
+
end # should_not include(Array_of_Strings)
|
285
|
+
|
286
|
+
context "should include(Array_of_Hashes)" do
|
287
|
+
it "passes if all Hashes in Array match all Solr documents in the response" do
|
288
|
+
@solr_resp_5_docs.should include([{"id"=>"111", "fld"=>"val", "fld2"=>"val2"},
|
289
|
+
{"id"=>"222"},
|
290
|
+
{"id"=>"333", "fld"=>"val"},
|
291
|
+
{"id"=>"444", "fld"=>["val1", "val2", "val3"]},
|
292
|
+
{"id"=>"555"}])
|
293
|
+
@solr_resp_5_docs.should include([{"id"=>"111"}, {"id"=>"222"}, {"id"=>"333"}, {"id"=>"444"}, {"id"=>"555"}])
|
294
|
+
end
|
295
|
+
it "passes if all Hashes in Array match some Solr documents in the response" do
|
296
|
+
@solr_resp_5_docs.should include([{"id"=>"333", "fld"=>"val"}, {"id"=>"111", "fld2"=>"val2"}])
|
297
|
+
@solr_resp_5_docs.should include([{"fld"=>"val"}])
|
298
|
+
end
|
299
|
+
it "fails if no Hashes in Array match Solr documents in the response" do
|
300
|
+
lambda {
|
301
|
+
@solr_resp_5_docs.should include([{"foo"=>"bar"}, {"bar"=>"food", "mmm"=>"food"}])
|
302
|
+
}.should fail_matching('} to include [{"foo"=>"bar"}, {"bar"=>"food", "mmm"=>"food"}]')
|
303
|
+
end
|
304
|
+
it "fails if only some Hashes in Array match Solr documents in the response" do
|
305
|
+
lambda {
|
306
|
+
@solr_resp_5_docs.should include([{"id"=>"222"}, {"id"=>"333", "fld"=>"val"}, {"foo"=>"bar"}, {"bar"=>"food", "mmm"=>"food"}])
|
307
|
+
}.should fail_matching('} to include [{"id"=>"222"},')
|
308
|
+
end
|
309
|
+
end # should include(Array_of_Hashes)
|
310
|
+
|
311
|
+
context "should_NOT include(Array_of_Hashes)" do
|
312
|
+
it "fails if all Hashes in Array match all Solr documents in the response" do
|
313
|
+
lambda {
|
314
|
+
@solr_resp_5_docs.should_not include([{"id"=>"111", "fld"=>"val", "fld2"=>"val2"},
|
315
|
+
{"id"=>"222"},
|
316
|
+
{"id"=>"333", "fld"=>"val"},
|
317
|
+
{"id"=>"444", "fld"=>["val1", "val2", "val3"]},
|
318
|
+
{"id"=>"555"}])
|
319
|
+
}.should fail
|
320
|
+
lambda {
|
321
|
+
@solr_resp_5_docs.should_not include([{"id"=>"111"}, {"id"=>"222"}, {"id"=>"333"}, {"id"=>"444"}, {"id"=>"555"}])
|
322
|
+
}.should fail_matching('not to include [{"id"=>"111"},')
|
323
|
+
end
|
324
|
+
it "fails if all Hashes in Array match some Solr documents in the response" do
|
325
|
+
lambda {
|
326
|
+
@solr_resp_5_docs.should_not include([{"id"=>"333", "fld"=>"val"}, {"id"=>"111", "fld2"=>"val2"}])
|
327
|
+
}.should fail_matching('not to include [{"id"=>"333",')
|
328
|
+
lambda {
|
329
|
+
@solr_resp_5_docs.should_not include([{"fld"=>"val"}])
|
330
|
+
}.should fail
|
331
|
+
end
|
332
|
+
it "passes if no Hashes in Array match Solr documents in the response" do
|
333
|
+
@solr_resp_5_docs.should_not include([{"foo"=>"bar"}, {"bar"=>"food", "mmm"=>"food"}])
|
334
|
+
end
|
335
|
+
it "passes if only some Hashes in Array match Solr documents in the response" do
|
336
|
+
@solr_resp_5_docs.should_not include([{"id"=>"222"}, {"id"=>"333", "fld"=>"val"}, {"foo"=>"bar"}, {"bar"=>"food", "mmm"=>"food"}])
|
337
|
+
end
|
338
|
+
|
339
|
+
end # should_not include(Array_of_Hashes)
|
340
|
+
|
341
|
+
context "mixed Array of Strings and Hashes" do
|
342
|
+
it "passes if all elements of Array pass" do
|
343
|
+
@solr_resp_5_docs.should include([ "222", {"id"=>"111", "fld"=>"val"}, "555" ])
|
344
|
+
end
|
345
|
+
it "fails if any element of Array fails" do
|
346
|
+
lambda {
|
347
|
+
@solr_resp_5_docs.should include([ "not_there", {"id"=>"111", "fld"=>"val"}, "555" ])
|
348
|
+
}.should fail_matching('} to include [')
|
349
|
+
lambda {
|
350
|
+
@solr_resp_5_docs.should include([ "222", {"id"=>"111", "not"=>"there"}, "555" ])
|
351
|
+
}.should fail_matching('} to include [')
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should allow #have_documents as alternative to #include" do
|
356
|
+
@solr_resp_5_docs.should have_documents(["111", "222", "333"])
|
357
|
+
end
|
358
|
+
|
359
|
+
end # Array argument
|
360
|
+
|
361
|
+
|
362
|
+
context "regex value" do
|
363
|
+
|
364
|
+
context 'should include(:key => "/regex/")' do
|
365
|
+
it "does something" do
|
366
|
+
pending "to be implemented"
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
end # regex value
|
371
|
+
|
372
|
+
|
373
|
+
before(:all) do
|
374
|
+
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new({ "response" =>
|
375
|
+
{ "numFound" => 5,
|
376
|
+
"start" => 0,
|
377
|
+
"docs" =>
|
378
|
+
[ {"id"=>"111", "fld"=>"val", "fld2"=>"val2"},
|
379
|
+
{"id"=>"222"},
|
380
|
+
{"id"=>"333", "fld"=>"val"},
|
381
|
+
{"id"=>"444", "fld"=>["val1", "val2", "val3"]},
|
382
|
+
{"id"=>"555"}
|
383
|
+
]
|
384
|
+
}
|
385
|
+
})
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
context "shouldn't break RSpec #include matcher" do
|
390
|
+
it "for String" do
|
391
|
+
"abc".should include("a")
|
392
|
+
"abc".should_not include("d")
|
393
|
+
end
|
394
|
+
|
395
|
+
it "for Array" do
|
396
|
+
[1,2,3].should include(3)
|
397
|
+
[1,2,3].should include(2,3)
|
398
|
+
[1,2,3].should_not include(4)
|
399
|
+
lambda {
|
400
|
+
[1,2,3].should include(1,666)
|
401
|
+
}.should fail
|
402
|
+
lambda {
|
403
|
+
[1,2,3].should_not include(1,666)
|
404
|
+
}.should fail
|
405
|
+
end
|
406
|
+
|
407
|
+
it "for Hash" do
|
408
|
+
{:key => 'value'}.should include(:key)
|
409
|
+
{:key => 'value'}.should_not include(:key2)
|
410
|
+
lambda {
|
411
|
+
{:key => 'value'}.should include(:key, :other)
|
412
|
+
}.should fail
|
413
|
+
lambda {
|
414
|
+
{:key => 'value'}.should_not include(:key, :other)
|
415
|
+
}.should fail
|
416
|
+
{'key' => 'value'}.should include('key')
|
417
|
+
{'key' => 'value'}.should_not include('key2')
|
418
|
+
end
|
419
|
+
end # context shouldn't break RSpec #include matcher
|
420
|
+
|
421
|
+
end # context RSpecSolr::SolrResponseHash #include matcher
|
422
|
+
|
423
|
+
end
|