2021-06-11 04:18:25 +02:00
|
|
|
require "./spec_helper"
|
|
|
|
WebMock.stub(:get, "html_example.com").to_return(body:
|
|
|
|
<<-BODY
|
|
|
|
<html>
|
|
|
|
<meta>
|
|
|
|
<head>
|
|
|
|
<title>page_title</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<form action="post_path" method="post" name="sample_form">
|
|
|
|
<input type="text" name="name">
|
|
|
|
<input type="text" name="email">
|
2021-06-16 07:58:49 +02:00
|
|
|
<input type="checkbox" id="ababa" name="ababa" checked>
|
2021-06-11 04:18:25 +02:00
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
BODY
|
|
|
|
)
|
|
|
|
|
|
|
|
describe "Mechanize Form test" do
|
|
|
|
agent = Mechanize.new
|
|
|
|
uri = "http://html_example.com/"
|
|
|
|
page = agent.get(uri)
|
|
|
|
form = page.forms.first
|
2021-06-16 07:58:49 +02:00
|
|
|
|
2021-06-11 04:18:25 +02:00
|
|
|
it "retrun form attribute" do
|
|
|
|
form.action.should eq "post_path"
|
|
|
|
form.method.should eq "POST"
|
|
|
|
form.enctype.should eq "application/x-www-form-urlencoded"
|
|
|
|
form.name.should eq "sample_form"
|
|
|
|
end
|
|
|
|
|
2021-06-16 07:58:49 +02:00
|
|
|
it "includes fields" do
|
|
|
|
form.fields.size.should eq 2
|
|
|
|
end
|
|
|
|
|
2021-06-11 04:18:25 +02:00
|
|
|
context "Form Fields" do
|
2021-06-16 07:58:49 +02:00
|
|
|
it "returns field attribute" do
|
2021-06-11 04:18:25 +02:00
|
|
|
field = form.fields.first
|
|
|
|
field.type.should eq "text"
|
|
|
|
field.name.should eq "name"
|
|
|
|
end
|
|
|
|
end
|
2021-06-16 07:58:49 +02:00
|
|
|
|
|
|
|
context "Form Fields CheckBox" do
|
|
|
|
checkbox = form.checkboxes.first
|
2021-06-16 08:23:48 +02:00
|
|
|
it "returns checkbox status" do
|
|
|
|
checkbox.checked?.should eq true
|
|
|
|
end
|
|
|
|
it "can change check status" do
|
|
|
|
checkbox.checked?.should eq true
|
|
|
|
checkbox.uncheck
|
|
|
|
checkbox.checked?.should eq false
|
|
|
|
checkbox.check
|
|
|
|
checkbox.checked?.should eq true
|
|
|
|
# #click reverses check status
|
|
|
|
checkbox.click
|
|
|
|
checkbox.checked?.should eq false
|
|
|
|
checkbox.click
|
|
|
|
checkbox.checked?.should eq true
|
|
|
|
end
|
|
|
|
it "returns query value" do
|
|
|
|
p checkbox.query_value
|
|
|
|
end
|
2021-06-16 07:58:49 +02:00
|
|
|
end
|
2021-06-11 04:18:25 +02:00
|
|
|
end
|