mechanize.cr/spec/spec_helper.cr

45 lines
1.2 KiB
Crystal
Raw Normal View History

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>
<a href="http://example.com/"></a>
</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")