File: meta_test.rb

package info (click to toggle)
ruby-browser 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: ruby: 4,845; makefile: 13
file content (57 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require "test_helper"

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

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

    browser = Browser.new("Custom")
    assert_includes browser.meta, "custom"

    browser = Browser.new("Safari")
    refute_includes browser.meta, "custom"

    Browser::Meta.rules.shift

    browser = Browser.new("Custom")
    refute_includes browser.meta, "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_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_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_includes meta, "unknown_platform"
    assert_includes meta, "unknown_device"
    assert_includes meta, "unknown_browser"
  end
end