Skip to content

Commit

Permalink
test: update tests to use frozen string literals
Browse files Browse the repository at this point in the history
so that ruby 3.4 doesn't emit so many warnings.
  • Loading branch information
flavorjones committed Mar 24, 2024
1 parent d353494 commit 8d49a1e
Show file tree
Hide file tree
Showing 48 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions test/test_mechanize.rb
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

require 'mechanize/test_case'

Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_cookie.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

module Enumerable
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_cookie_jar.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'
require 'fileutils'

Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_directory_saver.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeDirectorySaver < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_download.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeDownload < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_element_not_found_error.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeRedirectLimitReachedError < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_file.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFile < Mechanize::TestCase
Expand Down
3 changes: 2 additions & 1 deletion test/test_mechanize_file_connection.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFileConnection < Mechanize::TestCase
Expand All @@ -7,7 +8,7 @@ def test_request
uri = URI.parse "file://#{file_path}"
conn = Mechanize::FileConnection.new

body = ''
body = +''

conn.request uri, nil do |response|
assert_equal(file_path, response.file_path)
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_file_request.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFileRequest < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_file_response.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFileResponse < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_file_saver.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFileSaver < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeForm < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_check_box.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormCheckBox < Mechanize::TestCase
Expand Down
3 changes: 2 additions & 1 deletion test/test_mechanize_form_encoding.rb
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormEncoding < Mechanize::TestCase
Expand All @@ -8,7 +9,7 @@ class TestMechanizeFormEncoding < Mechanize::TestCase

INPUTTED_VALUE = "テスト" # "test" in Japanese UTF-8 encoding
CONTENT_ENCODING = 'Shift_JIS' # one of Japanese encoding
encoded_value = "\x83\x65\x83\x58\x83\x67".force_encoding(::Encoding::SHIFT_JIS) # "test" in Japanese Shift_JIS encoding
encoded_value = "\x83\x65\x83\x58\x83\x67".dup.force_encoding(::Encoding::SHIFT_JIS) # "test" in Japanese Shift_JIS encoding
EXPECTED_QUERY = "first_name=#{CGI.escape(encoded_value)}&first_name=&gender=&green%5Beggs%5D="

ENCODING_ERRORS = [EncodingError, Encoding::ConverterNotFoundError] # and so on
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_field.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormField < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_file_upload.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormFileUpload < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_image_button.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormImageButton < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_keygen.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormKeygen < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_multi_select_list.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormMultiSelectList < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_option.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormOption < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_radio_button.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormRadioButton < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_select_list.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormSelectList < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_form_textarea.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormTextarea < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_headers.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeHeaders < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_history.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeHistory < Mechanize::TestCase
Expand Down
7 changes: 4 additions & 3 deletions test/test_mechanize_http_agent.rb
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

require 'mechanize/test_case'

Expand Down Expand Up @@ -1027,7 +1028,7 @@ def test_response_content_encoding_gzip_encoding_bad

body = @agent.response_content_encoding @res, body_io

expected = "test\xB2"
expected = +"test\xB2"
expected.force_encoding Encoding::BINARY if have_encoding?

content = body.read
Expand Down Expand Up @@ -1432,11 +1433,11 @@ def test_response_read_file

io = @agent.response_read res, req, uri

expected = \n".force_encoding(Encoding::BINARY)
expected = \n".dup.force_encoding(Encoding::BINARY)

# Ruby 1.8.7 doesn't let us set the write mode of the tempfile to binary,
# so we should expect an inserted carriage return on some platforms
expected_with_carriage_return = \r\n".force_encoding(Encoding::BINARY)
expected_with_carriage_return = \r\n".dup.force_encoding(Encoding::BINARY)

body = io.read
assert_match(/^(#{expected}|#{expected_with_carriage_return})$/m, body)
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_http_auth_challenge.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeHttpAuthChallenge < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_http_auth_realm.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeHttpAuthRealm < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_http_auth_store.rb
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

require 'mechanize/test_case'

Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_http_content_disposition_parser.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeHttpContentDispositionParser < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_http_www_authenticate_parser.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeHttpWwwAuthenticateParser < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_image.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeImage < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_link.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeLink < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_page.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizePage < Mechanize::TestCase
Expand Down
11 changes: 6 additions & 5 deletions test/test_mechanize_page_encoding.rb
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
require 'mechanize/test_case'

# tests for Page encoding and charset and parsing
Expand All @@ -12,7 +13,7 @@ def setup

@uri = URI('http://localhost/')
@response_headers = { 'content-type' => 'text/html' }
@body = '<title>hi</title>'
@body = +'<title>hi</title>'
end

def util_page body = @body, headers = @response_headers
Expand Down Expand Up @@ -118,7 +119,7 @@ def test_page_meta_charset_handles_whitespace
end

def test_meta_charset
body = '<meta http-equiv="content-type" content="text/html;charset=META">'
body = +'<meta http-equiv="content-type" content="text/html;charset=META">'
page = util_page body

assert_equal ['META'], page.meta_charset
Expand All @@ -132,7 +133,7 @@ def test_detected_encoding

def test_encodings
response = {'content-type' => 'text/html;charset=HEADER'}
body = '<meta http-equiv="content-type" content="text/html;charset=META">'
body = +'<meta http-equiv="content-type" content="text/html;charset=META">'
@mech.default_encoding = 'DEFAULT'
page = util_page body, response

Expand Down Expand Up @@ -175,7 +176,7 @@ def test_parser_encoding_equals_overwrites_force_default_encoding
def test_parser_encoding_when_searching_elements
skip "Encoding not implemented" unless have_encoding?

body = '<span id="latin1">hi</span>'
body = +'<span id="latin1">hi</span>'
page = util_page body, 'content-type' => 'text/html,charset=ISO-8859-1'

result = page.search('#latin1')
Expand All @@ -187,7 +188,7 @@ def test_parser_error_message_containing_encoding_errors
skip if RUBY_ENGINE == 'jruby' # this is a libxml2-specific condition

# https://github.com/sparklemotion/mechanize/issues/553
body = <<~EOF
body = +<<~EOF
<html>
<body>
<!--
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_page_frame.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizePageFrame < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_page_image.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizePageImage < Mechanize::TestCase
Expand Down
13 changes: 7 additions & 6 deletions test/test_mechanize_page_link.rb
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

require 'mechanize/test_case'

Expand All @@ -11,7 +12,7 @@ class TestMechanizePageLink < Mechanize::TestCase
<title>hi</title>
HTML

BAD = <<-HTML
BAD = <<-HTML.dup
<meta http-equiv="content-type" content="text/html; charset=windows-1255">
<title>Bia\xB3ystok</title>
HTML
Expand Down Expand Up @@ -46,7 +47,7 @@ def setup

@uri = URI('http://example')
@res = { 'content-type' => 'text/html' }
@body = '<title>hi</title>'
@body = +'<title>hi</title>'
end

def util_page body = @body, res = @res
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_canonical_uri
end

def test_canonical_uri_unescaped
page = util_page <<-BODY
page = util_page(+<<-BODY)
<head>
<link rel="canonical" href="http://example/white space"/>
</head>
Expand All @@ -97,7 +98,7 @@ def test_charset_from_bad_content_type
end

def test_encoding
page = util_page WINDOWS_1255
page = util_page WINDOWS_1255.dup

assert_equal 'windows-1255', page.encoding
end
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_encoding_charset_bad
end

def test_encoding_meta_charset
page = util_page "<meta charset='UTF-8'>"
page = util_page(+"<meta charset='UTF-8'>")

assert_equal 'UTF-8', page.encoding
end
Expand Down Expand Up @@ -344,7 +345,7 @@ def test_title
end

def test_title_none
page = util_page '' # invalid HTML
page = util_page(+'') # invalid HTML

assert_nil(page.title)
end
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_page_meta_refresh.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizePageMetaRefresh < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_parser.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeParser < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_pluggable_parser.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizePluggableParser < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_redirect_limit_reached_error.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeRedirectLimitReachedError < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_redirect_not_get_or_head_error.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeRedirectNotGetOrHead < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_response_read_error.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeResponseReadError < Mechanize::TestCase
Expand Down
1 change: 1 addition & 0 deletions test/test_mechanize_subclass.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeSubclass < Mechanize::TestCase
Expand Down

0 comments on commit 8d49a1e

Please sign in to comment.