add post test
This commit is contained in:
parent
22c6a4a42a
commit
3fa6d2db9f
@ -1,6 +1,9 @@
|
|||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
WebMock.stub(:get, "example.com")
|
WebMock.stub(:get, "example.com")
|
||||||
WebMock.stub(:get, "http://example.com/?foo=bar&foo1=bar2")
|
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
|
describe "Mechanize HTTP test" do
|
||||||
it "simple GET" do
|
it "simple GET" do
|
||||||
@ -37,4 +40,12 @@ describe "Mechanize HTTP test" do
|
|||||||
agent.request_headers.empty?.should eq false
|
agent.request_headers.empty?.should eq false
|
||||||
agent.request_headers["Foo"].should eq "Bar"
|
agent.request_headers["Foo"].should eq "Bar"
|
||||||
end
|
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
|
end
|
||||||
|
@ -5,10 +5,10 @@ class MechanizeCr::FormContent::Field
|
|||||||
getter type : String
|
getter type : String
|
||||||
getter raw_value : String
|
getter raw_value : String
|
||||||
|
|
||||||
def initialize(node : Node | Myhtml::Node)
|
def initialize(node : Node | Myhtml::Node, value = "")
|
||||||
@node = node
|
@node = node
|
||||||
@name = node.fetch("name", "")
|
@name = node.fetch("name", "")
|
||||||
@value = node.fetch("value", "")
|
@value = value || node.fetch("value", "")
|
||||||
@type = node.fetch("type", "")
|
@type = node.fetch("type", "")
|
||||||
@raw_value = value
|
@raw_value = value
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user