rspec-solr 0.0.1 → 0.0.2
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.
- data/README.rdoc +4 -0
- data/expectation_matchers.rdoc +26 -14
- data/lib/rspec-solr.rb +1 -0
- data/lib/rspec-solr/compare_num_docs_matcher.rb +109 -0
- data/lib/rspec-solr/have_documents_matcher.rb +0 -6
- data/lib/rspec-solr/include_documents_matcher.rb +1 -1
- data/lib/rspec-solr/solr_response_hash.rb +8 -1
- data/lib/rspec-solr/version.rb +1 -1
- data/rspec-solr.gemspec +1 -1
- data/spec/comparing_num_docs_in_2_resp_spec.rb +277 -0
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -22,6 +22,10 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
See expecation_matchers.rdoc
|
24
24
|
|
25
|
+
== Ruby Version Compatibility
|
26
|
+
|
27
|
+
This should work with various rubies 1.8.7, but currently some tests expected ordered hashes (though the code itself doesn't require them).
|
28
|
+
|
25
29
|
== Contributing
|
26
30
|
|
27
31
|
1. Fork it
|
data/expectation_matchers.rdoc
CHANGED
@@ -113,6 +113,32 @@ TODO: Potential Syntax:
|
|
113
113
|
* rspec-solr_resp_hash.should include("fld"=>"val").before("fld"=>["val1", "val2", "val3"])
|
114
114
|
* rspec-solr_resp_hash.should include([{"title" => "title1"}, {"title" => "title2"}]).before("title" => "title3")
|
115
115
|
|
116
|
+
|
117
|
+
== COMPARING TOTAL RESULTS OF TWO RESPONSES
|
118
|
+
|
119
|
+
NOTE: this is about the TOTAL number of Solr documents that match ("numFound"), NOT solely the documents returned in THESE responses
|
120
|
+
|
121
|
+
=== Matchers
|
122
|
+
* have_more_results_than()
|
123
|
+
* have_fewer_results_than()
|
124
|
+
* have_the_same_number_of_results_as()
|
125
|
+
* have_more_documents_than()
|
126
|
+
* have_fewer_documents_than()
|
127
|
+
* have_the_same_number_of_documents_as()
|
128
|
+
|
129
|
+
=== Usage
|
130
|
+
* rspec-solr_resp_hash1.should have_more_results_than(rspec-solr_resp_hash2)
|
131
|
+
* rspec-solr_resp_hash1.should have_fewer_results_than(rspec-solr_resp_hash2)
|
132
|
+
* rspec-solr_resp_hash1.should have_the_same_number_of_results_as(rspec-solr_resp_hash2)
|
133
|
+
|
134
|
+
==== Alternate (allows more granularity)
|
135
|
+
* rspec-solr_resp_hash1.size.should > rspec-solr_resp_hash2.size
|
136
|
+
* rspec-solr_resp_hash1.size.should >= rspec-solr_resp_hash2.size
|
137
|
+
* rspec-solr_resp_hash1.size.should < rspec-solr_resp_hash2.size
|
138
|
+
* rspec-solr_resp_hash1.size.should <= rspec-solr_resp_hash2.size
|
139
|
+
* rspec-solr_resp_hash1.size.should == rspec-solr_resp_hash2.size
|
140
|
+
* rspec-solr_resp_hash1.size.should be_within(delta).of(rspec-solr_resp_hash2.size)
|
141
|
+
|
116
142
|
== TODO: MATCHING FACET VALUES IN RESPONSE
|
117
143
|
|
118
144
|
NOTE: this is about the facet values returned in THIS response
|
@@ -132,17 +158,3 @@ rspec-solr_resp_hash.should include_facet
|
|
132
158
|
* include_facets().before_facets()
|
133
159
|
|
134
160
|
|
135
|
-
== TODO: COMPARING TOTAL RESULTS OF TWO RESPONSES
|
136
|
-
|
137
|
-
=== Specifying Second Response
|
138
|
-
* than_solr_response({:q => "foo", :sort => "title"}) # solr params
|
139
|
-
* than_search_for("foo") # only q is specified, defaults for everything else
|
140
|
-
|
141
|
-
=== Potential Syntax
|
142
|
-
rspec-solr_resp_hash.should
|
143
|
-
|
144
|
-
=== Matchers
|
145
|
-
* have_more_results_than_solr_response(:params)
|
146
|
-
* have_fewer_results_than_solr_response(:params)
|
147
|
-
* have_the_same_number_of_results_as_solr_response(:params)
|
148
|
-
|
data/lib/rspec-solr.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Custom RSpec Matchers for Solr responses
|
2
|
+
module RSpecSolr::Matchers
|
3
|
+
|
4
|
+
# Determine if the receiver has the same number of Solr docs as the expected
|
5
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
6
|
+
def have_the_same_number_of_results_as
|
7
|
+
# Placeholder method for documentation purposes;
|
8
|
+
# the actual method is defined using RSpec's matcher DSL
|
9
|
+
end
|
10
|
+
|
11
|
+
# Determine if the receiver has fewer Solr docs than the expected
|
12
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
13
|
+
def have_fewer_results_than
|
14
|
+
# Placeholder method for documentation purposes;
|
15
|
+
# the actual method is defined using RSpec's matcher DSL
|
16
|
+
end
|
17
|
+
|
18
|
+
# Determine if the receiver has more Solr docs than the expected
|
19
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
20
|
+
def have_more_results_than
|
21
|
+
# Placeholder method for documentation purposes;
|
22
|
+
# the actual method is defined using RSpec's matcher DSL
|
23
|
+
end
|
24
|
+
|
25
|
+
# this is the lambda used to determine if the receiver (a Solr response object) has the same number of total documents
|
26
|
+
# as the expected RSpecSolr::SolrResponseHash
|
27
|
+
def self.same_number_of_results_body
|
28
|
+
lambda { |expected_solr_resp_hash|
|
29
|
+
match do |actual_solr_resp_hash|
|
30
|
+
actual_solr_resp_hash.size == expected_solr_resp_hash.size
|
31
|
+
end
|
32
|
+
|
33
|
+
failure_message_for_should do |actual_solr_resp_hash|
|
34
|
+
"expected #{actual_solr_resp_hash.size} documents in Solr response #{expected_solr_resp_hash.num_docs_partial_output_str}"
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message_for_should_not do |actual_solr_resp_hash|
|
38
|
+
"expected (not #{actual_solr_resp_hash.size}) documents in Solr response #{expected_solr_resp_hash.num_docs_partial_output_str}"
|
39
|
+
end
|
40
|
+
|
41
|
+
diffable
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Determine if the receiver (a Solr response object) has the same number of total documents as the expected RSpecSolr::SolrResponseHash
|
46
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
47
|
+
RSpec::Matchers.define :have_the_same_number_of_results_as, &same_number_of_results_body
|
48
|
+
|
49
|
+
# Determine if the receiver (a Solr response object) has the same number of total documents as the expected RSpecSolr::SolrResponseHash
|
50
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
51
|
+
RSpec::Matchers.define :have_the_same_number_of_documents_as, &same_number_of_results_body
|
52
|
+
|
53
|
+
# this is the lambda used to determine if the receiver (a Solr response object) has fewer total documents
|
54
|
+
# than the expected RSpecSolr::SolrResponseHash
|
55
|
+
def self.fewer_results_than_body
|
56
|
+
lambda { |expected_solr_resp_hash|
|
57
|
+
match do |actual_solr_resp_hash|
|
58
|
+
actual_solr_resp_hash.size < expected_solr_resp_hash.size
|
59
|
+
end
|
60
|
+
|
61
|
+
failure_message_for_should do |actual_solr_resp_hash|
|
62
|
+
"expected more than #{actual_solr_resp_hash.size} documents in Solr response #{expected_solr_resp_hash.num_docs_partial_output_str}"
|
63
|
+
end
|
64
|
+
|
65
|
+
failure_message_for_should_not do |actual_solr_resp_hash|
|
66
|
+
"expected #{actual_solr_resp_hash.size} or fewer documents in Solr response #{expected_solr_resp_hash.num_docs_partial_output_str}"
|
67
|
+
end
|
68
|
+
|
69
|
+
diffable
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
# Determine if the receiver (a Solr response object) has fewer total documents than the expected RSpecSolr::SolrResponseHash
|
74
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
75
|
+
RSpec::Matchers.define :have_fewer_results_than, &fewer_results_than_body
|
76
|
+
|
77
|
+
# Determine if the receiver (a Solr response object) has fewer total documents than the expected RSpecSolr::SolrResponseHash
|
78
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
79
|
+
RSpec::Matchers.define :have_fewer_documents_than, &fewer_results_than_body
|
80
|
+
|
81
|
+
# this is the lambda used to determine if the receiver (a Solr response object) has more total documents
|
82
|
+
# than the expected RSpecSolr::SolrResponseHash
|
83
|
+
def self.more_results_than_body
|
84
|
+
lambda { |expected_solr_resp_hash|
|
85
|
+
match do |actual_solr_resp_hash|
|
86
|
+
actual_solr_resp_hash.size > expected_solr_resp_hash.size
|
87
|
+
end
|
88
|
+
|
89
|
+
failure_message_for_should do |actual_solr_resp_hash|
|
90
|
+
"expected fewer than #{actual_solr_resp_hash.size} documents in Solr response #{expected_solr_resp_hash.num_docs_partial_output_str}"
|
91
|
+
end
|
92
|
+
|
93
|
+
failure_message_for_should_not do |actual_solr_resp_hash|
|
94
|
+
"expected #{actual_solr_resp_hash.size} or more documents in Solr response #{expected_solr_resp_hash.num_docs_partial_output_str}"
|
95
|
+
end
|
96
|
+
|
97
|
+
diffable
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
# Determine if the receiver (a Solr response object) has more total documents than the expected RSpecSolr::SolrResponseHash
|
102
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
103
|
+
RSpec::Matchers.define :have_more_results_than, &more_results_than_body
|
104
|
+
|
105
|
+
# Determine if the receiver (a Solr response object) has more total documents than the expected RSpecSolr::SolrResponseHash
|
106
|
+
# NOTE: this is about the TOTAL number of Solr documents matching the queries, not solely the number of docs in THESE responses
|
107
|
+
RSpec::Matchers.define :have_more_documents_than, &more_results_than_body
|
108
|
+
|
109
|
+
end
|
@@ -21,7 +21,7 @@ class RSpecSolr
|
|
21
21
|
# my_solr_resp_hash.should have(3).documents
|
22
22
|
# my_solr_resp_hash.should have_at_least(3).documents
|
23
23
|
def size
|
24
|
-
self["response"]["numFound"] # total number of Solr docs matching query
|
24
|
+
self["response"] ? self["response"]["numFound"] : 0 # total number of Solr docs matching query
|
25
25
|
# NOT: self["response"]["docs"].size # number of Solr docs returned in THIS response
|
26
26
|
end
|
27
27
|
|
@@ -105,6 +105,13 @@ class RSpecSolr
|
|
105
105
|
return first_doc_index
|
106
106
|
end
|
107
107
|
|
108
|
+
# @return String containing response header and numFound parts of hash for readable output for number of docs messages
|
109
|
+
def num_docs_partial_output_str
|
110
|
+
"{'responseHeader' => #{self['responseHeader'].inspect}, " +
|
111
|
+
(self['response'] ? "'response' => {'numFound' => #{self['response']['numFound']}, ...}" : "" ) +
|
112
|
+
" ... }"
|
113
|
+
end
|
114
|
+
|
108
115
|
private
|
109
116
|
|
110
117
|
# return the minimum of the two arguments. If one of the arguments is nil, then return the other argument.
|
data/lib/rspec-solr/version.rb
CHANGED
data/rspec-solr.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |gem|
|
|
26
26
|
# docs
|
27
27
|
gem.add_development_dependency "rdoc"
|
28
28
|
gem.add_development_dependency "yard"
|
29
|
-
#
|
29
|
+
# test coverage for this gem
|
30
30
|
gem.add_development_dependency 'simplecov'
|
31
31
|
gem.add_development_dependency 'simplecov-rcov'
|
32
32
|
# continuous integration
|
@@ -0,0 +1,277 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec-solr'
|
3
|
+
|
4
|
+
describe RSpecSolr do
|
5
|
+
|
6
|
+
# fixtures below
|
7
|
+
|
8
|
+
context "should have_the_same_number_of_results_as()" do
|
9
|
+
it "passes if both results have same total number of documents" do
|
10
|
+
@solr_resp_1_doc.should have_the_same_number_of_results_as(@solr_resp_1_doc)
|
11
|
+
@solr_resp_3_docs.should have_the_same_number_of_results_as(@solr_resp_3_docs)
|
12
|
+
@solr_resp_many_docs.should have_the_same_number_of_results_as(@solr_resp_many_docs2)
|
13
|
+
end
|
14
|
+
it "passes if neither search matches any documents" do
|
15
|
+
@solr_resp_no_docs.should have_the_same_number_of_results_as(@solr_resp_no_docs)
|
16
|
+
end
|
17
|
+
it "fails if the first response has more total results" do
|
18
|
+
lambda {
|
19
|
+
@solr_resp_not3_docs.should have_the_same_number_of_results_as(@solr_resp_3_docs)
|
20
|
+
}.should fail_matching('expected 8 documents in Solr response {')
|
21
|
+
end
|
22
|
+
it "fails if the first response has fewer total results" do
|
23
|
+
lambda {
|
24
|
+
@solr_resp_3_docs.should have_the_same_number_of_results_as(@solr_resp_not3_docs)
|
25
|
+
}.should fail_matching('expected 3 documents in Solr response {')
|
26
|
+
end
|
27
|
+
it "fails if only one response has results" do
|
28
|
+
lambda {
|
29
|
+
@solr_resp_no_docs.should have_the_same_number_of_results_as(@solr_resp_not3_docs)
|
30
|
+
}.should fail_matching('expected 0 documents in Solr response {')
|
31
|
+
lambda {
|
32
|
+
@solr_resp_3_docs.should have_the_same_number_of_results_as(@solr_resp_no_docs)
|
33
|
+
}.should fail_matching('expected 3 documents in Solr response {')
|
34
|
+
end
|
35
|
+
end # should have_the_same_number_of_results_as()
|
36
|
+
|
37
|
+
context "should_NOT have_the_same_number_of_results_as()" do
|
38
|
+
it "fails if both results have same total number of documents" do
|
39
|
+
lambda {
|
40
|
+
@solr_resp_1_doc.should_not have_the_same_number_of_results_as(@solr_resp_1_doc)
|
41
|
+
}.should fail_matching('expected (not 1) documents in Solr response {')
|
42
|
+
lambda {
|
43
|
+
@solr_resp_3_docs.should_not have_the_same_number_of_results_as(@solr_resp_3_docs)
|
44
|
+
}.should fail_matching('expected (not 3) documents in Solr response {')
|
45
|
+
lambda {
|
46
|
+
@solr_resp_many_docs.should_not have_the_same_number_of_results_as(@solr_resp_many_docs2)
|
47
|
+
}.should fail_matching('expected (not 1019) documents in Solr response {')
|
48
|
+
end
|
49
|
+
it "fails if neither search matches any documents" do
|
50
|
+
lambda {
|
51
|
+
@solr_resp_no_docs.should_not have_the_same_number_of_results_as(@solr_resp_no_docs)
|
52
|
+
}.should fail_matching('expected (not 0) documents in Solr response {')
|
53
|
+
end
|
54
|
+
it "passes if the first response has more total results" do
|
55
|
+
@solr_resp_not3_docs.should_not have_the_same_number_of_results_as(@solr_resp_3_docs)
|
56
|
+
end
|
57
|
+
it "passes if the first response has fewer total results" do
|
58
|
+
@solr_resp_3_docs.should_not have_the_same_number_of_results_as(@solr_resp_not3_docs)
|
59
|
+
end
|
60
|
+
it "passes if only one response has results" do
|
61
|
+
@solr_resp_no_docs.should_not have_the_same_number_of_results_as(@solr_resp_not3_docs)
|
62
|
+
@solr_resp_3_docs.should_not have_the_same_number_of_results_as(@solr_resp_no_docs)
|
63
|
+
end
|
64
|
+
end # should_NOT have_the_same_number_of_results_as()
|
65
|
+
|
66
|
+
|
67
|
+
context "should have_fewer_results_than()" do
|
68
|
+
it "passes if first response has no results and second doc has results" do
|
69
|
+
@solr_resp_no_docs.should have_fewer_results_than(@solr_resp_1_doc)
|
70
|
+
@solr_resp_no_docs.should have_fewer_results_than(@solr_resp_many_docs)
|
71
|
+
end
|
72
|
+
it "passes if first response has a smaller number of total results" do
|
73
|
+
@solr_resp_1_doc.should have_fewer_results_than(@solr_resp_3_docs)
|
74
|
+
@solr_resp_3_docs.should have_fewer_results_than(@solr_resp_not3_docs)
|
75
|
+
@solr_resp_3_docs.should have_fewer_results_than(@solr_resp_many_docs)
|
76
|
+
end
|
77
|
+
it "fails if responses have same number of total results" do
|
78
|
+
lambda {
|
79
|
+
@solr_resp_3_docs.should have_fewer_results_than(@solr_resp_3_docs)
|
80
|
+
}.should fail_matching('expected more than 3 documents in Solr response {')
|
81
|
+
lambda {
|
82
|
+
@solr_resp_many_docs.should have_fewer_results_than(@solr_resp_many_docs2)
|
83
|
+
}.should fail_matching('expected more than 1019 documents in Solr response {')
|
84
|
+
lambda {
|
85
|
+
@solr_resp_no_docs.should have_fewer_results_than(@solr_resp_no_docs)
|
86
|
+
}.should fail_matching('expected more than 0 documents in Solr response {')
|
87
|
+
end
|
88
|
+
it "fails if first response has more total results" do
|
89
|
+
lambda {
|
90
|
+
@solr_resp_3_docs.should have_fewer_results_than(@solr_resp_1_doc)
|
91
|
+
}.should fail_matching('expected more than 3 documents in Solr response {')
|
92
|
+
lambda {
|
93
|
+
@solr_resp_not3_docs.should have_fewer_results_than(@solr_resp_3_docs)
|
94
|
+
}.should fail_matching('expected more than 8 documents in Solr response {')
|
95
|
+
lambda {
|
96
|
+
@solr_resp_not3_docs.should have_fewer_results_than(@solr_resp_no_docs)
|
97
|
+
}.should fail_matching('expected more than 8 documents in Solr response {')
|
98
|
+
end
|
99
|
+
end # should have_fewer_results_than()
|
100
|
+
|
101
|
+
context "should_NOT have_fewer_results_than()" do
|
102
|
+
it "fails if first response has no results and second doc has results" do
|
103
|
+
lambda {
|
104
|
+
@solr_resp_no_docs.should_not have_fewer_results_than(@solr_resp_1_doc)
|
105
|
+
}.should fail_matching('expected 0 or fewer documents in Solr response {')
|
106
|
+
lambda {
|
107
|
+
@solr_resp_no_docs.should_not have_fewer_results_than(@solr_resp_many_docs)
|
108
|
+
}.should fail_matching('expected 0 or fewer documents in Solr response {')
|
109
|
+
end
|
110
|
+
it "fails if first response has a smaller number of total results" do
|
111
|
+
lambda {
|
112
|
+
@solr_resp_1_doc.should_not have_fewer_results_than(@solr_resp_3_docs)
|
113
|
+
}.should fail_matching('expected 1 or fewer documents in Solr response {')
|
114
|
+
lambda {
|
115
|
+
@solr_resp_3_docs.should_not have_fewer_results_than(@solr_resp_not3_docs)
|
116
|
+
}.should fail_matching('expected 3 or fewer documents in Solr response {')
|
117
|
+
lambda {
|
118
|
+
@solr_resp_3_docs.should_not have_fewer_results_than(@solr_resp_many_docs)
|
119
|
+
}.should fail_matching('expected 3 or fewer documents in Solr response {')
|
120
|
+
end
|
121
|
+
it "passes if responses have same number of total results" do
|
122
|
+
@solr_resp_3_docs.should_not have_fewer_results_than(@solr_resp_3_docs)
|
123
|
+
@solr_resp_many_docs.should_not have_fewer_results_than(@solr_resp_many_docs2)
|
124
|
+
@solr_resp_no_docs.should_not have_fewer_results_than(@solr_resp_no_docs)
|
125
|
+
end
|
126
|
+
it "passes if first response has more total results" do
|
127
|
+
@solr_resp_3_docs.should_not have_fewer_results_than(@solr_resp_1_doc)
|
128
|
+
@solr_resp_not3_docs.should_not have_fewer_results_than(@solr_resp_3_docs)
|
129
|
+
@solr_resp_not3_docs.should_not have_fewer_results_than(@solr_resp_no_docs)
|
130
|
+
end
|
131
|
+
end # should_NOT have_fewer_results_than()
|
132
|
+
|
133
|
+
|
134
|
+
context "should have_more_results_than()" do
|
135
|
+
it "passes if first response has results and second response does not" do
|
136
|
+
@solr_resp_1_doc.should have_more_results_than(@solr_resp_no_docs)
|
137
|
+
@solr_resp_many_docs.should have_more_results_than(@solr_resp_no_docs)
|
138
|
+
end
|
139
|
+
it "passes if first response has a larger number of total results" do
|
140
|
+
@solr_resp_3_docs.should have_more_results_than(@solr_resp_1_doc)
|
141
|
+
@solr_resp_not3_docs.should have_more_results_than(@solr_resp_3_docs)
|
142
|
+
@solr_resp_many_docs.should have_more_results_than(@solr_resp_not3_docs)
|
143
|
+
end
|
144
|
+
it "fails if responses have same number of total results" do
|
145
|
+
lambda {
|
146
|
+
@solr_resp_3_docs.should have_more_results_than(@solr_resp_3_docs)
|
147
|
+
}.should fail_matching('expected fewer than 3 documents in Solr response {')
|
148
|
+
lambda {
|
149
|
+
@solr_resp_many_docs.should have_more_results_than(@solr_resp_many_docs2)
|
150
|
+
}.should fail_matching('expected fewer than 1019 documents in Solr response {')
|
151
|
+
lambda {
|
152
|
+
@solr_resp_no_docs.should have_more_results_than(@solr_resp_no_docs)
|
153
|
+
}.should fail_matching('expected fewer than 0 documents in Solr response {')
|
154
|
+
end
|
155
|
+
it "fails if first response has fewer total results" do
|
156
|
+
lambda {
|
157
|
+
@solr_resp_1_doc.should have_more_results_than(@solr_resp_3_docs)
|
158
|
+
}.should fail_matching('expected fewer than 1 documents in Solr response {')
|
159
|
+
lambda {
|
160
|
+
@solr_resp_3_docs.should have_more_results_than(@solr_resp_not3_docs)
|
161
|
+
}.should fail_matching('expected fewer than 3 documents in Solr response {')
|
162
|
+
lambda {
|
163
|
+
@solr_resp_3_docs.should have_more_results_than(@solr_resp_many_docs)
|
164
|
+
}.should fail_matching('expected fewer than 3 documents in Solr response {')
|
165
|
+
end
|
166
|
+
end # should have_more_results_than()
|
167
|
+
|
168
|
+
context "should_NOT have_more_results_than()" do
|
169
|
+
it "fails if first response has results and second response does not" do
|
170
|
+
lambda {
|
171
|
+
@solr_resp_1_doc.should_not have_more_results_than(@solr_resp_no_docs)
|
172
|
+
}.should fail_matching('expected 1 or more documents in Solr response {')
|
173
|
+
lambda {
|
174
|
+
@solr_resp_many_docs.should_not have_more_results_than(@solr_resp_no_docs)
|
175
|
+
}.should fail_matching('expected 1019 or more documents in Solr response {')
|
176
|
+
end
|
177
|
+
it "fails if first response has a larger number of total results" do
|
178
|
+
lambda {
|
179
|
+
@solr_resp_3_docs.should_not have_more_results_than(@solr_resp_1_doc)
|
180
|
+
}.should fail_matching('expected 3 or more documents in Solr response {')
|
181
|
+
lambda {
|
182
|
+
@solr_resp_not3_docs.should_not have_more_results_than(@solr_resp_3_docs)
|
183
|
+
}.should fail_matching('expected 8 or more documents in Solr response {')
|
184
|
+
lambda {
|
185
|
+
@solr_resp_many_docs.should_not have_more_results_than(@solr_resp_not3_docs)
|
186
|
+
}.should fail_matching('expected 1019 or more documents in Solr response {')
|
187
|
+
end
|
188
|
+
it "passes if responses have same number of total results" do
|
189
|
+
@solr_resp_3_docs.should_not have_more_results_than(@solr_resp_3_docs)
|
190
|
+
@solr_resp_many_docs.should_not have_more_results_than(@solr_resp_many_docs2)
|
191
|
+
@solr_resp_no_docs.should_not have_more_results_than(@solr_resp_no_docs)
|
192
|
+
end
|
193
|
+
it "passes if first response has fewer total results" do
|
194
|
+
@solr_resp_1_doc.should_not have_more_results_than(@solr_resp_3_docs)
|
195
|
+
@solr_resp_3_docs.should_not have_more_results_than(@solr_resp_not3_docs)
|
196
|
+
@solr_resp_3_docs.should_not have_more_results_than(@solr_resp_many_docs)
|
197
|
+
end
|
198
|
+
end # should_NOT have_more_results_than()
|
199
|
+
|
200
|
+
|
201
|
+
context "the word documents should be interchangeable with results" do
|
202
|
+
it "have_the_same_number_of_documents_as" do
|
203
|
+
@solr_resp_1_doc.should have_the_same_number_of_documents_as(@solr_resp_1_doc)
|
204
|
+
@solr_resp_not3_docs.should_not have_the_same_number_of_documents_as(@solr_resp_3_docs)
|
205
|
+
end
|
206
|
+
it "have_fewer_results_than" do
|
207
|
+
@solr_resp_3_docs.should have_fewer_results_than(@solr_resp_not3_docs)
|
208
|
+
@solr_resp_many_docs.should_not have_fewer_results_than(@solr_resp_many_docs2)
|
209
|
+
end
|
210
|
+
it "have_more_results_than" do
|
211
|
+
@solr_resp_not3_docs.should have_more_results_than(@solr_resp_3_docs)
|
212
|
+
@solr_resp_1_doc.should_not have_more_documents_than(@solr_resp_3_docs)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
before(:all) do
|
218
|
+
@solr_resp_1_doc = RSpecSolr::SolrResponseHash.new({ "response" =>
|
219
|
+
{ "numFound" => 1,
|
220
|
+
"start" => 0,
|
221
|
+
"docs" => [ {"id"=>"111"} ]
|
222
|
+
}
|
223
|
+
})
|
224
|
+
|
225
|
+
@solr_resp_3_docs = RSpecSolr::SolrResponseHash.new({ "response" =>
|
226
|
+
{ "numFound" => 3,
|
227
|
+
"start" => 0,
|
228
|
+
"docs" =>
|
229
|
+
[ {"id"=>"111"},
|
230
|
+
{"id"=>"222"},
|
231
|
+
{"id"=>"333"},
|
232
|
+
]
|
233
|
+
}
|
234
|
+
})
|
235
|
+
|
236
|
+
@solr_resp_not3_docs = RSpecSolr::SolrResponseHash.new({ "response" =>
|
237
|
+
{ "numFound" => 8,
|
238
|
+
"start" => 0,
|
239
|
+
"docs" =>
|
240
|
+
[ {"id"=>"111"},
|
241
|
+
{"id"=>"222"},
|
242
|
+
{"id"=>"333"},
|
243
|
+
]
|
244
|
+
}
|
245
|
+
})
|
246
|
+
|
247
|
+
@solr_resp_many_docs = RSpecSolr::SolrResponseHash.new({ "response" =>
|
248
|
+
{ "numFound" => 1019,
|
249
|
+
"start" => 0,
|
250
|
+
"docs" =>
|
251
|
+
[ {"id"=>"111"},
|
252
|
+
{"id"=>"222"},
|
253
|
+
{"id"=>"333"},
|
254
|
+
]
|
255
|
+
}
|
256
|
+
})
|
257
|
+
|
258
|
+
@solr_resp_many_docs2 = RSpecSolr::SolrResponseHash.new({ "response" =>
|
259
|
+
{ "numFound" => 1019,
|
260
|
+
"start" => 10,
|
261
|
+
"docs" =>
|
262
|
+
[ {"id"=>"777"},
|
263
|
+
{"id"=>"888"},
|
264
|
+
{"id"=>"999"},
|
265
|
+
]
|
266
|
+
}
|
267
|
+
})
|
268
|
+
|
269
|
+
@solr_resp_no_docs = RSpecSolr::SolrResponseHash.new({ "response" =>
|
270
|
+
{ "numFound" => 0,
|
271
|
+
"start" => 0,
|
272
|
+
"docs" => []
|
273
|
+
}
|
274
|
+
})
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-solr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- Rakefile
|
145
145
|
- expectation_matchers.rdoc
|
146
146
|
- lib/rspec-solr.rb
|
147
|
+
- lib/rspec-solr/compare_num_docs_matcher.rb
|
147
148
|
- lib/rspec-solr/have_documents_matcher.rb
|
148
149
|
- lib/rspec-solr/include_documents_matcher.rb
|
149
150
|
- lib/rspec-solr/solr_response_hash.rb
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- lib/tasks/doc.rake
|
153
154
|
- lib/tasks/spec.rake
|
154
155
|
- rspec-solr.gemspec
|
156
|
+
- spec/comparing_num_docs_in_2_resp_spec.rb
|
155
157
|
- spec/have_documents_spec.rb
|
156
158
|
- spec/include_before_spec.rb
|
157
159
|
- spec/include_document_spec.rb
|
@@ -174,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
176
|
version: '0'
|
175
177
|
segments:
|
176
178
|
- 0
|
177
|
-
hash:
|
179
|
+
hash: -4321084972605956257
|
178
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
181
|
none: false
|
180
182
|
requirements:
|
@@ -183,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
185
|
version: '0'
|
184
186
|
segments:
|
185
187
|
- 0
|
186
|
-
hash:
|
188
|
+
hash: -4321084972605956257
|
187
189
|
requirements: []
|
188
190
|
rubyforge_project:
|
189
191
|
rubygems_version: 1.8.24
|
@@ -191,6 +193,7 @@ signing_key:
|
|
191
193
|
specification_version: 3
|
192
194
|
summary: RSpec custom matchers for Solr response objects
|
193
195
|
test_files:
|
196
|
+
- spec/comparing_num_docs_in_2_resp_spec.rb
|
194
197
|
- spec/have_documents_spec.rb
|
195
198
|
- spec/include_before_spec.rb
|
196
199
|
- spec/include_document_spec.rb
|