diff --git a/.github/workflows/ruby-tests.yml b/.github/workflows/ruby-tests.yml index cffac166..ba1de791 100644 --- a/.github/workflows/ruby-tests.yml +++ b/.github/workflows/ruby-tests.yml @@ -19,12 +19,11 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["2.7", "3.0", "3.1"] + ruby: ["3.2", "3.3"] gemfile: - Gemfile - - gemfiles/7_0.gemfile + - gemfiles/7_1.gemfile - gemfiles/6_1.gemfile - - gemfiles/6_0.gemfile steps: - uses: actions/checkout@v2.4.0 diff --git a/.rubocop.yml b/.rubocop.yml index 81749dcf..13ca8f16 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,3 +16,6 @@ AllCops: Naming/VariableNumber: Enabled: false + +Minitest/EmptyLineBeforeAssertionMethods: + Enabled: false diff --git a/browser.gemspec b/browser.gemspec index d6a22491..d4821c62 100644 --- a/browser.gemspec +++ b/browser.gemspec @@ -7,27 +7,26 @@ Gem::Specification.new do |s| s.version = Browser::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Nando Vieira"] - s.email = ["fnando.vieira@gmail.com"] + s.email = ["me@fnando.com"] s.homepage = "https://github.com/fnando/browser" s.summary = "Do some browser detection with Ruby." s.description = s.summary s.license = "MIT" - s.required_ruby_version = ">= 2.5.0" + s.required_ruby_version = ">= 3.2.0" + s.metadata["rubygems_mfa_required"] = "true" s.metadata["changelog_uri"] = "https://github.com/fnando/browser/blob/main/CHANGELOG.md" s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- exe/*` .split("\n") .map {|f| File.basename(f) } s.require_paths = ["lib"] - s.add_development_dependency "bundler", ">= 0" + s.add_development_dependency "bundler" s.add_development_dependency "minitest" s.add_development_dependency "minitest-autotest" s.add_development_dependency "minitest-utils" - s.add_development_dependency "pry-meta" s.add_development_dependency "rack-test" s.add_development_dependency "rails" s.add_development_dependency "rake" diff --git a/gemfiles/6_1.gemfile b/gemfiles/6_1.gemfile deleted file mode 100644 index 8f0feace..00000000 --- a/gemfiles/6_1.gemfile +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" -gemspec path: ".." - -gem "rails", "~> 6.1.0" diff --git a/gemfiles/6_0.gemfile b/gemfiles/7_1.gemfile similarity index 77% rename from gemfiles/6_0.gemfile rename to gemfiles/7_1.gemfile index bda7e30a..b17e019b 100644 --- a/gemfiles/6_0.gemfile +++ b/gemfiles/7_1.gemfile @@ -3,4 +3,4 @@ source "https://rubygems.org" gemspec path: ".." -gem "rails", "~> 6.0.0" +gem "rails", "~> 7.1.0" diff --git a/lib/browser.rb b/lib/browser.rb index bf811ac7..87aca635 100644 --- a/lib/browser.rb +++ b/lib/browser.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true require_relative "browser/browser" -require_relative "browser/rails" if defined?(::Rails) +require_relative "browser/rails" if defined?(Rails) diff --git a/lib/browser/base.rb b/lib/browser/base.rb index 157689b5..4c974c93 100644 --- a/lib/browser/base.rb +++ b/lib/browser/base.rb @@ -270,7 +270,7 @@ def electron?(expected_version = nil) private def validate_size(subject, input) actual_bytesize = input.bytesize - size_limit = Browser.public_send("#{subject}_size_limit") + size_limit = Browser.public_send(:"#{subject}_size_limit") return if actual_bytesize < size_limit diff --git a/test/browser_test.rb b/test/browser_test.rb index 825dc0b7..9f89d58d 100644 --- a/test/browser_test.rb +++ b/test/browser_test.rb @@ -117,7 +117,7 @@ class BrowserTest < Minitest::Test test "returns empty language set for missing accept language" do browser = Browser.new("") - assert_equal [], browser.accept_language + assert_empty browser.accept_language end test "sets accept language while instantiating object" do diff --git a/test/rails_test.rb b/test/rails_test.rb index fadb9698..7237b005 100644 --- a/test/rails_test.rb +++ b/test/rails_test.rb @@ -26,7 +26,7 @@ def app "HTTP_ACCEPT_LANGUAGE" => "en-US;q=0.8" assert_equal 200, last_response.status - assert_equal true, JSON.parse(last_response.body)["isBot"] + assert JSON.parse(last_response.body)["isBot"] assert_equal "en-US", JSON.parse(last_response.body)["acceptLanguages"][0] end end diff --git a/test/unit/accept_language_test.rb b/test/unit/accept_language_test.rb index e9bb6123..2586ba7b 100644 --- a/test/unit/accept_language_test.rb +++ b/test/unit/accept_language_test.rb @@ -161,6 +161,6 @@ def assert_language(item, expect = {}) test "sets default quality value for invalid strings" do result = Browser::AcceptLanguage.parse(";q=0.0.0.0") - assert_equal 0.1, result[0].quality + assert_equal 0.1, result[0].quality # rubocop:disable Minitest/AssertInDelta end end diff --git a/test/unit/facebook_test.rb b/test/unit/facebook_test.rb index 033b0b1c..79590461 100644 --- a/test/unit/facebook_test.rb +++ b/test/unit/facebook_test.rb @@ -8,7 +8,7 @@ class FacebookTest < Minitest::Test assert_equal "Facebook", browser.name assert browser.facebook? - assert :facebook, browser.id + assert_equal :facebook, browser.id assert_equal "135.0.0.45.90", browser.full_version assert_equal "135", browser.version end @@ -18,7 +18,7 @@ class FacebookTest < Minitest::Test assert_equal "Facebook", browser.name assert browser.facebook? - assert :facebook, browser.id + assert_equal :facebook, browser.id assert_equal "AppleWebKit/605.1.15", browser.full_version assert_equal "AppleWebKit/605", browser.version end @@ -28,7 +28,7 @@ class FacebookTest < Minitest::Test assert_equal "Facebook", browser.name assert browser.facebook? - assert :facebook, browser.id + assert_equal :facebook, browser.id assert_equal "214.0.0.43.83", browser.full_version assert_equal "214", browser.version end diff --git a/test/unit/instagram_test.rb b/test/unit/instagram_test.rb index 8e8a4b0c..d9ae5ad0 100644 --- a/test/unit/instagram_test.rb +++ b/test/unit/instagram_test.rb @@ -8,7 +8,7 @@ class InstagramTest < Minitest::Test assert_equal "Instagram", browser.name assert browser.instagram? - assert :instagram, browser.id + assert_equal :instagram, browser.id assert_equal "41.0.0.14.90", browser.full_version assert_equal "41", browser.version end @@ -18,7 +18,7 @@ class InstagramTest < Minitest::Test assert_equal "Instagram", browser.name assert browser.instagram? - assert :instagram, browser.id + assert_equal :instagram, browser.id assert_equal "182257141", browser.full_version assert_equal "182257141", browser.version end diff --git a/test/unit/internet_explorer_test.rb b/test/unit/internet_explorer_test.rb index 581178df..63be6a52 100644 --- a/test/unit/internet_explorer_test.rb +++ b/test/unit/internet_explorer_test.rb @@ -261,34 +261,34 @@ class IeTest < Minitest::Test browser = Browser.new(Browser["IE6"]) meta = browser.meta - assert meta.include?("ie") - assert meta.include?("ie6") - assert meta.include?("oldie") - assert meta.include?("lt-ie8") - assert meta.include?("lt-ie9") - assert meta.include?("windows") + assert_includes meta, "ie" + assert_includes meta, "ie6" + assert_includes meta, "oldie" + assert_includes meta, "lt-ie8" + assert_includes meta, "lt-ie9" + assert_includes meta, "windows" end test "returns string representation for ie7" do browser = Browser.new(Browser["IE7"]) meta = browser.meta - assert meta.include?("ie") - assert meta.include?("ie7") - assert meta.include?("oldie") - assert meta.include?("lt-ie8") - assert meta.include?("lt-ie9") - assert meta.include?("windows") + assert_includes meta, "ie" + assert_includes meta, "ie7" + assert_includes meta, "oldie" + assert_includes meta, "lt-ie8" + assert_includes meta, "lt-ie9" + assert_includes meta, "windows" end test "returns string representation for ie8" do browser = Browser.new(Browser["IE8"]) meta = browser.meta - assert meta.include?("ie") - assert meta.include?("ie8") - assert meta.include?("lt-ie9") - assert meta.include?("windows") + assert_includes meta, "ie" + assert_includes meta, "ie8" + assert_includes meta, "lt-ie9" + assert_includes meta, "windows" end test "does not detect as two different versions" do diff --git a/test/unit/ios_test.rb b/test/unit/ios_test.rb index 5d555584..20a635b0 100644 --- a/test/unit/ios_test.rb +++ b/test/unit/ios_test.rb @@ -119,22 +119,22 @@ class IosTest < Minitest::Test browser = Browser.new(Browser["IPHONE"]) meta = browser.to_s - assert meta.include?("webkit") - assert meta.include?("ios") - assert meta.include?("safari") - assert meta.include?("safari3") - assert meta.include?("mobile") - refute meta.include?("tablet") + assert_includes meta, "webkit" + assert_includes meta, "ios" + assert_includes meta, "safari" + assert_includes meta, "safari3" + assert_includes meta, "mobile" + refute_includes meta, "tablet" end test "returns string representation for ipad" do browser = Browser.new(Browser["IPAD"]) meta = browser.to_s - assert meta.include?("webkit") - assert meta.include?("ios") - assert meta.include?("safari") - assert meta.include?("tablet") - refute meta.include?("mobile") + assert_includes meta, "webkit" + assert_includes meta, "ios" + assert_includes meta, "safari" + assert_includes meta, "tablet" + refute_includes meta, "mobile" end end diff --git a/test/unit/meta_test.rb b/test/unit/meta_test.rb index 0e44c5dd..a4349409 100644 --- a/test/unit/meta_test.rb +++ b/test/unit/meta_test.rb @@ -5,7 +5,7 @@ class MetaTest < Minitest::Test class CustomRule < Browser::Meta::Base def meta - "custom" if /Custom/.match?(browser.ua) + "custom" if browser.ua.include?("Custom") end end @@ -13,15 +13,15 @@ def meta Browser::Meta.rules.unshift(CustomRule) browser = Browser.new("Custom") - assert browser.meta.include?("custom") + assert_includes browser.meta, "custom" browser = Browser.new("Safari") - refute browser.meta.include?("custom") + refute_includes browser.meta, "custom" Browser::Meta.rules.shift browser = Browser.new("Custom") - refute browser.meta.include?("custom") + refute_includes browser.meta, "custom" end test "sets meta" do @@ -33,25 +33,25 @@ def meta browser = Browser.new(Browser["CHROME"]) meta = browser.to_s - assert meta.include?("chrome") - assert meta.include?("webkit") - assert meta.include?("mac") + assert_includes meta, "chrome" + assert_includes meta, "webkit" + assert_includes meta, "mac" end test "returns string representation for mobile" do browser = Browser.new(Browser["BLACKBERRY"]) meta = browser.to_s - assert meta.include?("blackberry") - assert meta.include?("mobile") + assert_includes meta, "blackberry" + assert_includes meta, "mobile" end test "returns string representation for unknown platform/device/browser" do browser = Browser.new("Unknown") meta = browser.to_s - assert meta.include?("unknown_platform") - assert meta.include?("unknown_device") - assert meta.include?("unknown_browser") + assert_includes meta, "unknown_platform" + assert_includes meta, "unknown_device" + assert_includes meta, "unknown_browser" end end diff --git a/test/unit/platform_test.rb b/test/unit/platform_test.rb index b75605b6..32fa0a18 100644 --- a/test/unit/platform_test.rb +++ b/test/unit/platform_test.rb @@ -31,8 +31,8 @@ def id test "implements ==" do platform = Browser::Platform.new(Browser["IOS9"]) - assert platform == :ios - refute platform == :android + assert_operator platform, :==, :ios # rubocop:disable Minitest/AssertEqual + refute_equal platform, :android end test "detects unknown platforms" do diff --git a/test/unit/proxy_test.rb b/test/unit/proxy_test.rb index afedaafc..c9e8d366 100644 --- a/test/unit/proxy_test.rb +++ b/test/unit/proxy_test.rb @@ -14,7 +14,7 @@ class ProxyTest < Minitest::Test browser = Browser.new(ua) assert browser.proxy? - assert browser.meta.include?("proxy") + assert_includes browser.meta, "proxy" end end end diff --git a/test/unit/snapchat_test.rb b/test/unit/snapchat_test.rb index 8fd5ef94..033c5451 100644 --- a/test/unit/snapchat_test.rb +++ b/test/unit/snapchat_test.rb @@ -8,7 +8,7 @@ class SnapchatTest < Minitest::Test assert_equal "Snapchat", browser.name assert browser.snapchat? - assert :snapchat, browser.id + assert_equal :snapchat, browser.id assert_equal "10.69.5.72", browser.full_version assert_equal "10", browser.version end @@ -18,7 +18,7 @@ class SnapchatTest < Minitest::Test assert_equal "Snapchat", browser.name assert browser.snapchat? - assert :snapchat, browser.id + assert_equal :snapchat, browser.id assert_equal "10.70.0.0", browser.full_version assert_equal "10", browser.version end @@ -28,7 +28,7 @@ class SnapchatTest < Minitest::Test assert_equal "Snapchat", browser.name assert browser.snapchat? - assert :snapchat, browser.id + assert_equal :snapchat, browser.id assert_equal "10.70.0.0", browser.full_version assert_equal "10", browser.version end diff --git a/test/unit/uc_browser_test.rb b/test/unit/uc_browser_test.rb index 3847808c..ddc3111c 100644 --- a/test/unit/uc_browser_test.rb +++ b/test/unit/uc_browser_test.rb @@ -6,7 +6,7 @@ class UcBrowserTest < Minitest::Test test "detects UC Browser" do browser = Browser.new(Browser["UC_BROWSER"]) assert browser.uc_browser? - assert_equal browser.name, "UCBrowser" + assert_equal "UCBrowser", browser.name end test "detects version by range" do diff --git a/test/unit/windows_test.rb b/test/unit/windows_test.rb index 2e31551a..924d99bf 100644 --- a/test/unit/windows_test.rb +++ b/test/unit/windows_test.rb @@ -8,7 +8,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows_x64? refute browser.platform.windows_wow64? assert browser.platform.windows_x64_inclusive? - assert_equal browser.platform.version, "6.2" + assert_equal "6.2", browser.platform.version end test "detects windows wow64" do @@ -16,14 +16,14 @@ class WindowsTest < Minitest::Test refute browser.platform.windows_x64? assert browser.platform.windows_wow64? assert browser.platform.windows_x64_inclusive? - assert_equal browser.platform.version, "6.3" + assert_equal "6.3", browser.platform.version end test "detects windows_2000" do browser = Browser.new(Browser["WINDOWS_2000"]) assert browser.platform.windows? - assert_equal browser.platform.version, "5.0" + assert_equal "5.0", browser.platform.version assert browser.platform.windows?(["=5.0"]) end @@ -31,7 +31,7 @@ class WindowsTest < Minitest::Test browser = Browser.new(Browser["WINDOWS_2000_SP1"]) assert browser.platform.windows? - assert_equal browser.platform.version, "5.01" + assert_equal "5.01", browser.platform.version assert browser.platform.windows?(["=5.01"]) end @@ -40,7 +40,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows_xp? - assert_equal browser.platform.version, "5.1" + assert_equal "5.1", browser.platform.version assert browser.platform.windows?(["=5.1"]) end @@ -50,7 +50,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows_xp? assert browser.platform.windows_x64? - assert_equal browser.platform.version, "5.2" + assert_equal "5.2", browser.platform.version assert browser.platform.windows?(["=5.2"]) end @@ -59,7 +59,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows_vista? - assert_equal browser.platform.version, "6.0" + assert_equal "6.0", browser.platform.version assert browser.platform.windows?(["=6.0"]) end @@ -68,7 +68,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows7? - assert_equal browser.platform.version, "6.1" + assert_equal "6.1", browser.platform.version assert browser.platform.windows?(["=6.1"]) end @@ -78,7 +78,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows8? refute browser.platform.windows8_1? - assert_equal browser.platform.version, "6.2" + assert_equal "6.2", browser.platform.version assert browser.platform.windows?(["=6.2"]) end @@ -88,7 +88,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows8? assert browser.platform.windows8_1? - assert_equal browser.platform.version, "6.3" + assert_equal "6.3", browser.platform.version assert browser.platform.windows?(["=6.3"]) end @@ -97,7 +97,7 @@ class WindowsTest < Minitest::Test assert browser.platform.windows? assert browser.platform.windows10? - assert_equal browser.platform.version, "10.0" + assert_equal "10.0", browser.platform.version assert browser.platform.windows?(["=10.0"]) end