Skip to content

Commit

Permalink
Rename deprecated mock and stub rspec methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkirb committed Oct 29, 2013
1 parent dddfaac commit 962f5bc
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 110 deletions.
18 changes: 9 additions & 9 deletions spec/support/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def build_ok_response(body = '', headers = {})
end

def build_response(code,message = '', body = '', headers = {})
mock(Net::HTTPOK).tap do |response|
response.stub!(:code).and_return(code)
response.stub!(:message).and_return(message)
response.stub!(:body).and_return(body)
response.stub!(:http_version).and_return("1.1")
response.stub!(:to_hash).and_return(headers)
response.stub!('[]').and_return(nil)
double(Net::HTTPOK).tap do |response|
response.stub(:code).and_return(code)
response.stub(:message).and_return(message)
response.stub(:body).and_return(body)
response.stub(:http_version).and_return("1.1")
response.stub(:to_hash).and_return(headers)
response.stub('[]').and_return(nil)
headers.each{|k,v|
response.stub!('[]').with(k).and_return(v)
response.stub('[]').with(k).and_return(v)
}
end
end
Expand All @@ -38,4 +38,4 @@ def cacheable_headers
headers = {"date" => Time.now.httpdate, "expires" => half_hour_after, "age" => "0", "last-modified" => ten_mins_early}
headers
end
end
end
2 changes: 1 addition & 1 deletion spec/wrest/async_request/event_machine_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Wrest::AsyncRequest
hash = {}
uri = "http://localhost:3000".to_uri
request = Wrest::Native::Get.new(uri,{},{},:callback => Wrest::Callback.new({200 => lambda{|response| hash["success"] = true}}))
response_200 = mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {})
response_200 = double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {})
request.should_receive(:do_request).and_return(response_200)

async_obj = EventMachineBackend.new
Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/async_request/thread_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Wrest::AsyncRequest
hash = {}
uri = "http://localhost:3000".to_uri
request = Wrest::Native::Get.new(uri,{},{},:callback => Wrest::Callback.new({200 => lambda{|response| hash["success"] = true}}))
response_200 = mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {})
response_200 = double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {})
request.should_receive(:do_request).and_return(response_200)

async_obj = ThreadBackend.new
Expand Down
4 changes: 2 additions & 2 deletions spec/wrest/cache_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@request_uri = 'http://localhost/foo'.to_uri
@get = Wrest::Native::Get.new(@request_uri, {}, {}, {:cache_store => @cache})
@ok_response = Wrest::Native::Response.new(build_ok_response('', cacheable_headers()))
@get.stub!(:invoke_without_cache_check).and_return(@ok_response)
@get.stub(:invoke_without_cache_check).and_return(@ok_response)
@cache_proxy = @get.cache_proxy
end

Expand Down Expand Up @@ -225,4 +225,4 @@
@cache_proxy.get
end
end
end
end
4 changes: 2 additions & 2 deletions spec/wrest/callback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Wrest
describe Callback do
let(:response_200){mock(Net::HTTPOK, :code => 200, :message => "OK", :body => '', :to_hash => {})}
let(:response_200){double(Net::HTTPOK, :code => 200, :message => "OK", :body => '', :to_hash => {})}
context "new" do
context "ensure_values_are_collections" do
it "should return a hash whose values are collections given a hash with values that are not collections" do
Expand Down Expand Up @@ -130,7 +130,7 @@ module Wrest
block_executed = false
code = 200..206
callback = Callback.new(code => lambda{|response| block_executed = true})
response_301 = mock(Net::HTTPOK, :code => 301, :message => "moved permanenlty", :body => '', :to_hash => {})
response_301 = double(Net::HTTPOK, :code => 301, :message => "moved permanenlty", :body => '', :to_hash => {})
callback.execute(response_301)
block_executed.should be_false
end
Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/components/mutators/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Wrest::Components
end

it "should ensure that the next mutator is invoked for a subclass" do
next_mutator = mock('Mutator')
next_mutator = double('Mutator')
mutator = Mutators::CamelToSnakeCase.new(next_mutator)

next_mutator.should_receive(:mutate).with(['a', 1]).and_return([:a, '1'])
Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/components/translators/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Wrest::Components::Translators
describe Json do
let(:http_response) { mock('Http Reponse') }
let(:http_response) { double('Http Reponse') }

it "should know how to convert json to a hashmap" do
http_response.should_receive(:body).and_return("{
Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/components/translators/txt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Wrest::Components::Translators
describe Txt do
let(:http_response) { mock('Http Reponse') }
let(:http_response) { double('Http Reponse') }
it "should return response body when deserialise" do
http_response.should_receive(:body).and_return("Homebrew is the easiest.")

Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/components/translators/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Wrest::Components::Translators
describe Xml do
let(:http_response) { mock('Http Reponse') }
let(:http_response) { double('Http Reponse') }
it "should know how to convert xml to a hashmap" do
http_response.should_receive(:body).and_return("<ooga><age>12</age></ooga>")

Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/curl/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ module Wrest
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/wrest/curl/put_multipart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ module Wrest
end
end
end
end
end
16 changes: 8 additions & 8 deletions spec/wrest/curl/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ module Wrest
describe Curl::Response do
context 'Aliased methods' do
it "has #deserialize delegate to #deserialise" do
response = Wrest::Curl::Response.new(mock('Response', :headers => {'Content-type' => 'text/xml;charset=utf-8'}))
response = Wrest::Curl::Response.new(double('Response', :headers => {'Content-type' => 'text/xml;charset=utf-8'}))

response.should_receive(:deserialise)
response.deserialize
end

it "has #deserialize_using delegate to #deserialise_using" do
response = Wrest::Curl::Response.new(mock('Response', :headers => {'Content-type' => 'text/xml;charset=utf-8'}))
response = Wrest::Curl::Response.new(double('Response', :headers => {'Content-type' => 'text/xml;charset=utf-8'}))

response.should_receive(:deserialise_using)
response.deserialize_using
Expand All @@ -21,16 +21,16 @@ module Wrest

describe 'Headers' do
it "should know how to retrieve content type irrespective of the casing" do
http_response = mock('Patron::Response')
http_response.stub!(:headers).and_return({'Content-type' => 'text/xml;charset=utf-8'})
http_response = double('Patron::Response')
http_response.stub(:headers).and_return({'Content-type' => 'text/xml;charset=utf-8'})
response = Wrest::Curl::Response.new(http_response)
response.content_type.should == 'text/xml'
end
end

it "should know how to deserialise json responses" do
http_response = mock('response')
http_response.stub!(:code).and_return('200')
http_response = double('response')
http_response.stub(:code).and_return('200')
http_response.should_receive(:body).and_return(<<-EOJS
{
"menu": "File",
Expand All @@ -55,8 +55,8 @@ module Wrest

describe "cache deserialised body" do
it "should return the catched deserialised body when deserialise is called more than once" do
http_response = mock('curl response')
http_response.stub!(:headers).and_return({'Content-type' => 'text/xml;charset=utf-8'})
http_response = double('curl response')
http_response.stub(:headers).and_return({'Content-type' => 'text/xml;charset=utf-8'})

response = Wrest::Curl::Response.new(http_response)

Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/hash_with_case_insensitive_access_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ module Wrest
end
end

end
end
8 changes: 4 additions & 4 deletions spec/wrest/http/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module Wrest
describe 'Response' do
describe 'Headers' do
it "should know how to retrieve content type irrespective of the casing" do
http_response = mock('Response')
http_response.stub!(:headers).and_return({'Content-type' => 'application/xml'})
http_response.stub!(:code).and_return('200')
http_response.stub!(:content_type).and_return('application/xml')
http_response = double('Response')
http_response.stub(:headers).and_return({'Content-type' => 'application/xml'})
http_response.stub(:code).and_return('200')
http_response.stub(:content_type).and_return('application/xml')

response = library::Response.new(http_response)
response.content_type.should == 'application/xml'
Expand Down
16 changes: 8 additions & 8 deletions spec/wrest/http_codes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ module Wrest
it "should know if the response code is HTTP #{status_message} for #{klass} object" do
code = status
method = (status_message.split.join('_').downcase + "?").to_sym
net_response = mock(mock_class)
net_response.stub!(:code).and_return(code)
net_response.stub!(:headers).and_return({})
net_response.stub!(:status).and_return(code)
net_response = double(mock_class)
net_response.stub(:code).and_return(code)
net_response.stub(:headers).and_return({})
net_response.stub(:status).and_return(code)
klass.constantize.send(:new, net_response).send(method).should be_true
end

it "should know if the response code is not HTTP #{status_message} for #{klass} object" do
code = (status.to_i + 1).to_s
method = (status_message.split.join('_').downcase + "?").to_sym
net_response = mock(mock_class)
net_response.stub!(:code).and_return(code)
net_response.stub!(:headers).and_return({})
net_response.stub!(:status).and_return(code)
net_response = double(mock_class)
net_response.stub(:code).and_return(code)
net_response.stub(:headers).and_return({})
net_response.stub(:status).and_return(code)
klass.constantize.send(:new, net_response).send(method).should be_false
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/wrest/native/redirection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Wrest::Native::Redirection do

it "should make a request to the url in its location header and return the response" do
mock_net_http_response = mock(Net::HTTPRedirection)
mock_net_http_response = double(Net::HTTPRedirection)
redirect_url = 'http://redirect.com'
redirect_uri = redirect_url.to_uri
mock_net_http_response.should_receive(:to_hash).and_return('location' => redirect_url)
Expand All @@ -12,7 +12,7 @@
Wrest::Uri.should_receive(:new).with(redirect_url, anything).and_return(redirect_uri)

after_redirect_request = Wrest::Native::Get.new(redirect_uri)
final_mock_response = mock(Wrest::Native::Response)
final_mock_response = double(Wrest::Native::Response)
after_redirect_request.should_receive(:invoke).and_return(final_mock_response)

Wrest::Native::Get.should_receive(:new).with(redirect_uri, {}, {}, {:username=>nil, :password=>nil}).and_return(after_redirect_request)
Expand All @@ -28,15 +28,15 @@

request_url = 'http://redirect.com'

response = mock(Net::HTTPRedirection)
response.stub!(:code).and_return('301')
response.stub!(:message).and_return('')
response.stub!(:body).and_return('')
response.stub!(:to_hash).and_return('location' => request_url)
response = double(Net::HTTPRedirection)
response.stub(:code).and_return('301')
response.stub(:message).and_return('')
response.stub(:body).and_return('')
response.stub(:to_hash).and_return('location' => request_url)

http_connection = mock(Net::HTTP)
http_connection.stub!(:read_timeout=)
http_connection.stub!(:set_debug_output)
http_connection = double(Net::HTTP)
http_connection.stub(:read_timeout=)
http_connection.stub(:set_debug_output)
http_connection.should_receive(:request).exactly(5).times.and_return(response)

Net::HTTP.should_receive(:new).exactly(5).times.and_return(http_connection)
Expand Down
40 changes: 20 additions & 20 deletions spec/wrest/native/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@
uri = 'http://localhost/foo'.to_uri
request = Wrest::Native::Get.new(uri)
redirect_location = 'http://coathangers.com'
redirected_request = mock('Request to http://coathangers.com')
redirected_request = double('Request to http://coathangers.com')

mock_connection = mock('Http Connection')
uri.stub!(:create_connection).and_return(mock_connection)
mock_connection = double('Http Connection')
uri.stub(:create_connection).and_return(mock_connection)

raw_response = mock(Net::HTTPRedirection)
raw_response.stub!(:code).and_return('301')
raw_response.stub!(:message).and_return('')
raw_response.stub!(:body).and_return('')
raw_response = double(Net::HTTPRedirection)
raw_response.stub(:code).and_return('301')
raw_response.stub(:message).and_return('')
raw_response.stub(:body).and_return('')

response = Wrest::Native::Redirection.new(raw_response)
response.stub!(:[]).with('location').and_return(redirect_location)
response.stub(:[]).with('location').and_return(redirect_location)

mock_connection.should_receive(:request).and_return(raw_response)
mock_connection.should_receive(:set_debug_output)

Wrest::Native::Response.should_receive(:new).and_return(response)
redirected_request.stub!(:get)
redirected_request.stub(:get)
Wrest::Uri.should_receive(:new).with(redirect_location, hash_including(:follow_redirects_count=>1)).and_return(redirected_request)

request.invoke
Expand All @@ -67,20 +67,20 @@
it "should not set basic authentication for request if either of username or password is nil" do
uri = 'http://localhost/foo'.to_uri
request = Wrest::Native::Get.new(uri)
http_request = mock(Net::HTTP::Get, :method => "GET", :hash => {})
http_request = double(Net::HTTP::Get, :method => "GET", :hash => {})
http_request.should_not_receive(:basic_auth)
request.should_receive(:http_request).any_number_of_times.and_return(http_request)
request.should_receive(:do_request).and_return(mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
request.should_receive(:do_request).and_return(double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
request.invoke
end

it "should set basic authentication for request" do
uri = 'http://localhost/foo'.to_uri
request = Wrest::Native::Get.new(uri, {}, {}, {:username => "name", :password => "password"})
http_request = mock(Net::HTTP::Get, :method => "GET", :hash => {})
http_request = double(Net::HTTP::Get, :method => "GET", :hash => {})
http_request.should_receive(:basic_auth).with('name', 'password')
request.should_receive(:http_request).any_number_of_times.and_return(http_request)
request.should_receive(:do_request).and_return(mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
request.should_receive(:do_request).and_return(double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
request.invoke
end

Expand All @@ -92,11 +92,11 @@

context "SSL options" do
let(:uri){ 'https://localhost/foo'.to_uri }
let(:http_request){ mock(Net::HTTP::Get, :method => "GET") }
let(:http_request){ double(Net::HTTP::Get, :method => "GET") }
def setup_request_expectations(request)
request.tap do |r|
request.should_receive(:http_request).any_number_of_times.and_return(http_request)
request.should_receive(:do_request).and_return(mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
request.should_receive(:do_request).and_return(double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
end
end

Expand Down Expand Up @@ -125,7 +125,7 @@ def setup_request_expectations(request)
it "should not store response in cache if the original request was not GET" do
cache = {}
post = Wrest::Native::Post.new("http://localhost".to_uri, {}, {}, cacheable_headers, {:cache_store => cache})
post.should_receive(:do_request).and_return(mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))
post.should_receive(:do_request).and_return(double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {}))

cache.should_not_receive(:[])
post.invoke
Expand All @@ -147,9 +147,9 @@ def setup_request_expectations(request)
uri = 'http://localhost/foo'.to_uri
request = Wrest::Native::Get.new(uri,{},{},:callback => response_handler)

response_204 = mock(Net::HTTPOK, :code => "204", :message => 'not OK', :body => '', :to_hash => {})
response_200 = mock(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {})
response_501 = mock(Net::HTTPOK, :code => "501", :message => 'not implemented', :body => '', :to_hash => {})
response_204 = double(Net::HTTPOK, :code => "204", :message => 'not OK', :body => '', :to_hash => {})
response_200 = double(Net::HTTPOK, :code => "200", :message => 'OK', :body => '', :to_hash => {})
response_501 = double(Net::HTTPOK, :code => "501", :message => 'not implemented', :body => '', :to_hash => {})

request.should_receive(:do_request).and_return(response_200, response_501, response_204)

Expand All @@ -165,7 +165,7 @@ def setup_request_expectations(request)
end

it "should correctly use the detailed_http_logging option" do
logger = mock(Logger)
logger = double(Logger)
logger.should_receive(:<<).at_least(:once).with {|detailed_log| detailed_log.include? "opening connection to"}
logger.should_receive(:<<).any_number_of_times

Expand Down
Loading

0 comments on commit 962f5bc

Please sign in to comment.