rspec-solr 1.0.1 → 2.0.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/.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,102 +2,99 @@ require 'spec_helper'
|
|
2
2
|
require 'rspec-solr'
|
3
3
|
|
4
4
|
describe RSpecSolr do
|
5
|
-
|
6
5
|
# fixtures below
|
7
|
-
|
8
|
-
context
|
9
|
-
context
|
10
|
-
it
|
11
|
-
@solr_resp.
|
12
|
-
@solr_resp.
|
13
|
-
@solr_resp.
|
6
|
+
|
7
|
+
context '#include().in_each_of_first(n)' do
|
8
|
+
context 'should' do
|
9
|
+
it 'passes when all docs in range meet criteria' do
|
10
|
+
expect(@solr_resp).to include('fld' => 'val').in_each_of_first(2)
|
11
|
+
expect(@solr_resp).to include('fld' => 'val').in_each_of_first(2).documents
|
12
|
+
expect(@solr_resp).to include('fld' => 'val').in_each_of_first(2).results
|
14
13
|
end
|
15
|
-
it
|
16
|
-
@solr_resp.
|
17
|
-
@solr_resp.
|
18
|
-
@solr_resp.
|
14
|
+
it 'passes when all docs in range meet regex criteria' do
|
15
|
+
expect(@solr_resp).to include('fld' => /val/).in_each_of_first(2)
|
16
|
+
expect(@solr_resp).to include('fld' => /al/).in_each_of_first(2)
|
17
|
+
expect(@solr_resp).to include('fld' => /Val/i).in_each_of_first(2)
|
19
18
|
end
|
20
19
|
it "fails when doc in range doesn't meet criteria" do
|
21
|
-
|
22
|
-
@solr_resp.
|
23
|
-
|
24
|
-
|
25
|
-
@solr_resp.
|
26
|
-
|
20
|
+
expect do
|
21
|
+
expect(@solr_resp).to include('fld2' => 'val2').in_each_of_first(2)
|
22
|
+
end.to raise_error.with_message a_string_including 'expected each of the first 2 documents to include {"fld2"=>"val2"}'
|
23
|
+
expect do
|
24
|
+
expect(@solr_resp).to include('fld' => 'val').in_each_of_first(3)
|
25
|
+
end.to raise_error.with_message a_string_including 'expected each of the first 3 documents to include {"fld"=>"val"}'
|
27
26
|
end
|
28
27
|
it "fails when doc in range doesn't meet regex criteria" do
|
29
|
-
|
30
|
-
@solr_resp.
|
31
|
-
|
32
|
-
|
33
|
-
@solr_resp.
|
34
|
-
|
28
|
+
expect do
|
29
|
+
expect(@solr_resp).to include('fld2' => /l2/).in_each_of_first(2)
|
30
|
+
end.to raise_error.with_message a_string_including 'expected each of the first 2 documents to include {"fld2"=>/l2/}'
|
31
|
+
expect do
|
32
|
+
expect(@solr_resp).to include('fld' => /al/).in_each_of_first(3)
|
33
|
+
end.to raise_error.with_message a_string_including 'expected each of the first 3 documents to include {"fld"=>/al/}'
|
35
34
|
end
|
36
35
|
end
|
37
|
-
context
|
38
|
-
it
|
39
|
-
|
40
|
-
@solr_resp.
|
41
|
-
|
42
|
-
|
43
|
-
@solr_resp.
|
44
|
-
|
45
|
-
|
46
|
-
@solr_resp.
|
47
|
-
|
36
|
+
context 'should_NOT' do
|
37
|
+
it 'fails when all docs in range meet criteria' do
|
38
|
+
expect do
|
39
|
+
expect(@solr_resp).not_to include('fld' => 'val').in_each_of_first(2)
|
40
|
+
end.to raise_error.with_message a_string_including 'expected some of the first 2 documents not to include {"fld"=>"val"}'
|
41
|
+
expect do
|
42
|
+
expect(@solr_resp).not_to include('fld' => 'val').in_each_of_first(2).documents
|
43
|
+
end.to raise_error.with_message a_string_including 'expected some of the first 2 documents not to include {"fld"=>"val"}'
|
44
|
+
expect do
|
45
|
+
expect(@solr_resp).not_to include('fld' => 'val').in_each_of_first(2).results
|
46
|
+
end.to raise_error.with_message a_string_including 'expected some of the first 2 documents not to include {"fld"=>"val"}'
|
48
47
|
end
|
49
|
-
it
|
50
|
-
|
51
|
-
@solr_resp.
|
52
|
-
|
53
|
-
|
54
|
-
@solr_resp.
|
55
|
-
|
56
|
-
|
57
|
-
@solr_resp.
|
58
|
-
|
48
|
+
it 'fails when all docs in range meet regex criteria' do
|
49
|
+
expect do
|
50
|
+
expect(@solr_resp).not_to include('fld' => /val/).in_each_of_first(2)
|
51
|
+
end.to raise_error.with_message a_string_including 'expected some of the first 2 documents not to include {"fld"=>/val/}'
|
52
|
+
expect do
|
53
|
+
expect(@solr_resp).not_to include('fld' => /al/).in_each_of_first(2)
|
54
|
+
end.to raise_error.with_message a_string_including 'expected some of the first 2 documents not to include {"fld"=>/al/}'
|
55
|
+
expect do
|
56
|
+
expect(@solr_resp).not_to include('fld' => /Val/i).in_each_of_first(2)
|
57
|
+
end.to raise_error.with_message a_string_including 'expected some of the first 2 documents not to include {"fld"=>/Val/i}'
|
59
58
|
end
|
60
59
|
it "passes when doc in range doesn't meet criteria" do
|
61
|
-
@solr_resp.
|
62
|
-
@solr_resp.
|
60
|
+
expect(@solr_resp).not_to include('fld' => 'val').in_each_of_first(3)
|
61
|
+
expect(@solr_resp).not_to include('fld2' => 'val2').in_each_of_first(2)
|
63
62
|
end
|
64
63
|
it "passes when doc in range doesn't meet regex criteria" do
|
65
|
-
@solr_resp.
|
66
|
-
@solr_resp.
|
64
|
+
expect(@solr_resp).not_to include('fld2' => /l2/).in_each_of_first(2)
|
65
|
+
expect(@solr_resp).not_to include('fld' => /al/).in_each_of_first(3)
|
67
66
|
end
|
68
67
|
end
|
69
|
-
it
|
70
|
-
expect
|
71
|
-
@solr_resp.
|
72
|
-
|
73
|
-
expect
|
74
|
-
@solr_resp.
|
75
|
-
|
76
|
-
expect
|
77
|
-
@solr_resp.
|
78
|
-
|
79
|
-
expect
|
80
|
-
@solr_resp.
|
81
|
-
|
82
|
-
expect
|
83
|
-
@solr_resp.
|
84
|
-
|
68
|
+
it 'should expect a Hash for the include' do
|
69
|
+
expect do
|
70
|
+
expect(@solr_resp).to include('111').in_each_of_first(1)
|
71
|
+
end.to raise_error(ArgumentError, 'in_each_of_first(n) requires a Hash argument to include() method')
|
72
|
+
expect do
|
73
|
+
expect(@solr_resp).to include(%w(111 222)).in_each_of_first(1)
|
74
|
+
end.to raise_error(ArgumentError, 'in_each_of_first(n) requires a Hash argument to include() method')
|
75
|
+
expect do
|
76
|
+
expect(@solr_resp).not_to include('111').in_each_of_first(1)
|
77
|
+
end.to raise_error(ArgumentError, 'in_each_of_first(n) requires a Hash argument to include() method')
|
78
|
+
expect do
|
79
|
+
expect(@solr_resp).to include('fld' => 'val').in_each_of_first(1)
|
80
|
+
end.to_not raise_error
|
81
|
+
expect do
|
82
|
+
expect(@solr_resp).to include('fld' => 'val', 'fld2' => 'val2').in_each_of_first(1)
|
83
|
+
end.to_not raise_error
|
85
84
|
end
|
86
85
|
end
|
87
|
-
|
86
|
+
|
88
87
|
before(:all) do
|
89
|
-
@solr_resp = RSpecSolr::SolrResponseHash.new(
|
90
|
-
{
|
91
|
-
|
92
|
-
|
93
|
-
[
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
88
|
+
@solr_resp = RSpecSolr::SolrResponseHash.new('response' =>
|
89
|
+
{ 'numFound' => 5,
|
90
|
+
'start' => 0,
|
91
|
+
'docs' =>
|
92
|
+
[{ 'id' => '111', 'fld' => 'val', 'fld2' => 'val2' },
|
93
|
+
{ 'id' => '222', 'fld' => 'val' },
|
94
|
+
{ 'id' => '333' },
|
95
|
+
{ 'id' => '444', 'fld' => %w(val1 val2 val3) },
|
96
|
+
{ 'id' => '555' }
|
98
97
|
]
|
99
|
-
}
|
100
|
-
})
|
98
|
+
})
|
101
99
|
end
|
102
|
-
|
103
|
-
end
|
100
|
+
end
|
@@ -2,232 +2,228 @@ require 'spec_helper'
|
|
2
2
|
require 'rspec-solr'
|
3
3
|
|
4
4
|
describe RSpecSolr do
|
5
|
-
|
6
5
|
# fixtures below
|
7
|
-
|
8
|
-
context
|
9
|
-
context
|
10
|
-
it
|
11
|
-
@solr_resp_5_docs.
|
12
|
-
@solr_resp_5_docs.
|
13
|
-
@solr_resp_5_docs.
|
14
|
-
end
|
15
|
-
it
|
16
|
-
|
17
|
-
@solr_resp_5_docs.
|
18
|
-
|
19
|
-
end
|
20
|
-
it
|
21
|
-
@solr_resp_5_docs.
|
22
|
-
end
|
23
|
-
it
|
24
|
-
|
25
|
-
@solr_resp_5_docs.
|
26
|
-
|
27
|
-
end
|
28
|
-
it
|
29
|
-
@solr_resp_5_docs.
|
30
|
-
@solr_resp_5_docs.
|
31
|
-
end
|
32
|
-
it
|
33
|
-
|
34
|
-
@solr_resp_5_docs.
|
35
|
-
|
36
|
-
|
37
|
-
@solr_resp_5_docs.
|
38
|
-
|
39
|
-
end
|
40
|
-
it
|
41
|
-
|
42
|
-
@solr_resp_5_docs.
|
43
|
-
|
44
|
-
|
45
|
-
@solr_resp_5_docs.
|
46
|
-
|
47
|
-
|
48
|
-
@solr_resp_5_docs.
|
49
|
-
|
6
|
+
|
7
|
+
context '#include().in_first(n)' do
|
8
|
+
context 'should include().in_first(n)' do
|
9
|
+
it 'passes when include arg is String and doc meets criteria' do
|
10
|
+
expect(@solr_resp_5_docs).to include('222').in_first(3)
|
11
|
+
expect(@solr_resp_5_docs).to include('111').in_first(1)
|
12
|
+
expect(@solr_resp_5_docs).to include('222').in_first(2)
|
13
|
+
end
|
14
|
+
it 'fails when include arg is String but doc comes too late' do
|
15
|
+
expect do
|
16
|
+
expect(@solr_resp_5_docs).to include('222').in_first(1)
|
17
|
+
end.to raise_error.with_message a_string_including 'expected response to include document "222" in first 1'
|
18
|
+
end
|
19
|
+
it 'passes when include arg is Hash and doc meets criteria' do
|
20
|
+
expect(@solr_resp_5_docs).to include('fld' => %w(val1 val2 val3)).in_first(4)
|
21
|
+
end
|
22
|
+
it 'fails when include arg is Hash but doc comes too late' do
|
23
|
+
expect do
|
24
|
+
expect(@solr_resp_5_docs).to include('fld' => %w(val1 val2 val3)).in_first(2)
|
25
|
+
end.to raise_error.with_message a_string_including 'expected response to include document {"fld"=>["val1", "val2", "val3"]} in first 2'
|
26
|
+
end
|
27
|
+
it 'passes when include arg is Array and all docs meet criteria' do
|
28
|
+
expect(@solr_resp_5_docs).to include(%w(111 222)).in_first(2)
|
29
|
+
expect(@solr_resp_5_docs).to include(['333', { 'fld2' => 'val2' }]).in_first(4)
|
30
|
+
end
|
31
|
+
it 'fails when include arg is Array but at least one doc comes too late' do
|
32
|
+
expect do
|
33
|
+
expect(@solr_resp_5_docs).to include(%w(111 444)).in_first(2)
|
34
|
+
end.to raise_error.with_message a_string_including 'expected response to include documents ["111", "444"] in first 2'
|
35
|
+
expect do
|
36
|
+
expect(@solr_resp_5_docs).to include(['333', { 'fld2' => 'val2' }]).in_first(2)
|
37
|
+
end.to raise_error.with_message a_string_including 'expected response to include documents ["333", {"fld2"=>"val2"}] in first 2'
|
38
|
+
end
|
39
|
+
it 'fails when there is no matching result' do
|
40
|
+
expect do
|
41
|
+
expect(@solr_resp_5_docs).to include('666').in_first(6)
|
42
|
+
end.to raise_error.with_message a_string_including 'expected response to include document "666" in first 6'
|
43
|
+
expect do
|
44
|
+
expect(@solr_resp_5_docs).to include('fld' => 'not there').in_first(3)
|
45
|
+
end.to raise_error.with_message a_string_including 'expected response to include document {"fld"=>"not there"} in first 3'
|
46
|
+
expect do
|
47
|
+
expect(@solr_resp_5_docs).to include('666', '777').in_first(6)
|
48
|
+
end.to raise_error.with_message a_string_including 'expected response to include documents "666" and "777" in first 6'
|
50
49
|
end
|
51
50
|
end # should include().in_first(n)
|
52
51
|
|
53
|
-
context
|
54
|
-
it
|
55
|
-
|
56
|
-
@solr_resp_5_docs.
|
57
|
-
|
58
|
-
end
|
59
|
-
it
|
60
|
-
@solr_resp_5_docs.
|
61
|
-
end
|
62
|
-
it
|
63
|
-
|
64
|
-
@solr_resp_5_docs.
|
65
|
-
|
66
|
-
end
|
67
|
-
it
|
68
|
-
@solr_resp_5_docs.
|
69
|
-
end
|
70
|
-
it
|
71
|
-
|
72
|
-
@solr_resp_5_docs.
|
73
|
-
|
74
|
-
|
75
|
-
@solr_resp_5_docs.
|
76
|
-
|
77
|
-
end
|
78
|
-
it
|
79
|
-
@solr_resp_5_docs.
|
80
|
-
@solr_resp_5_docs.
|
81
|
-
end
|
82
|
-
it
|
83
|
-
@solr_resp_5_docs.
|
84
|
-
@solr_resp_5_docs.
|
85
|
-
@solr_resp_5_docs.
|
86
|
-
end
|
87
|
-
end # should_NOT include().in_first(n)
|
52
|
+
context 'should_NOT include().in_first(n)' do
|
53
|
+
it 'fails when include arg is String and doc meets criteria' do
|
54
|
+
expect do
|
55
|
+
expect(@solr_resp_5_docs).not_to include('222').in_first(2)
|
56
|
+
end.to raise_error.with_message a_string_including 'not to include document "222" in first 2'
|
57
|
+
end
|
58
|
+
it 'passes when include arg is String but doc comes too late' do
|
59
|
+
expect(@solr_resp_5_docs).not_to include('222').in_first(1)
|
60
|
+
end
|
61
|
+
it 'fails when include arg is Hash and doc meets criteria' do
|
62
|
+
expect do
|
63
|
+
expect(@solr_resp_5_docs).not_to include('fld' => %w(val1 val2 val3)).in_first(4)
|
64
|
+
end.to raise_error.with_message a_string_including 'not to include document {"fld"=>["val1", "val2", "val3"]} in first 4'
|
65
|
+
end
|
66
|
+
it 'passes when include arg is Hash but doc comes too late' do
|
67
|
+
expect(@solr_resp_5_docs).not_to include('fld' => %w(val1 val2 val3)).in_first(2)
|
68
|
+
end
|
69
|
+
it 'fails when include arg is Array and all docs meet criteria' do
|
70
|
+
expect do
|
71
|
+
expect(@solr_resp_5_docs).not_to include('111', '222').in_first(2)
|
72
|
+
end.to raise_error.with_message a_string_including 'not to include documents "111" and "222" in first 2'
|
73
|
+
expect do
|
74
|
+
expect(@solr_resp_5_docs).not_to include(['333', { 'fld2' => 'val2' }]).in_first(4)
|
75
|
+
end.to raise_error.with_message a_string_including 'not to include documents ["333", {"fld2"=>"val2"}] in first 4'
|
76
|
+
end
|
77
|
+
it 'passes when include arg is Array but at least one doc comes too late' do
|
78
|
+
expect(@solr_resp_5_docs).not_to include(%w(111 444)).in_first(2)
|
79
|
+
expect(@solr_resp_5_docs).not_to include(['333', { 'fld2' => 'val2' }]).in_first(2)
|
80
|
+
end
|
81
|
+
it 'passes when there is no matching result' do
|
82
|
+
expect(@solr_resp_5_docs).not_to include('666').in_first(6)
|
83
|
+
expect(@solr_resp_5_docs).not_to include('fld' => 'not there').in_first(3)
|
84
|
+
expect(@solr_resp_5_docs).not_to include('666', '777').in_first(6)
|
85
|
+
end
|
86
|
+
end # should_NOT include().in_first(n)
|
88
87
|
end # include().in_first(n)
|
89
|
-
|
90
|
-
context
|
91
|
-
context
|
92
|
-
it
|
93
|
-
@solr_resp_5_docs.
|
88
|
+
|
89
|
+
context '#include().in_first (no n set) implies n=1' do
|
90
|
+
context 'should #include().in_first' do
|
91
|
+
it 'passes when matching document is first' do
|
92
|
+
expect(@solr_resp_5_docs).to include('111').in_first
|
94
93
|
end
|
95
|
-
it
|
96
|
-
|
97
|
-
@solr_resp_5_docs.
|
98
|
-
|
94
|
+
it 'fails when matching document is not first' do
|
95
|
+
expect do
|
96
|
+
expect(@solr_resp_5_docs).to include('fld' => %w(val1 val2 val3)).in_first
|
97
|
+
end.to raise_error.with_message a_string_including 'expected response to include document {"fld"=>["val1", "val2", "val3"]} in first 1'
|
99
98
|
end
|
100
99
|
end
|
101
|
-
context
|
102
|
-
it
|
103
|
-
|
104
|
-
@solr_resp_5_docs.
|
105
|
-
|
100
|
+
context 'should_NOT include().in_first' do
|
101
|
+
it 'fails when matching document is first' do
|
102
|
+
expect do
|
103
|
+
expect(@solr_resp_5_docs).not_to include('111').in_first
|
104
|
+
end.to raise_error.with_message a_string_including 'not to include document "111" in first 1'
|
106
105
|
end
|
107
|
-
it
|
108
|
-
@solr_resp_5_docs.
|
106
|
+
it 'passes when matching document is not first' do
|
107
|
+
expect(@solr_resp_5_docs).not_to include('fld' => %w(val1 val2 val3)).in_first
|
109
108
|
end
|
110
109
|
end
|
111
110
|
end # include().in_first (no n set)
|
112
|
-
|
113
|
-
context
|
114
|
-
context
|
115
|
-
it
|
116
|
-
@solr_resp_5_docs.
|
117
|
-
@solr_resp_5_docs.
|
118
|
-
@solr_resp_5_docs.
|
111
|
+
|
112
|
+
context '#include().in_first(n).allowed_chained.names' do
|
113
|
+
context 'should #include().in_first(n).allowed_chained.names' do
|
114
|
+
it 'passes when document(s) meet criteria' do
|
115
|
+
expect(@solr_resp_5_docs).to include('222').in_first(2).results
|
116
|
+
expect(@solr_resp_5_docs).to include('222').in_first(2).documents
|
117
|
+
expect(@solr_resp_5_docs).to include('fld2' => 'val2').in_first.document
|
119
118
|
end
|
120
119
|
it "fails when document(s) don't meet criteria" do
|
121
|
-
|
122
|
-
@solr_resp_5_docs.
|
123
|
-
|
120
|
+
expect do
|
121
|
+
expect(@solr_resp_5_docs).to include('fld' => %w(val1 val2 val3)).in_first.result
|
122
|
+
end.to raise_error.with_message a_string_including 'expected response to include document {"fld"=>["val1", "val2", "val3"]} in first 1'
|
124
123
|
end
|
125
124
|
end
|
126
|
-
context
|
127
|
-
it
|
128
|
-
|
129
|
-
@solr_resp_5_docs.
|
130
|
-
|
131
|
-
|
132
|
-
@solr_resp_5_docs.
|
133
|
-
|
125
|
+
context 'should_NOT #include().in_first(n).allowed_chained.names' do
|
126
|
+
it 'fails when document(s) meet criteria' do
|
127
|
+
expect do
|
128
|
+
expect(@solr_resp_5_docs).not_to include('222').in_first(2).documents
|
129
|
+
end.to raise_error.with_message a_string_including 'not to include document "222" in first 2 '
|
130
|
+
expect do
|
131
|
+
expect(@solr_resp_5_docs).not_to include('fld2' => 'val2').in_first.document
|
132
|
+
end.to raise_error.with_message a_string_including 'not to include document {"fld2"=>"val2"} in first 1'
|
134
133
|
end
|
135
134
|
it "passes when document(s) don't meet criteria" do
|
136
|
-
@solr_resp_5_docs.
|
135
|
+
expect(@solr_resp_5_docs).not_to include('fld' => %w(val1 val2 val3)).in_first.result
|
137
136
|
end
|
138
137
|
end
|
139
|
-
it
|
140
|
-
expect
|
141
|
-
@solr_resp.
|
142
|
-
|
143
|
-
end
|
138
|
+
it 'should raise a NoMethodError exception when it gets nonsense after include' do
|
139
|
+
expect do
|
140
|
+
expect(@solr_resp).to include('111').bad_method(2)
|
141
|
+
end.to raise_error(NoMethodError, /bad_method/)
|
142
|
+
end
|
144
143
|
end # include().in_first().allowed_chained.names
|
145
|
-
|
146
|
-
context
|
147
|
-
context
|
148
|
-
it
|
149
|
-
@solr_resp_5_docs.
|
150
|
-
@solr_resp_5_docs.
|
151
|
-
@solr_resp_5_docs.
|
152
|
-
end
|
153
|
-
it
|
154
|
-
|
155
|
-
@solr_resp_5_docs.
|
156
|
-
|
157
|
-
|
158
|
-
@solr_resp_5_docs.
|
159
|
-
|
160
|
-
end
|
161
|
-
it
|
162
|
-
|
163
|
-
@solr_resp_5_docs.
|
164
|
-
|
165
|
-
end
|
144
|
+
|
145
|
+
context '#include().as_first' do
|
146
|
+
context 'should include().as_first' do
|
147
|
+
it 'passes when the first document meets the criteria' do
|
148
|
+
expect(@solr_resp_5_docs).to include('111').as_first
|
149
|
+
expect(@solr_resp_5_docs).to include('fld' => 'val').as_first
|
150
|
+
expect(@solr_resp_5_docs).to include('fld' => 'val', 'fld2' => 'val2').as_first
|
151
|
+
end
|
152
|
+
it 'fails when a document meets the criteria but is not the first' do
|
153
|
+
expect do
|
154
|
+
expect(@solr_resp_5_docs).to include('222').as_first
|
155
|
+
end.to raise_error.with_message a_string_including 'expected response to include document "222" in first 1'
|
156
|
+
expect do
|
157
|
+
expect(@solr_resp_5_docs).to include('fld' => %w(val1 val2 val3)).as_first
|
158
|
+
end.to raise_error.with_message a_string_including 'expected response to include document {"fld"=>["val1", "val2", "val3"]} in first 1'
|
159
|
+
end
|
160
|
+
it 'fails when there is no matching result' do
|
161
|
+
expect do
|
162
|
+
expect(@solr_resp_5_docs).to include('96').as_first
|
163
|
+
end.to raise_error.with_message a_string_including 'expected response to include document "96" in first 1'
|
164
|
+
end
|
166
165
|
end
|
167
|
-
context
|
168
|
-
it
|
169
|
-
|
170
|
-
@solr_resp_5_docs.
|
171
|
-
|
172
|
-
|
173
|
-
@solr_resp_5_docs.
|
174
|
-
|
175
|
-
|
176
|
-
@solr_resp_5_docs.
|
177
|
-
|
178
|
-
end
|
179
|
-
it
|
180
|
-
@solr_resp_5_docs.
|
181
|
-
@solr_resp_5_docs.
|
182
|
-
end
|
183
|
-
it
|
184
|
-
@solr_resp_5_docs.
|
185
|
-
end
|
166
|
+
context 'should_NOT include().as_first' do
|
167
|
+
it 'fails when the first document meets the criteria' do
|
168
|
+
expect do
|
169
|
+
expect(@solr_resp_5_docs).not_to include('111').as_first
|
170
|
+
end.to raise_error.with_message a_string_including 'not to include document "111" in first 1'
|
171
|
+
expect do
|
172
|
+
expect(@solr_resp_5_docs).not_to include('fld' => 'val').as_first
|
173
|
+
end.to raise_error.with_message a_string_including 'not to include document {"fld"=>"val"} in first 1'
|
174
|
+
expect do
|
175
|
+
expect(@solr_resp_5_docs).not_to include('fld' => 'val', 'fld2' => 'val2').as_first
|
176
|
+
end.to raise_error.with_message a_string_including 'not to include document {"fld"=>"val", "fld2"=>"val2"} in first 1'
|
177
|
+
end
|
178
|
+
it 'passes when a document meets the criteria but is not the first' do
|
179
|
+
expect(@solr_resp_5_docs).not_to include('222').as_first.document
|
180
|
+
expect(@solr_resp_5_docs).not_to include('fld' => %w(val1 val2 val3)).as_first
|
181
|
+
end
|
182
|
+
it 'passes when there is no matching result' do
|
183
|
+
expect(@solr_resp_5_docs).not_to include('96').as_first
|
184
|
+
end
|
186
185
|
end
|
187
186
|
end
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
@solr_resp_5_docs.
|
194
|
-
@solr_resp_5_docs.
|
195
|
-
@solr_resp_5_docs.should include("fld2"=>"val2").as_first.document
|
187
|
+
|
188
|
+
context '#include().as_first().allowed_chained.names' do
|
189
|
+
context 'should #include().as_first(n).allowed_chained.names' do
|
190
|
+
it 'passes when document(s) meet criteria' do
|
191
|
+
expect(@solr_resp_5_docs).to include(%w(111 222)).as_first(2).results
|
192
|
+
expect(@solr_resp_5_docs).to include(%w(111 222)).as_first(2).documents
|
193
|
+
expect(@solr_resp_5_docs).to include('fld2' => 'val2').as_first.document
|
196
194
|
end
|
197
195
|
it "fails when document(s) don't meet criteria" do
|
198
|
-
|
199
|
-
@solr_resp_5_docs.
|
200
|
-
|
196
|
+
expect do
|
197
|
+
expect(@solr_resp_5_docs).to include('fld' => %w(val1 val2 val3)).as_first.result
|
198
|
+
end.to raise_error.with_message a_string_including 'expected response to include document {"fld"=>["val1", "val2", "val3"]} in first 1'
|
201
199
|
end
|
202
200
|
end
|
203
|
-
context
|
204
|
-
it
|
205
|
-
|
206
|
-
@solr_resp_5_docs.
|
207
|
-
|
208
|
-
|
209
|
-
@solr_resp_5_docs.
|
210
|
-
|
201
|
+
context 'should_NOT #include().as_first(n).any_chained.names' do
|
202
|
+
it 'fails when document(s) meet criteria' do
|
203
|
+
expect do
|
204
|
+
expect(@solr_resp_5_docs).not_to include(%w(111 222)).as_first(2).documents
|
205
|
+
end.to raise_error.with_message a_string_including 'not to include documents ["111", "222"] in first 2'
|
206
|
+
expect do
|
207
|
+
expect(@solr_resp_5_docs).not_to include('fld2' => 'val2').as_first.document
|
208
|
+
end.to raise_error.with_message a_string_including 'not to include document {"fld2"=>"val2"} in first 1'
|
211
209
|
end
|
212
210
|
it "passes when document(s) don't meet criteria" do
|
213
|
-
@solr_resp_5_docs.
|
211
|
+
expect(@solr_resp_5_docs).not_to include('fld' => %w(val1 val2 val3)).as_first.result
|
214
212
|
end
|
215
213
|
end
|
216
214
|
end # include().as_first().allowed_chained.names
|
217
215
|
|
218
216
|
before(:all) do
|
219
|
-
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new(
|
220
|
-
{
|
221
|
-
|
222
|
-
|
223
|
-
[
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
217
|
+
@solr_resp_5_docs = RSpecSolr::SolrResponseHash.new('response' =>
|
218
|
+
{ 'numFound' => 5,
|
219
|
+
'start' => 0,
|
220
|
+
'docs' =>
|
221
|
+
[{ 'id' => '111', 'fld' => 'val', 'fld2' => 'val2' },
|
222
|
+
{ 'id' => '222' },
|
223
|
+
{ 'id' => '333', 'fld' => 'val' },
|
224
|
+
{ 'id' => '444', 'fld' => %w(val1 val2 val3) },
|
225
|
+
{ 'id' => '555' }
|
228
226
|
]
|
229
|
-
}
|
230
|
-
})
|
227
|
+
})
|
231
228
|
end
|
232
|
-
|
233
|
-
end
|
229
|
+
end
|