mechanize.cr/spec/http_spec.cr

42 lines
1.2 KiB
Crystal
Raw Normal View History

2021-04-19 06:50:12 +02:00
require "./spec_helper"
2021-06-08 14:20:46 +02:00
require "webmock"
2021-06-10 10:09:36 +02:00
WebMock.stub(:get, "example.com")
WebMock.stub(:get, "http://example.com/?foo=bar&foo1=bar2")
2021-04-19 06:50:12 +02:00
2021-06-10 10:30:33 +02:00
describe "Mechanize HTTP test" do
2021-06-09 15:36:35 +02:00
it "simple GET" do
2021-06-09 14:44:54 +02:00
agent = Mechanize.new
uri = "http://example.com/"
page = agent.get(uri)
page.code.should eq 200
page.uri.to_s.should eq uri
2021-04-19 06:50:12 +02:00
end
2021-06-09 15:36:35 +02:00
it "GET with query parameter" do
agent = Mechanize.new
params = {"foo" => "bar", "foo1" => "bar2"}
uri = "http://example.com/"
page = agent.get(uri, params: params)
page.code.should eq 200
page.uri.to_s.should eq "http://example.com/?foo=bar&foo1=bar2"
end
2021-06-10 10:09:36 +02:00
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
2021-04-19 06:50:12 +02:00
end