From d96d597547d15ebecdf2dfde3c10d16cafe862e0 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Sat, 12 Jun 2021 23:17:45 +0900 Subject: [PATCH] add submit form test --- spec/agent_spec.cr | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/agent_spec.cr diff --git a/spec/agent_spec.cr b/spec/agent_spec.cr new file mode 100644 index 0000000..907ed56 --- /dev/null +++ b/spec/agent_spec.cr @@ -0,0 +1,32 @@ +require "./spec_helper" +WebMock.stub(:get, "html_example.com").to_return(body: +<<-BODY + + + + page_title + + +
+ + + +
+ + +BODY +) +WebMock.stub(:post, "http://html_example.com/post_path"). + with(body: "name=foo&email=bar", headers: {"Content-Type" => "application/x-www-form-urlencoded"}). + to_return(body: "success") + +describe "Mechanize Agent test" do + agent = Mechanize.new + page = agent.get("http://html_example.com/") + form = page.forms[0] + form.field_with("name").value = "foo" + form.field_with("email").value = "bar" + page = agent.submit(form) + page.not_nil!.code.should eq 200 + page.not_nil!.body.should eq "success" +end