Skip to content

Commit

Permalink
Merge pull request #80 from adamjonas/master
Browse files Browse the repository at this point in the history
increment rspec version and change syntax from should to expect with transpec
  • Loading branch information
mwmitchell committed Jun 1, 2014
2 parents 04f3526 + 95f7661 commit c89ec40
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -11,7 +11,7 @@ end

group :test do
gem "rake", ">= 0.9.2"
gem "rspec", "~> 2.6"
gem "rspec", "~> 2.14"
end

if defined? RUBY_VERSION and RUBY_VERSION < "1.9"
Expand Down
4 changes: 2 additions & 2 deletions spec/api/char_spec.rb
Expand Up @@ -8,9 +8,9 @@
chr = ascii.chr
esc = char.escape(chr)
if chr =~ /\W/
esc.to_s.should == "\\#{chr}"
expect(esc.to_s).to eq("\\#{chr}")
else
esc.to_s.should == chr
expect(esc.to_s).to eq(chr)
end
end
end
Expand Down
72 changes: 36 additions & 36 deletions spec/api/client_spec.rb
Expand Up @@ -12,23 +12,23 @@ def client

context "initialize" do
it "should accept whatevs and set it as the @connection" do
RSolr::Client.new(:whatevs).connection.should == :whatevs
expect(RSolr::Client.new(:whatevs).connection).to eq(:whatevs)
end
end

context "send_and_receive" do
include ClientHelper
it "should forward these method calls the #connection object" do
[:get, :post, :head].each do |meth|
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
and_return({:status => 200, :body => "{}", :headers => {}})
client.send_and_receive '', :method => meth, :params => {}, :data => nil, :headers => {}
end
end

it "should be timeout aware" do
[:get, :post, :head].each do |meth|
client.connection.should_receive(:execute).with(client, hash_including(:read_timeout => 42, :open_timeout=>43))
expect(client.connection).to receive(:execute).with(client, hash_including(:read_timeout => 42, :open_timeout=>43))
client.send_and_receive '', :method => meth, :params => {}, :data => nil, :headers => {}
end
end
Expand All @@ -48,29 +48,29 @@ def client
}
end
it "should retry 503s if requested" do
client.connection.should_receive(:execute).exactly(2).times.and_return(
expect(client.connection).to receive(:execute).exactly(2).times.and_return(
{:status => 503, :body => "{}", :headers => {'Retry-After' => 0}},
{:status => 200, :body => "{}", :headers => {}}
)
client.execute request_context
end
it "should not retry a 503 if the retry-after is too large" do
client.connection.should_receive(:execute).exactly(1).times.and_return(
expect(client.connection).to receive(:execute).exactly(1).times.and_return(
{:status => 503, :body => "{}", :headers => {'Retry-After' => 10}}
)
lambda {
expect {
Timeout.timeout(0.5) do
client.execute({:retry_after_limit => 0}.merge(request_context))
end
}.should raise_error(RSolr::Error::Http)
}.to raise_error(RSolr::Error::Http)
end
end

context "post" do
include ClientHelper
it "should pass the expected params to the connection's #execute method" do
request_opts = {:data => "the data", :method=>:post, :headers => {"Content-Type" => "text/plain"}}
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
with(client, hash_including(request_opts)).
and_return(
:body => "",
Expand All @@ -84,14 +84,14 @@ def client
context "xml" do
include ClientHelper
it "should return an instance of RSolr::Xml::Generator" do
client.xml.should be_a RSolr::Xml::Generator
expect(client.xml).to be_a RSolr::Xml::Generator
end
end

context "add" do
include ClientHelper
it "should send xml to the connection's #post method" do
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
with(
client, hash_including({
:path => "update",
Expand All @@ -105,7 +105,7 @@ def client
:status => 200,
:headers => {"Content-Type"=>"text/xml"}
)
client.xml.should_receive(:add).
expect(client.xml).to receive(:add).
with({:id=>1}, {:commitWith=>10}).
and_return("<xml/>")
client.add({:id=>1}, :add_attributes => {:commitWith=>10})
Expand All @@ -115,7 +115,7 @@ def client
context "update" do
include ClientHelper
it "should send data to the connection's #post method" do
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
with(
client, hash_including({
:path => "update",
Expand All @@ -137,7 +137,7 @@ def client
include ClientHelper
[:commit, :optimize, :rollback].each do |meth|
it "should send a #{meth} message to the connection's #post method" do
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
with(
client, hash_including({
:path => "update",
Expand All @@ -159,7 +159,7 @@ def client
context "delete_by_id" do
include ClientHelper
it "should send data to the connection's #post method" do
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
with(
client, hash_including({
:path => "update",
Expand All @@ -180,7 +180,7 @@ def client
context "delete_by_query" do
include ClientHelper
it "should send data to the connection's #post method" do
client.connection.should_receive(:execute).
expect(client.connection).to receive(:execute).
with(
client, hash_including({
:path => "update",
Expand All @@ -203,30 +203,30 @@ def client
it 'should not try to evaluate ruby when the :qt is not :ruby' do
body = '{:time=>"NOW"}'
result = client.adapt_response({:params=>{}}, {:status => 200, :body => body, :headers => {}})
result.should == body
expect(result).to eq(body)
end

it 'should evaluate ruby responses when the :wt is :ruby' do
body = '{:time=>"NOW"}'
result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
result.should == {:time=>"NOW"}
expect(result).to eq({:time=>"NOW"})
end

it 'should evaluate json responses when the :wt is :json' do
body = '{"time": "NOW"}'
result = client.adapt_response({:params=>{:wt=>:json}}, {:status => 200, :body => body, :headers => {}})
if defined? JSON
result.should == {:time=>"NOW"}
expect(result).to eq({:time=>"NOW"})
else
# ruby 1.8 without the JSON gem
result.should == '{"time": "NOW"}'
expect(result).to eq('{"time": "NOW"}')
end
end

it "ought raise a RSolr::Error::InvalidRubyResponse when the ruby is indeed frugged, or even fruggified" do
lambda {
expect {
client.adapt_response({:params=>{:wt => :ruby}}, {:status => 200, :body => "<woops/>", :headers => {}})
}.should raise_error RSolr::Error::InvalidRubyResponse
}.to raise_error RSolr::Error::InvalidRubyResponse
end

end
Expand All @@ -235,10 +235,10 @@ def client
include ClientHelper
it "should raise a NoMethodError if the #with_indifferent_access extension isn't loaded" do
# TODO: Find a less implmentation-tied way to test this
Hash.any_instance.should_receive(:respond_to?).with(:with_indifferent_access).and_return(false)
expect_any_instance_of(Hash).to receive(:respond_to?).with(:with_indifferent_access).and_return(false)
body = "{'foo'=>'bar'}"
result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
lambda { result.with_indifferent_access }.should raise_error NoMethodError
expect { result.with_indifferent_access }.to raise_error NoMethodError
end

it "should provide indifferent access" do
Expand All @@ -247,13 +247,13 @@ def client
result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
indifferent_result = result.with_indifferent_access

result.should be_a(RSolr::Response)
result['foo'].should == 'bar'
result[:foo].should be_nil
expect(result).to be_a(RSolr::Response)
expect(result['foo']).to eq('bar')
expect(result[:foo]).to be_nil

indifferent_result.should be_a(RSolr::Response)
indifferent_result['foo'].should == 'bar'
indifferent_result[:foo].should == 'bar'
expect(indifferent_result).to be_a(RSolr::Response)
expect(indifferent_result['foo']).to eq('bar')
expect(indifferent_result[:foo]).to eq('bar')
end
end

Expand All @@ -267,10 +267,10 @@ def client
:headers => {}
)
[/fq=0/, /fq=1/, /q=test/, /wt=ruby/].each do |pattern|
result[:query].should match pattern
expect(result[:query]).to match pattern
end
result[:data].should == "data"
result[:headers].should == {}
expect(result[:data]).to eq("data")
expect(result[:headers]).to eq({})
end

it "should set the Content-Type header to application/x-www-form-urlencoded; charset=UTF-8 if a hash is passed in to the data arg" do
Expand All @@ -279,12 +279,12 @@ def client
:data => {:q=>'test', :fq=>[0,1]},
:headers => {}
)
result[:query].should == "wt=ruby"
expect(result[:query]).to eq("wt=ruby")
[/fq=0/, /fq=1/, /q=test/].each do |pattern|
result[:data].should match pattern
expect(result[:data]).to match pattern
end
result[:data].should_not match /wt=ruby/
result[:headers].should == {"Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8"}
expect(result[:data]).not_to match /wt=ruby/
expect(result[:headers]).to eq({"Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8"})
end

end
Expand Down
26 changes: 13 additions & 13 deletions spec/api/connection_spec.rb
Expand Up @@ -22,16 +22,16 @@
subject { RSolr::Connection.new }

before do
Net::HTTP.stub(:new) { http }
allow(Net::HTTP).to receive(:new) { http }
end

it "should configure Net:HTTP read_timeout" do
http.should_receive(:read_timeout=).with(42)
expect(http).to receive(:read_timeout=).with(42)
subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :read_timeout => 42}
end

it "should use Net:HTTP default read_timeout if not specified" do
http.should_not_receive(:read_timeout=)
expect(http).not_to receive(:read_timeout=)
subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
end
end
Expand All @@ -44,16 +44,16 @@
subject { RSolr::Connection.new }

before do
Net::HTTP.stub(:new) { http }
allow(Net::HTTP).to receive(:new) { http }
end

it "should configure Net:HTTP open_timeout" do
http.should_receive(:open_timeout=).with(42)
expect(http).to receive(:open_timeout=).with(42)
subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
end

it "should use Net:HTTP default open_timeout if not specified" do
http.should_not_receive(:open_timeout=)
expect(http).not_to receive(:open_timeout=)
subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
end
end
Expand All @@ -68,28 +68,28 @@
subject { RSolr::Connection.new }

before do
Net::HTTP.stub(:new) { http }
allow(Net::HTTP).to receive(:new) { http }
end

it "should configure Net:HTTP open_timeout" do
pending "doesn't work with ruby 1.8" if RUBY_VERSION < "1.9"
http.should_receive(:request).and_raise(Errno::ECONNREFUSED)
lambda {
expect(http).to receive(:request).and_raise(Errno::ECONNREFUSED)
expect {
subject.execute client, request_context
}.should raise_error(Errno::ECONNREFUSED, /#{request_context}/)
}.to raise_error(Errno::ECONNREFUSED, /#{request_context}/)
end
end

describe "basic auth support" do
let(:http) { double(Net::HTTP).as_null_object }

before do
Net::HTTP.stub(:new) { http }
allow(Net::HTTP).to receive(:new) { http }
end

it "sets the authorization header" do
http.should_receive(:request) do |request|
request.fetch('authorization').should == "Basic #{Base64.encode64("joe:pass")}".strip
expect(http).to receive(:request) do |request|
expect(request.fetch('authorization')).to eq("Basic #{Base64.encode64("joe:pass")}".strip)
double(Net::HTTPResponse).as_null_object
end
RSolr::Connection.new.execute nil, :uri => URI.parse("http://joe:pass@localhost:8983/solr"), :method => :get
Expand Down
8 changes: 4 additions & 4 deletions spec/api/error_spec.rb
Expand Up @@ -19,14 +19,14 @@ def generate_error_with_backtrace(request, response)

it "only shows the first eleven lines of the response" do
error = generate_error_with_backtrace @request, @response
error.to_s.should match(/line 1\n.+line 11\n\n/m)
expect(error.to_s).to match(/line 1\n.+line 11\n\n/m)
end

it "shows only one line when the response is one line long" do
@response[:body] = "<pre>failed</pre>"

error = generate_error_with_backtrace @request, @response
error.to_s.should match(/Error: failed/)
expect(error.to_s).to match(/Error: failed/)
end
end

Expand All @@ -43,14 +43,14 @@ def generate_error_with_backtrace(request, response)

it "only shows the first eleven lines of the response" do
error = generate_error_with_backtrace @request, @response
error.to_s.should match(/line 1\n.+line 11\n\n/m)
expect(error.to_s).to match(/line 1\n.+line 11\n\n/m)
end

it "shows only one line when the response is one line long" do
@response[:body] = "failed"

error = generate_error_with_backtrace @request, @response
error.to_s.should match(/Error: failed/)
expect(error.to_s).to match(/Error: failed/)
end
end
end
10 changes: 5 additions & 5 deletions spec/api/pagination_spec.rb
Expand Up @@ -6,16 +6,16 @@
r = c.build_paginated_request 3, 25, "select", {:params => {:q => "test"}}
#r[:page].should == 3
#r[:per_page].should == 25
r[:params]["start"].should == 50
r[:params]["rows"].should == 25
r[:uri].query.should =~ /rows=25/
r[:uri].query.should =~ /start=50/
expect(r[:params]["start"]).to eq(50)
expect(r[:params]["rows"]).to eq(25)
expect(r[:uri].query).to match(/rows=25/)
expect(r[:uri].query).to match(/start=50/)
end
end
context "paginate" do
it "should build a paginated request context and call execute" do
c = RSolr::Client.new(nil, {})#.extend(RSolr::Pagination::Client)
c.should_receive(:execute).with(hash_including({
expect(c).to receive(:execute).with(hash_including({
#:page => 1,
#:per_page => 10,
:params => {
Expand Down
8 changes: 4 additions & 4 deletions spec/api/rsolr_spec.rb
Expand Up @@ -2,17 +2,17 @@
describe "RSolr" do

it "has a version that can be read via #version or VERSION" do
RSolr.version.should == RSolr::VERSION
expect(RSolr.version).to eq(RSolr::VERSION)
end

it "can escape" do
RSolr.should be_a(RSolr::Char)
RSolr.escape("this string").should == "this\\ string"
expect(RSolr).to be_a(RSolr::Char)
expect(RSolr.escape("this string")).to eq("this\\ string")
end

context "connect" do
it "should return a RSolr::Client instance" do
RSolr.connect.should be_a(RSolr::Client)
expect(RSolr.connect).to be_a(RSolr::Client)
end
end

Expand Down

0 comments on commit c89ec40

Please sign in to comment.