Permalink
Browse files

Don't needlessly leave File objects around, just read them directly.

  • Loading branch information...
1 parent acb998b commit 46075be806b1c87b0c95224cb65e0fced2398717 @benpickles committed Nov 11, 2013
@@ -48,7 +48,7 @@
end
let(:file) { File.new(__FILE__) }
- let(:file_contents) { File.new(__FILE__).read }
+ let(:file_contents) { File.read(__FILE__) }
it 'handles file uploads correctly' do
stub_request(:put, "http://example.com/upload").with(:body => file_contents)
@@ -92,13 +92,13 @@ class MyException < StandardError; end;
describe "when response body was declared as IO" do
it "should return response body" do
stub_request(:get, "www.example.com").to_return(:body => File.new(__FILE__))
- http_request(:get, "http://www.example.com/").body.should == File.new(__FILE__).read
+ http_request(:get, "http://www.example.com/").body.should == File.read(__FILE__)
end
it "should return response body if requested many times" do
stub_request(:get, "www.example.com").to_return(:body => File.new(__FILE__))
2.times do
- http_request(:get, "http://www.example.com/").body.should == File.new(__FILE__).read
+ http_request(:get, "http://www.example.com/").body.should == File.read(__FILE__)
end
end
@@ -199,7 +199,7 @@ def call(request)
describe "when response was declared as a string with a raw response" do
before(:each) do
- @input = File.new(CURL_EXAMPLE_OUTPUT_PATH).read
+ @input = File.read(CURL_EXAMPLE_OUTPUT_PATH)
stub_request(:get, "www.example.com").to_return(@input)
@response = http_request(:get, "http://www.example.com/")
end
@@ -111,13 +111,13 @@
it "should report content of a IO object if provided" do
@response = WebMock::Response.new(:body => File.new(__FILE__))
- @response.body.should == File.new(__FILE__).read
+ @response.body.should == File.read(__FILE__)
end
it "should report many times content of a IO object if provided" do
@response = WebMock::Response.new(:body => File.new(__FILE__))
- @response.body.should == File.new(__FILE__).read
- @response.body.should == File.new(__FILE__).read
+ @response.body.should == File.read(__FILE__)
+ @response.body.should == File.read(__FILE__)
end
end
@@ -157,7 +157,7 @@
describe "when input is String" do
before(:each) do
- @input = File.new(CURL_EXAMPLE_OUTPUT_PATH).read
+ @input = File.read(CURL_EXAMPLE_OUTPUT_PATH)
@response = WebMock::Response.new(@input)
end

0 comments on commit 46075be

Please sign in to comment.