2021-04-19 06:50:12 +02:00
|
|
|
require "spec"
|
2021-06-11 03:44:59 +02:00
|
|
|
require "webmock"
|
2021-04-19 06:50:12 +02:00
|
|
|
require "../src/mechanize"
|
2021-06-16 16:20:03 +02:00
|
|
|
|
|
|
|
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, "another_domain.com/")
|
|
|
|
|
2021-08-17 18:30:01 +02:00
|
|
|
WebMock.stub(:get, "example.com/form").to_return(body: <<-BODY
|
2021-06-16 16:20:03 +02:00
|
|
|
<html>
|
|
|
|
<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-29 12:14:30 +02:00
|
|
|
<input type="submit" name="commit" value="submit">
|
2021-06-16 16:20:03 +02:00
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
BODY
|
|
|
|
)
|
2021-08-19 02:02:14 +02:00
|
|
|
|
|
|
|
WebMock.stub(:get, "example.com/link").to_return(body: <<-BODY
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>page_title</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
2021-08-19 02:49:53 +02:00
|
|
|
<a href="http://example.com/">link text</a>
|
2021-08-19 03:42:11 +02:00
|
|
|
<map>
|
|
|
|
<area shape="rect" coords="184,6,253,27"
|
|
|
|
href="http://example.com" />
|
|
|
|
</map>
|
2021-08-19 02:02:14 +02:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
BODY
|
|
|
|
)
|
|
|
|
|
2021-08-17 18:30:01 +02:00
|
|
|
WebMock.stub(:post, "example.com/post_path")
|
|
|
|
.with(body: "name=foo&email=bar", headers: {"Content-Type" => "application/x-www-form-urlencoded"})
|
|
|
|
.to_return(body: "success")
|
2021-06-29 12:14:30 +02:00
|
|
|
|
2021-08-17 18:30:01 +02:00
|
|
|
WebMock.stub(:post, "example.com/post_path")
|
|
|
|
.with(body: "name=foo&email=bar&commit=submit", headers: {"Content-Type" => "application/x-www-form-urlencoded"})
|
|
|
|
.to_return(body: "success with button")
|