add http test
This commit is contained in:
parent
663e6dac5d
commit
88f973d2af
@ -1,6 +1,7 @@
|
|||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
require "webmock"
|
require "webmock"
|
||||||
WebMock.stub(:any, "example.com")
|
WebMock.stub(:get, "example.com")
|
||||||
|
WebMock.stub(:get, "http://example.com/?foo=bar&foo1=bar2")
|
||||||
|
|
||||||
describe Mechanize do
|
describe Mechanize do
|
||||||
it "simple GET" do
|
it "simple GET" do
|
||||||
@ -12,7 +13,6 @@ describe Mechanize do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "GET with query parameter" do
|
it "GET with query parameter" do
|
||||||
WebMock.stub(:get, "http://example.com/?foo=bar&foo1=bar2")
|
|
||||||
agent = Mechanize.new
|
agent = Mechanize.new
|
||||||
params = {"foo" => "bar", "foo1" => "bar2"}
|
params = {"foo" => "bar", "foo1" => "bar2"}
|
||||||
uri = "http://example.com/"
|
uri = "http://example.com/"
|
||||||
@ -20,4 +20,22 @@ describe Mechanize do
|
|||||||
page.code.should eq 200
|
page.code.should eq 200
|
||||||
page.uri.to_s.should eq "http://example.com/?foo=bar&foo1=bar2"
|
page.uri.to_s.should eq "http://example.com/?foo=bar&foo1=bar2"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "GET with query parameter as URL string" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
uri = "http://example.com/?foo=bar&foo1=bar2"
|
||||||
|
page = agent.get(uri)
|
||||||
|
page.code.should eq 200
|
||||||
|
page.uri.to_s.should eq uri
|
||||||
|
end
|
||||||
|
|
||||||
|
it "set custom request headers" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
uri = "http://example.com/"
|
||||||
|
headers = HTTP::Headers{"Foo" => "Bar"}
|
||||||
|
agent.request_headers.empty?.should eq true
|
||||||
|
page = agent.get(uri, headers: headers)
|
||||||
|
agent.request_headers.empty?.should eq false
|
||||||
|
agent.request_headers["Foo"].should eq "Bar"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user