2021-06-10 10:38:42 +02:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
describe "Mechanize Page test" do
|
|
|
|
it "return status code of request" do
|
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/")
|
|
|
|
page.code.should eq 200
|
|
|
|
page = agent.get("http://fail_example.com")
|
|
|
|
page.code.should eq 500
|
|
|
|
end
|
|
|
|
|
|
|
|
it "return request body" do
|
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/")
|
|
|
|
page.body.should eq ""
|
|
|
|
page = agent.get("http://body_example.com")
|
|
|
|
page.body.should eq "hello"
|
|
|
|
end
|
2021-06-11 01:45:23 +02:00
|
|
|
|
|
|
|
it "return page title" do
|
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/")
|
|
|
|
page.title.should eq ""
|
2021-06-16 16:20:03 +02:00
|
|
|
page = agent.get("http://example.com/form")
|
2021-06-11 01:45:23 +02:00
|
|
|
page.title.should eq "page_title"
|
|
|
|
end
|
2021-06-11 02:17:59 +02:00
|
|
|
|
|
|
|
it "return page forms" do
|
|
|
|
agent = Mechanize.new
|
2021-06-16 16:20:03 +02:00
|
|
|
page = agent.get("http://example.com/form")
|
2021-06-11 02:17:59 +02:00
|
|
|
page.forms.size.should eq 1
|
2021-06-27 13:17:23 +02:00
|
|
|
page.forms.first.name.should eq "sample_form"
|
|
|
|
end
|
|
|
|
|
2021-08-11 00:17:38 +02:00
|
|
|
it "can detect form by using form_with method, argument type: Hash" do
|
2021-06-27 13:17:23 +02:00
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/form")
|
2021-08-17 18:30:01 +02:00
|
|
|
form = page.form_with({"name" => "sample_form"})
|
2021-06-27 13:17:23 +02:00
|
|
|
form.name.should eq "sample_form"
|
2021-06-11 02:17:59 +02:00
|
|
|
end
|
2021-08-11 00:17:38 +02:00
|
|
|
|
|
|
|
it "can detect form by using form_with method, argument type: NamedTuple" do
|
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/form")
|
2021-08-17 18:30:01 +02:00
|
|
|
form = page.form_with({name: "sample_form"})
|
2021-08-11 00:17:38 +02:00
|
|
|
form.name.should eq "sample_form"
|
|
|
|
end
|
2021-08-19 02:02:14 +02:00
|
|
|
|
2021-08-19 03:42:11 +02:00
|
|
|
it "return page links, links means <a> and <area>" do
|
2021-08-19 02:02:14 +02:00
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/link")
|
2021-08-19 03:42:11 +02:00
|
|
|
page.links.size.should eq 2
|
2021-08-19 02:02:14 +02:00
|
|
|
end
|
2021-06-10 10:38:42 +02:00
|
|
|
end
|