add user agent test

master
Kanezoh 2021-08-04 14:37:56 +09:00
parent 976f2b3d68
commit 3d4dfc4568
2 changed files with 16 additions and 0 deletions

View File

@ -47,4 +47,12 @@ describe "Mechanize HTTP test" do
page.body.should eq "success"
page.code.should eq 200
end
it "can set user agent" do
agent = Mechanize.new
mac_chrome_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
agent.user_agent = mac_chrome_agent
page = agent.get("http://example.com/")
agent.request_headers["User-Agent"].should eq mac_chrome_agent
end
end

View File

@ -65,6 +65,14 @@ class Mechanize
@agent.request_headers = request_headers
end
def user_agent
@agent.user_agent
end
def user_agent=(user_agent)
@agent.user_agent = user_agent
end
def current_page
@agent.current_page
end