Class: Mechanize::TestCase
- Inherits:
-
MiniTest::Unit::TestCase
- Object
- MiniTest::Unit::TestCase
- Mechanize::TestCase
- Defined in:
- lib/mechanize/test_case.rb
Constant Summary collapse
- TEST_DIR =
File. '../../../test', __FILE__
- REQUESTS =
[]
Instance Method Summary collapse
- #fake_page(agent = @mech) ⇒ Object
- #have_encoding? ⇒ Boolean
- #html_page(body) ⇒ Object
- #in_tmpdir ⇒ Object
- #node(element, attributes = {}) ⇒ Object
- #page(uri, content_type = 'text/html', body = '', code = 200) ⇒ Object
- #requests ⇒ Object
- #setup ⇒ Object
- #ssl_certificate ⇒ Object
- #ssl_private_key ⇒ Object
Instance Method Details
#fake_page(agent = @mech) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mechanize/test_case.rb', line 31 def fake_page agent = @mech uri = URI 'http://fake.example/' html = <<-END <html> <body> <form><input type="submit" value="submit" /></form> </body> </html> END response = { 'content-type' => 'text/html' } Mechanize::Page.new uri, response, html, 200, agent end |
#have_encoding? ⇒ Boolean
46 47 48 |
# File 'lib/mechanize/test_case.rb', line 46 def have_encoding? Object.const_defined? :Encoding end |
#html_page(body) ⇒ Object
50 51 52 53 |
# File 'lib/mechanize/test_case.rb', line 50 def html_page body uri = URI 'http://example/' Mechanize::Page.new uri, { 'content-type' => 'text/html' }, body, 200, @mech end |
#in_tmpdir ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mechanize/test_case.rb', line 55 def in_tmpdir Dir.mktmpdir do |dir| Dir.chdir dir do yield end end end |
#node(element, attributes = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mechanize/test_case.rb', line 63 def node element, attributes = {} doc = Nokogiri::HTML::Document.new node = Nokogiri::XML::Node.new element, doc attributes.each do |name, value| node[name] = value end node end |
#page(uri, content_type = 'text/html', body = '', code = 200) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/mechanize/test_case.rb', line 75 def page uri, content_type = 'text/html', body = '', code = 200 uri = URI uri unless URI::Generic === uri Mechanize::Page.new(uri, { 'content-type' => content_type }, body, code, @mech) end |
#requests ⇒ Object
82 83 84 |
# File 'lib/mechanize/test_case.rb', line 82 def requests REQUESTS end |
#setup ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/mechanize/test_case.rb', line 22 def setup super REQUESTS.clear @mech = Mechanize.new @ssl_private_key = nil @ssl_certificate = nil end |
#ssl_certificate ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mechanize/test_case.rb', line 97 def ssl_certificate @ssl_certificate ||= OpenSSL::X509::Certificate.new <<-CERT -----BEGIN CERTIFICATE----- MIIBQjCB7aADAgECAgEAMA0GCSqGSIb3DQEBBQUAMCoxDzANBgNVBAMMBm5vYm9k eTEXMBUGCgmSJomT8ixkARkWB2V4YW1wbGUwIBcNMTExMTAzMjEwODU5WhgPOTk5 OTEyMzExMjU5NTlaMCoxDzANBgNVBAMMBm5vYm9keTEXMBUGCgmSJomT8ixkARkW B2V4YW1wbGUwWjANBgkqhkiG9w0BAQEFAANJADBGAkEA8pmEfmP0Ibir91x6pbts 4JmmsVZd3xvD5p347EFvBCbhBW1nv1GsbCBEFlSiT1q2qvxGb5IlbrfdhdgyqdTX UQIBATANBgkqhkiG9w0BAQUFAANBAAAB//////////////////////////////// //8AMCEwCQYFKw4DAhoFAAQUePiv+QrJxyjtEJNnH5pB9OTWIqA= -----END CERTIFICATE----- CERT end |
#ssl_private_key ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mechanize/test_case.rb', line 86 def ssl_private_key @ssl_private_key ||= OpenSSL::PKey::RSA.new <<-KEY -----BEGIN RSA PRIVATE KEY----- MIG7AgEAAkEA8pmEfmP0Ibir91x6pbts4JmmsVZd3xvD5p347EFvBCbhBW1nv1Gs bCBEFlSiT1q2qvxGb5IlbrfdhdgyqdTXUQIBAQIBAQIhAPumXslvf6YasXa1hni3 p80joKOug2UUgqOLD2GUSO//AiEA9ssY6AFxjHWuwo/+/rkLmkfO2s1Lz3OeUEWq 6DiHOK8CAQECAQECIQDt8bc4vS6wh9VXApNSKIpVygtxSFe/IwLeX26n77j6Qg== -----END RSA PRIVATE KEY----- KEY end |