format code
This commit is contained in:
parent
858a999ed2
commit
9478bffdf1
@ -6,12 +6,11 @@ WebMock.stub(:get, "example.com/cookies2").to_return(headers: {"Set-Cookie" => "
|
||||
WebMock.stub(:get, "example.com/cookies3").to_return(headers: {"Set-Cookie" => "id=456"})
|
||||
WebMock.stub(:get, "example.com/secure_cookies").to_return(headers: {"Set-Cookie" => "id=123; Secure"})
|
||||
WebMock.stub(:get, "example.com/paths").to_return(headers: {"Set-Cookie" => "id=123; Path=/paths"})
|
||||
WebMock.stub(:get, "example.com/paths/hoge").to_return()
|
||||
WebMock.stub(:get, "https://example.com/").to_return()
|
||||
WebMock.stub(:get, "example.com/hoge/paths").to_return()
|
||||
WebMock.stub(:get, "www.example.com").to_return()
|
||||
WebMock.stub(:get, "example.com/meta_cookie").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/paths/hoge").to_return
|
||||
WebMock.stub(:get, "https://example.com/").to_return
|
||||
WebMock.stub(:get, "example.com/hoge/paths").to_return
|
||||
WebMock.stub(:get, "www.example.com").to_return
|
||||
WebMock.stub(:get, "example.com/meta_cookie").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/button").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/button").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/check_box").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/check_box").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/fields").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/fields").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/multi_select_list").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/multi_select_list").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/multi_select_list").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/multi_select_list").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper.cr"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/radio_button").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/radio_button").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/select_list").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/select_list").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "../spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/form/textarea").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form/textarea").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,7 +1,6 @@
|
||||
require "./spec_helper"
|
||||
|
||||
WebMock.stub(:get, "example.com/check_form").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/check_form").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
|
@ -1,8 +1,8 @@
|
||||
require "./spec_helper"
|
||||
WebMock.stub(:get, "http://example.com/?foo=bar&foo1=bar2")
|
||||
WebMock.stub(:post, "http://example.com/post").
|
||||
with(body: "email=foobar", headers: {"Content-Type" => "application/x-www-form-urlencoded"}).
|
||||
to_return(body: "success")
|
||||
WebMock.stub(:post, "http://example.com/post")
|
||||
.with(body: "email=foobar", headers: {"Content-Type" => "application/x-www-form-urlencoded"})
|
||||
.to_return(body: "success")
|
||||
WebMock.stub(:get, "example.com/%E3%81%82%E3%81%82%E3%81%82")
|
||||
|
||||
describe "Mechanize HTTP test" do
|
||||
|
@ -2,14 +2,12 @@ require "spec"
|
||||
require "webmock"
|
||||
require "../src/mechanize"
|
||||
|
||||
|
||||
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/")
|
||||
|
||||
WebMock.stub(:get, "example.com/form").to_return(body:
|
||||
<<-BODY
|
||||
WebMock.stub(:get, "example.com/form").to_return(body: <<-BODY
|
||||
<html>
|
||||
<head>
|
||||
<title>page_title</title>
|
||||
@ -24,10 +22,10 @@ WebMock.stub(:get, "example.com/form").to_return(body:
|
||||
</html>
|
||||
BODY
|
||||
)
|
||||
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")
|
||||
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")
|
||||
|
||||
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")
|
||||
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")
|
||||
|
@ -10,7 +10,8 @@ class Mechanize
|
||||
AGENT = {
|
||||
"Mechanize" => "Mechanize/#{VERSION} Crystal/#{Crystal::VERSION} (https://github.com/Kanezoh/mechanize.cr)",
|
||||
}
|
||||
def initialize()
|
||||
|
||||
def initialize
|
||||
@agent = MechanizeCr::HTTP::Agent.new
|
||||
@agent.context = self
|
||||
@agent.user_agent = AGENT["Mechanize"]
|
||||
|
@ -6,6 +6,7 @@
|
||||
# this property is used to send cookies to same origin resource.
|
||||
class ::HTTP::Cookie
|
||||
property origin : String?
|
||||
|
||||
def initialize(name : String, value : String, @path : String? = nil,
|
||||
@expires : Time? = nil, @domain : String? = nil,
|
||||
@secure : Bool = false, @http_only : Bool = false,
|
||||
@ -30,7 +31,7 @@ class ::HTTP::Cookie
|
||||
end
|
||||
|
||||
if domain
|
||||
host.try &.=~(/.*#{domain.try &.gsub(".", "\.")}$/)
|
||||
host.try &.=~(/.*#{domain.try &.gsub(".", ".")}$/)
|
||||
else
|
||||
origin == host
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
require "./base_error"
|
||||
|
||||
class MechanizeCr::ElementNotFoundError < MechanizeCr::Error
|
||||
getter element : Symbol
|
||||
getter conditions : String
|
||||
@ -9,5 +10,4 @@ class MechanizeCr::ElementNotFoundError < MechanizeCr::Error
|
||||
|
||||
super "Element #{element} with conditions #{conditions} was not found"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,7 +1,9 @@
|
||||
require "http/client"
|
||||
|
||||
class MechanizeCr::File
|
||||
# property :body, :filename
|
||||
property :body, :code, uri, :response
|
||||
|
||||
def initialize(uri : URI, response : ::HTTP::Client::Response, body : String, code : Int32)
|
||||
@uri = uri
|
||||
@body = body
|
||||
|
@ -1,10 +1,12 @@
|
||||
class MechanizeCr::FormContent::Button < MechanizeCr::FormContent::Field
|
||||
getter form_node : Node | Lexbor::Node
|
||||
|
||||
def initialize(node : Node | Lexbor::Node, form_node : Node | Lexbor::Node, value = nil)
|
||||
@form_node = form_node
|
||||
super(node, value)
|
||||
end
|
||||
end
|
||||
|
||||
require "./reset_button"
|
||||
require "./submit_button"
|
||||
require "./image_button"
|
||||
|
@ -2,6 +2,7 @@ class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::RadioButton
|
||||
def check
|
||||
@checked = true
|
||||
end
|
||||
|
||||
def query_value
|
||||
[@name, @value || "on"]
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ class MechanizeCr::FormContent::Field
|
||||
def inspect # :nodoc:
|
||||
"[%s:0x%x type: %s name: %s value: %s]" % [
|
||||
self.class.name.sub(/MechanizeCr::FormContent::/, "").downcase,
|
||||
object_id, type, name, value
|
||||
object_id, type, name, value,
|
||||
]
|
||||
end
|
||||
end
|
||||
|
@ -55,7 +55,7 @@ class MechanizeCr::FormContent::MultiSelectList
|
||||
def inspect # :nodoc:
|
||||
"[%s:0x%x type: %s name: %s values: [%s]]" % [
|
||||
self.class.name.sub(/MechanizeCr::FormContent::/, "").downcase,
|
||||
object_id, type, name, values.join(',')
|
||||
object_id, type, name, values.join(','),
|
||||
]
|
||||
end
|
||||
end
|
||||
|
@ -51,7 +51,6 @@ class MechanizeCr::FormContent::RadioButton < MechanizeCr::FormContent::Field
|
||||
#
|
||||
# alias eql? == # :nodoc:
|
||||
|
||||
|
||||
private def uncheck_peers
|
||||
form.radiobuttons_with(name).try &.each do |b|
|
||||
next if b.value == value
|
||||
|
@ -2,6 +2,7 @@ require "./page"
|
||||
|
||||
class MechanizeCr::History < Array(MechanizeCr::Page)
|
||||
property max_size : Int32
|
||||
|
||||
def initialize(max_size = 100)
|
||||
@max_size = max_size
|
||||
super
|
||||
|
@ -52,7 +52,7 @@ module MechanizeCr
|
||||
|
||||
def http_request(uri, method, params)
|
||||
case uri.scheme.not_nil!.downcase
|
||||
when "http", "https" then
|
||||
when "http", "https"
|
||||
case method
|
||||
when :get
|
||||
::HTTP::Client.get(uri, headers: request_headers)
|
||||
|
Loading…
Reference in New Issue
Block a user