2008-10-21 15:27:35 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
2008-11-17 02:25:29 +00:00
|
|
|
|
|
|
|
require "webrat/merb"
|
2008-10-21 15:27:35 +00:00
|
|
|
|
2009-08-13 00:50:55 +00:00
|
|
|
describe Webrat::MerbAdapter do
|
2008-10-21 15:27:35 +00:00
|
|
|
it "should not pass empty params if data is and empty hash" do
|
2009-08-13 00:50:55 +00:00
|
|
|
session = Webrat::MerbAdapter.new
|
2008-10-21 15:27:35 +00:00
|
|
|
response = OpenStruct.new
|
|
|
|
response.status = 200
|
2008-10-21 15:47:15 +00:00
|
|
|
session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
|
2008-10-21 15:27:35 +00:00
|
|
|
session.get('url', {}, nil)
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-10-21 15:27:35 +00:00
|
|
|
%w{post put delete}.each do |request_method|
|
|
|
|
it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
|
2009-08-13 00:50:55 +00:00
|
|
|
session = Webrat::MerbAdapter.new
|
2008-10-21 15:27:35 +00:00
|
|
|
response = OpenStruct.new
|
|
|
|
response.status = 200
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-10-21 15:47:15 +00:00
|
|
|
session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
|
2008-10-21 15:27:35 +00:00
|
|
|
session.send(request_method, 'url', {}, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-04-24 20:56:28 +00:00
|
|
|
%w{post put}.each do |request_method|
|
|
|
|
it "should call do request with method #{request_method.upcase} with a file attachment" do
|
2009-08-13 00:50:55 +00:00
|
|
|
session = Webrat::MerbAdapter.new
|
2009-04-24 20:56:28 +00:00
|
|
|
response = OpenStruct.new
|
|
|
|
response.status = 200
|
|
|
|
|
|
|
|
file = File.new(__FILE__)
|
|
|
|
session.should_receive(:request).with { |path, env|
|
|
|
|
path.should == "url"
|
|
|
|
env[:method].should == request_method.upcase
|
|
|
|
env[:headers].should be_nil
|
|
|
|
env[:input].should be_an_instance_of(StringIO)
|
|
|
|
env["CONTENT_LENGTH"].should be_an_instance_of(Fixnum)
|
|
|
|
env["CONTENT_TYPE"].should match(/multipart.*boundary/)
|
|
|
|
}.and_return(response)
|
|
|
|
session.send(request_method, 'url', { :file => file }, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-21 15:27:35 +00:00
|
|
|
context "a session with a response" do
|
2009-04-08 00:14:59 +00:00
|
|
|
before do
|
2009-08-13 00:50:55 +00:00
|
|
|
@session = Webrat::MerbAdapter.new
|
2008-10-21 15:27:35 +00:00
|
|
|
@response = OpenStruct.new
|
|
|
|
@response.status = 200
|
|
|
|
@response.body = 'test response'
|
|
|
|
@session.instance_variable_set(:@response, @response)
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-10-21 15:27:35 +00:00
|
|
|
it "should return body of a request as a response_body" do
|
|
|
|
@session.response_body.should == @response.body
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-10-21 15:27:35 +00:00
|
|
|
it "should return status of a request as a response_code" do
|
|
|
|
@session.response_code.should == @response.status
|
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
end
|