add page.title test

master
Kanezoh 2021-06-11 08:45:23 +09:00
parent 29a0969504
commit 0b130e7da7
1 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,17 @@ require "webmock"
WebMock.stub(:get, "example.com")
WebMock.stub(:get, "fail_example.com").to_return(status: 500)
WebMock.stub(:get, "body_example.com").to_return(body: "hello")
WebMock.stub(:get, "html_example.com").to_return(body:
<<-BODY
<html>
<meta>
<head>
<title>page_title</title>
</head>
<body></body>
</html>
BODY
)
describe "Mechanize Page test" do
it "return status code of request" do
@ -20,4 +31,12 @@ describe "Mechanize Page test" do
page = agent.get("http://body_example.com")
page.body.should eq "hello"
end
it "return page title" do
agent = Mechanize.new
page = agent.get("http://example.com/")
page.title.should eq ""
page = agent.get("http://html_example.com")
page.title.should eq "page_title"
end
end