Sha256: 2d7905e54b43ae0ca1fec9a702dcff052cb8230c26faf5f01bbc49da8d3c1a85

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "test_helper"

class MetaTest < Minitest::Test
  class CustomRule < Browser::Meta::Base
    def meta
      "custom" if /Custom/.match?(browser.ua)
    end
  end

  test "extend rules" do
    Browser::Meta.rules.unshift(CustomRule)

    browser = Browser.new("Custom")
    assert browser.meta.include?("custom")

    browser = Browser.new("Safari")
    refute browser.meta.include?("custom")

    Browser::Meta.rules.shift

    browser = Browser.new("Custom")
    refute browser.meta.include?("custom")
  end

  test "sets meta" do
    browser = Browser.new(Browser["CHROME"])
    assert_kind_of Array, browser.meta
  end

  test "returns string representation" do
    browser = Browser.new(Browser["CHROME"])
    meta = browser.to_s

    assert meta.include?("chrome")
    assert meta.include?("webkit")
    assert meta.include?("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")
  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")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
browser-5.3.1 test/unit/meta_test.rb
browser-5.3.0 test/unit/meta_test.rb
browser-5.2.0 test/unit/meta_test.rb