From 316a3de570cb6c133e9f75f388a9c78dc8c278f1 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Wed, 16 Jun 2021 14:17:11 +0900 Subject: [PATCH] add history test --- spec/agent_spec.cr | 20 +++++++++++++++----- src/mechanize/http/agent.cr | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spec/agent_spec.cr b/spec/agent_spec.cr index 792f2c2..9ed4304 100644 --- a/spec/agent_spec.cr +++ b/spec/agent_spec.cr @@ -36,7 +36,7 @@ WebMock.stub(:post, "http://html_example.com/post_path"). to_return(body: "success") describe "Mechanize Agent test" do - it "fill and submit form" do + it "can fill and submit form" do agent = Mechanize.new page = agent.get("http://html_example.com/") form = page.forms[0] @@ -47,7 +47,7 @@ describe "Mechanize Agent test" do page.not_nil!.body.should eq "success" end - it "receive and send cookie" do + it "can receive and send cookie" do agent = Mechanize.new # receive cookies agent.get("http://example.com/cookies1") @@ -56,7 +56,7 @@ describe "Mechanize Agent test" do agent.request_headers["Cookie"].should eq "id=123" end - it "receive and send multiple cookies" do + it "can receive and send multiple cookies" do agent = Mechanize.new # receive cookies1 agent.get("http://example.com/cookies1") @@ -66,14 +66,14 @@ describe "Mechanize Agent test" do agent.request_headers["Cookie"].should eq "id=123; name=kanezoh" end - it "get cookie from meta head" do + it "can get cookie from meta head" do agent = Mechanize.new agent.get("http://example.com/meta_cookie") agent.get("http://example.com/") agent.request_headers["Cookie"].should eq "id=123" end - it "don't send cookies to another domain" do + it "doesn't send cookies to another domain" do agent = Mechanize.new agent.get("http://example.com/cookies1") agent.get("http://example.com/") @@ -81,4 +81,14 @@ describe "Mechanize Agent test" do agent.get("http://another_domain.com/") agent.request_headers.has_key?("Cookie").should eq false end + + it "can save history" do + agent = Mechanize.new + agent.get("http://example.com/") + agent.history.size.should eq 1 + agent.history.last.title.should eq "" + agent.get("http://html_example.com/") + agent.history.size.should eq 2 + agent.history.last.title.should eq "page_title" + end end diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index 2fef4dc..a720407 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -37,6 +37,10 @@ module MechanizeCr end end + def back + @history.pop + end + private def set_request_headers(uri, headers) reset_request_header_cookies host = uri.host