add post test

This commit is contained in:
Kanezoh 2021-06-11 13:47:36 +09:00
parent 22c6a4a42a
commit 3fa6d2db9f
2 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,9 @@
require "./spec_helper"
WebMock.stub(:get, "example.com")
WebMock.stub(:get, "http://example.com/?foo=bar&foo1=bar2")
WebMock.stub(:post, "http://example.com/post").
with(body: "email=foobar", headers: {"Content-Type" => "application/x-www-form-urlencoded"}).
to_return(body: "success")
describe "Mechanize HTTP test" do
it "simple GET" do
@ -37,4 +40,12 @@ describe "Mechanize HTTP test" do
agent.request_headers.empty?.should eq false
agent.request_headers["Foo"].should eq "Bar"
end
it "simple POST" do
agent = Mechanize.new
query = { "email" => "foobar" }
page = agent.post("http://example.com/post", query: query)
page.body.should eq "success"
page.code.should eq 200
end
end

View File

@ -5,10 +5,10 @@ class MechanizeCr::FormContent::Field
getter type : String
getter raw_value : String
def initialize(node : Node | Myhtml::Node)
def initialize(node : Node | Myhtml::Node, value = "")
@node = node
@name = node.fetch("name", "")
@value = node.fetch("value", "")
@value = value || node.fetch("value", "")
@type = node.fetch("type", "")
@raw_value = value
end