mechanize.cr/spec/form_spec.cr

54 lines
1.6 KiB
Crystal
Raw Normal View History

2021-06-11 04:18:25 +02:00
require "./spec_helper"
2021-06-16 16:20:03 +02:00
WebMock.stub(:get, "example.com/check_form").to_return(body:
2021-06-11 04:18:25 +02:00
<<-BODY
<html>
<head>
<title>page_title</title>
</head>
<body>
<form action="post_path" method="post" name="sample_form">
2021-06-18 23:16:36 +02:00
<!-- fields -->
2021-06-11 04:18:25 +02:00
<input type="text" name="name">
<input type="text" name="email">
2021-06-18 23:16:36 +02:00
<input type="hidden" name="userid" value="12345">
<input type="password" id="pass" name="password">
<!-- checkbox -->
2021-06-16 16:20:03 +02:00
<input type="checkbox" id="remember_me" name="remember_me" checked>
2021-06-18 23:16:36 +02:00
<!-- radiobuttons -->
2021-06-17 05:04:45 +02:00
<input type="radio" id="contactChoice1" name="contact" value="email">
<input type="radio" id="contactChoice2" name="contact" value="phone">
<input type="radio" id="contactChoice3" name="contact" value="mail">
2021-06-18 23:16:36 +02:00
<!-- buttons -->
<input type="button" value="pushit">
<input type="reset" value="no">
<input type="submit" value="submit">
2021-06-30 07:05:17 +02:00
<input type="image" src="images/kaeru.png" alt="gerogero">
2021-06-11 04:18:25 +02:00
</form>
</body>
</html>
BODY
)
describe "Mechanize Form test" do
agent = Mechanize.new
2021-06-16 16:20:03 +02:00
uri = "http://example.com/check_form"
2021-06-11 04:18:25 +02:00
page = agent.get(uri)
form = page.forms.first
2021-06-16 07:58:49 +02:00
2021-06-18 13:59:10 +02:00
it "returns form attribute" do
2021-06-11 04:18:25 +02:00
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-18 23:16:36 +02:00
it "includes fields, radiobuttons, checkboxes, buttons" do
# fields: input type = (text,hidden, or others)
form.fields.size.should eq 4
form.checkboxes.size.should eq 1
form.radiobuttons.size.should eq 3
2021-06-30 07:05:17 +02:00
form.buttons.size.should eq 4
2021-06-16 07:58:49 +02:00
end
2021-06-11 04:18:25 +02:00
end