Skip to content

Commit

Permalink
Fix rubocop violations.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Apr 30, 2024
1 parent fa4f685 commit 4bb0b89
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 82 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ruby-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ AllCops:

Naming/VariableNumber:
Enabled: false

Minitest/EmptyLineBeforeAssertionMethods:
Enabled: false
9 changes: 4 additions & 5 deletions browser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions gemfiles/6_1.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/6_0.gemfile → gemfiles/7_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source "https://rubygems.org"
gemspec path: ".."

gem "rails", "~> 6.0.0"
gem "rails", "~> 7.1.0"
2 changes: 1 addition & 1 deletion lib/browser.rb
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion lib/browser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/browser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/unit/accept_language_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/unit/facebook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/instagram_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
32 changes: 16 additions & 16 deletions test/unit/internet_explorer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions test/unit/ios_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 12 additions & 12 deletions test/unit/meta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
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

test "extends rules" do
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
Expand All @@ -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
4 changes: 2 additions & 2 deletions test/unit/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/unit/snapchat_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/uc_browser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4bb0b89

Please sign in to comment.