browser 1.1.0 → 2.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +2 -0
  3. data/.hound.yml +26 -6
  4. data/.rubocop.yml +26 -6
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +177 -41
  7. data/Rakefile +1 -1
  8. data/bin/rake +16 -0
  9. data/bot_exceptions.yml +1 -0
  10. data/bots.yml +188 -192
  11. data/browser.gemspec +14 -28
  12. data/languages.yml +54 -54
  13. data/lib/browser.rb +82 -202
  14. data/lib/browser/accept_language.rb +47 -0
  15. data/lib/browser/action_controller.rb +1 -1
  16. data/lib/browser/base.rb +159 -0
  17. data/lib/browser/blackberry.rb +21 -0
  18. data/lib/browser/bot.rb +63 -0
  19. data/lib/browser/chrome.rb +23 -0
  20. data/lib/browser/detect_version.rb +19 -0
  21. data/lib/browser/device.rb +175 -0
  22. data/lib/browser/device/base.rb +11 -0
  23. data/lib/browser/device/blackberry_playbook.rb +17 -0
  24. data/lib/browser/device/ipad.rb +17 -0
  25. data/lib/browser/device/iphone.rb +17 -0
  26. data/lib/browser/device/ipod_touch.rb +17 -0
  27. data/lib/browser/device/kindle.rb +17 -0
  28. data/lib/browser/device/kindle_fire.rb +17 -0
  29. data/lib/browser/device/playstation3.rb +17 -0
  30. data/lib/browser/device/playstation4.rb +17 -0
  31. data/lib/browser/device/psp.rb +17 -0
  32. data/lib/browser/device/psvita.rb +17 -0
  33. data/lib/browser/device/surface.rb +23 -0
  34. data/lib/browser/device/tv.rb +17 -0
  35. data/lib/browser/device/unknown.rb +17 -0
  36. data/lib/browser/device/wii.rb +17 -0
  37. data/lib/browser/device/wiiu.rb +17 -0
  38. data/lib/browser/device/xbox_360.rb +17 -0
  39. data/lib/browser/device/xbox_one.rb +17 -0
  40. data/lib/browser/edge.rb +19 -0
  41. data/lib/browser/firefox.rb +19 -0
  42. data/lib/browser/generic.rb +32 -0
  43. data/lib/browser/internet_explorer.rb +61 -0
  44. data/lib/browser/meta/base.rb +1 -1
  45. data/lib/browser/meta/device.rb +9 -0
  46. data/lib/browser/meta/generic_browser.rb +1 -1
  47. data/lib/browser/meta/id.rb +1 -1
  48. data/lib/browser/meta/ie.rb +1 -1
  49. data/lib/browser/meta/ios.rb +2 -2
  50. data/lib/browser/meta/mobile.rb +2 -2
  51. data/lib/browser/meta/modern.rb +1 -1
  52. data/lib/browser/meta/platform.rb +2 -2
  53. data/lib/browser/meta/proxy.rb +1 -1
  54. data/lib/browser/meta/safari.rb +1 -1
  55. data/lib/browser/meta/tablet.rb +9 -0
  56. data/lib/browser/meta/webkit.rb +1 -1
  57. data/lib/browser/middleware.rb +1 -1
  58. data/lib/browser/middleware/context.rb +2 -2
  59. data/lib/browser/middleware/context/additions.rb +1 -1
  60. data/lib/browser/middleware/context/url_methods.rb +3 -3
  61. data/lib/browser/nokia.rb +19 -0
  62. data/lib/browser/opera.rb +19 -0
  63. data/lib/browser/phantom_js.rb +19 -0
  64. data/lib/browser/platform.rb +152 -0
  65. data/lib/browser/platform/adobe_air.rb +21 -0
  66. data/lib/browser/platform/android.rb +21 -0
  67. data/lib/browser/platform/base.rb +15 -0
  68. data/lib/browser/platform/blackberry.rb +21 -0
  69. data/lib/browser/platform/chrome_os.rb +21 -0
  70. data/lib/browser/platform/firefox_os.rb +21 -0
  71. data/lib/browser/platform/ios.rb +28 -0
  72. data/lib/browser/platform/linux.rb +21 -0
  73. data/lib/browser/platform/mac.rb +21 -0
  74. data/lib/browser/platform/other.rb +21 -0
  75. data/lib/browser/platform/windows.rb +21 -0
  76. data/lib/browser/platform/windows_mobile.rb +21 -0
  77. data/lib/browser/platform/windows_phone.rb +21 -0
  78. data/lib/browser/rails.rb +3 -2
  79. data/lib/browser/safari.rb +22 -0
  80. data/lib/browser/testing.rb +23 -0
  81. data/lib/browser/uc_browser.rb +19 -0
  82. data/lib/browser/version.rb +2 -7
  83. data/search_engines.yml +5 -5
  84. data/test/browser_test.rb +71 -172
  85. data/test/middleware_test.rb +7 -7
  86. data/test/sample_app.rb +3 -3
  87. data/test/test_helper.rb +11 -10
  88. data/test/ua.yml +15 -26
  89. data/test/ua_bots.yml +27 -0
  90. data/test/ua_search_engines.yml +6 -0
  91. data/test/unit/accept_language_test.rb +92 -0
  92. data/test/unit/adobe_air_test.rb +5 -10
  93. data/test/unit/android_test.rb +44 -49
  94. data/test/unit/blackberry_test.rb +55 -77
  95. data/test/unit/bots_test.rb +52 -84
  96. data/test/unit/chrome_test.rb +48 -42
  97. data/test/unit/console_test.rb +4 -62
  98. data/test/unit/device_test.rb +193 -0
  99. data/test/unit/firefox_test.rb +32 -27
  100. data/test/unit/ie_test.rb +223 -238
  101. data/test/unit/ios_app_test.rb +3 -3
  102. data/test/unit/ios_test.rb +87 -94
  103. data/test/unit/kindle_test.rb +10 -24
  104. data/test/unit/nokia_test.rb +3 -7
  105. data/test/unit/opera_test.rb +20 -30
  106. data/test/unit/platform_test.rb +161 -0
  107. data/test/unit/proxy_test.rb +3 -3
  108. data/test/unit/safari_test.rb +66 -0
  109. data/test/unit/uc_browser_test.rb +3 -7
  110. data/test/unit/windows_phone_test.rb +19 -40
  111. data/test/unit/windows_test.rb +32 -34
  112. metadata +73 -28
  113. data/lib/browser/methods/blackberry.rb +0 -51
  114. data/lib/browser/methods/bots.rb +0 -35
  115. data/lib/browser/methods/consoles.rb +0 -43
  116. data/lib/browser/methods/devices.rb +0 -41
  117. data/lib/browser/methods/ie.rb +0 -99
  118. data/lib/browser/methods/language.rb +0 -16
  119. data/lib/browser/methods/mobile.rb +0 -35
  120. data/lib/browser/methods/platform.rb +0 -152
  121. data/lib/browser/methods/proxy.rb +0 -8
  122. data/lib/browser/methods/tv.rb +0 -8
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class ChromeOS < Base
4
+ def match?
5
+ ua =~ /CrOS/
6
+ end
7
+
8
+ def name
9
+ "Chrome OS"
10
+ end
11
+
12
+ def id
13
+ :chrome_os
14
+ end
15
+
16
+ def version
17
+ ua[/CrOS(?: x86_64)? ([\d.]+)/, 1]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class FirefoxOS < Base
4
+ def version
5
+ "0"
6
+ end
7
+
8
+ def name
9
+ "Firefox OS"
10
+ end
11
+
12
+ def id
13
+ :firefox_os
14
+ end
15
+
16
+ def match?
17
+ ua !~ /(Android|Linux|BlackBerry|Windows|Mac)/ && ua =~ /Firefox/
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ module Browser
2
+ class Platform
3
+ class IOS < Base
4
+ MATCHER = /(iPhone|iPad|iPod)/
5
+ VERSION_MATCHER = /OS ([\d.]+)/
6
+
7
+ def version
8
+ ua[VERSION_MATCHER, 1] || "0"
9
+ end
10
+
11
+ def name
12
+ "iOS (#{device})"
13
+ end
14
+
15
+ def id
16
+ :ios
17
+ end
18
+
19
+ def match?
20
+ ua =~ MATCHER
21
+ end
22
+
23
+ def device
24
+ ua[MATCHER, 1]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class Linux < Base
4
+ def version
5
+ "0"
6
+ end
7
+
8
+ def name
9
+ "Generic Linux"
10
+ end
11
+
12
+ def id
13
+ :linux
14
+ end
15
+
16
+ def match?
17
+ ua =~ /Linux/
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class Mac < Base
4
+ def version
5
+ "0"
6
+ end
7
+
8
+ def name
9
+ "Macintosh"
10
+ end
11
+
12
+ def id
13
+ :mac
14
+ end
15
+
16
+ def match?
17
+ ua =~ /Mac/
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class Other < Base
4
+ def version
5
+ "0"
6
+ end
7
+
8
+ def name
9
+ "Other"
10
+ end
11
+
12
+ def id
13
+ :other
14
+ end
15
+
16
+ def match?
17
+ true
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class Windows < Base
4
+ def version
5
+ "0"
6
+ end
7
+
8
+ def name
9
+ "Windows"
10
+ end
11
+
12
+ def id
13
+ :windows
14
+ end
15
+
16
+ def match?
17
+ ua =~ /Windows/
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class WindowsMobile < Base
4
+ def version
5
+ "0"
6
+ end
7
+
8
+ def name
9
+ "Windows Mobile"
10
+ end
11
+
12
+ def id
13
+ :windows_mobile
14
+ end
15
+
16
+ def match?
17
+ ua =~ /Windows CE/
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class WindowsPhone < Base
4
+ def version
5
+ ua[/Windows Phone ([\d.]+)/, 1]
6
+ end
7
+
8
+ def name
9
+ "Windows Phone"
10
+ end
11
+
12
+ def id
13
+ :windows_phone
14
+ end
15
+
16
+ def match?
17
+ ua =~ /Windows Phone/
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,13 +2,14 @@ require "rails/railtie"
2
2
  require "browser/action_controller"
3
3
  require "browser/middleware/context/additions"
4
4
 
5
- class Browser
5
+ module Browser
6
6
  class Railtie < Rails::Railtie
7
7
  config.browser = ActiveSupport::OrderedOptions.new
8
8
 
9
9
  initializer "browser" do
10
10
  ::ActionController::Base.send :include, Browser::ActionController
11
- Browser::Middleware::Context.send :include, Browser::Middleware::Context::Additions
11
+ Browser::Middleware::Context.send :include,
12
+ Browser::Middleware::Context::Additions
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,22 @@
1
+ module Browser
2
+ class Safari < Base
3
+ def id
4
+ :safari
5
+ end
6
+
7
+ def name
8
+ "Safari"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[Version/([\d.]+)], 1] ||
13
+ ua[%r[Safari/([\d.]+)], 1] ||
14
+ ua[%r[AppleWebKit/([\d.]+)], 1] ||
15
+ "0.0"
16
+ end
17
+
18
+ def match?
19
+ !!(ua =~ /Safari/ && ua !~ /Chrome|CriOS|PhantomJS|FxiOS/)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Browser
2
+ def self.user_agents
3
+ @user_agents ||= browser_user_agents
4
+ .merge(bot_user_agents)
5
+ .merge(search_engine_user_agents)
6
+ end
7
+
8
+ def self.browser_user_agents
9
+ @browser_user_agents ||= YAML.load_file(Browser.root.join("test/ua.yml"))
10
+ end
11
+
12
+ def self.bot_user_agents
13
+ @bot_user_agents ||= YAML.load_file(Browser.root.join("test/ua_bots.yml"))
14
+ end
15
+
16
+ def self.search_engine_user_agents
17
+ @search_engine_user_agents ||= YAML.load_file(Browser.root.join("test/ua_search_engines.yml"))
18
+ end
19
+
20
+ def self.[](key)
21
+ user_agents.fetch(key)
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Browser
2
+ class UCBrowser < Base
3
+ def id
4
+ :uc_browser
5
+ end
6
+
7
+ def name
8
+ "UCBrowser"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[UCBrowser/([\d.]+)], 1]
13
+ end
14
+
15
+ def match?
16
+ ua =~ /UCBrowser/
17
+ end
18
+ end
19
+ end
@@ -1,8 +1,3 @@
1
- class Browser
2
- module Version
3
- MAJOR = 1
4
- MINOR = 1
5
- PATCH = 0
6
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
- end
1
+ module Browser
2
+ VERSION = "2.0.0.rc1"
8
3
  end
@@ -1,6 +1,6 @@
1
- Baidu: "Chinese search engine"
1
+ baidu: "Chinese search engine"
2
2
  bingbot: "Microsoft bing bot"
3
- Googlebot: "Google spider"
4
- Slurp: "Yahoo spider"
5
- DuckDuckBot: "Duck Duck Go"
6
- Ask Jeeves: "Ask Jeeves"
3
+ googlebot: "Google spider"
4
+ slurp: "Yahoo spider"
5
+ duckduckbot: "Duck Duck Go"
6
+ ask jeeves: "Ask Jeeves"
@@ -1,147 +1,88 @@
1
1
  require "test_helper"
2
2
 
3
3
  class BrowserTest < Minitest::Test
4
- setup do
5
- @browser = Browser.new
6
- end
7
-
8
- test "yields self when block is given" do
9
- browser = nil
10
- Browser.new {|b| browser = b }
11
- assert_kind_of Browser, browser
12
- end
13
-
14
- test "responds to ua methods" do
15
- assert @browser.respond_to?(:ua)
16
- assert @browser.respond_to?(:ua=)
17
- end
18
-
19
- test "delegates ua methods" do
20
- @browser.user_agent = "Safari"
21
- assert_equal "Safari", @browser.ua
22
-
23
- @browser.ua = "Mozilla"
24
- assert_equal "Mozilla", @browser.user_agent
25
- end
26
-
27
- test "sets accept language while instantiating object" do
28
- @browser = Browser.new(:accept_language => "pt-br")
29
- assert_equal ["pt-br"], @browser.accept_language
30
- end
31
-
32
4
  test "sets user agent while instantianting object" do
33
- @browser = Browser.new(:ua => "Safari")
34
- assert_equal "Safari", @browser.ua
35
-
36
- @browser = Browser.new(:user_agent => "Chrome")
37
- assert_equal "Chrome", @browser.ua
5
+ browser = Browser.new("Safari")
6
+ assert_equal "Safari", browser.ua
38
7
  end
39
8
 
40
9
  test "detects android" do
41
- @browser.ua = $ua["ANDROID"]
10
+ browser = Browser.new(Browser["ANDROID"])
42
11
 
43
- assert_equal "Android", @browser.name
44
- assert @browser.android?
45
- refute @browser.safari?
46
- assert @browser.webkit?
47
- assert @browser.mobile?
48
- refute @browser.tablet?
49
- assert @browser.modern?
50
- assert_equal "3.1.2", @browser.full_version
51
- assert_equal "3", @browser.version
12
+ assert_equal "Safari", browser.name
13
+ assert browser.platform.android?
14
+ assert browser.safari?
15
+ assert browser.webkit?
16
+ assert browser.modern?
17
+ assert_equal "3.1.2", browser.full_version
18
+ assert_equal "3", browser.version
52
19
  end
53
20
 
54
21
  test "detects android tablet" do
55
- @browser.ua = $ua["TABLOID"]
22
+ browser = Browser.new(Browser["TABLOID"])
56
23
 
57
- assert_equal "Android", @browser.name
58
- assert @browser.android?
59
- refute @browser.safari?
60
- assert @browser.webkit?
61
- refute @browser.mobile?
62
- assert @browser.tablet?
63
- assert @browser.modern?
64
- assert_equal "4.0", @browser.full_version
65
- assert_equal "4", @browser.version
24
+ assert_equal "Safari", browser.name
25
+ assert browser.platform.android?
26
+ assert browser.safari?
27
+ assert browser.webkit?
28
+ assert browser.modern?
29
+ assert_equal "4.0", browser.full_version
30
+ assert_equal "4", browser.version
66
31
  end
67
32
 
68
33
  test "detects surface tablet" do
69
- @browser.ua = $ua["SURFACE"]
34
+ browser = Browser.new(Browser["SURFACE"])
70
35
 
71
- assert_equal "Internet Explorer", @browser.name
72
- assert @browser.surface?
73
- assert @browser.ie?
74
- refute @browser.mobile?
75
- assert @browser.tablet?
76
- assert @browser.modern?
77
- assert_equal "10.0", @browser.full_version
78
- assert_equal "10", @browser.version
36
+ assert_equal "Internet Explorer", browser.name
37
+ assert browser.device.surface?
38
+ assert browser.ie?
39
+ assert browser.modern?
40
+ assert_equal "10.0", browser.full_version
41
+ assert_equal "10", browser.version
79
42
  end
80
43
 
81
44
  test "detects quicktime" do
82
- @browser.ua = $ua["QUICKTIME"]
45
+ browser = Browser.new(Browser["QUICKTIME"])
83
46
 
84
- assert_equal "QuickTime", @browser.name
85
- assert @browser.quicktime?
86
- assert_equal "7.6.8", @browser.full_version
87
- assert_equal "7", @browser.version
47
+ assert_equal "QuickTime", browser.name
48
+ assert browser.quicktime?
49
+ assert_equal "7.6.8", browser.full_version
50
+ assert_equal "7", browser.version
88
51
  end
89
52
 
90
53
  test "detects core media" do
91
- @browser.ua = $ua["COREMEDIA"]
54
+ browser = Browser.new(Browser["COREMEDIA"])
92
55
 
93
- assert_equal "Apple CoreMedia", @browser.name
94
- assert @browser.core_media?
95
- assert_equal "1.0.0.10F569", @browser.full_version
96
- assert_equal "1", @browser.version
56
+ assert_equal "Apple CoreMedia", browser.name
57
+ assert browser.core_media?
58
+ assert_equal "1.0.0.10", browser.full_version
59
+ assert_equal "1", browser.version
97
60
  end
98
61
 
99
62
  test "detects phantom.js" do
100
- @browser.ua = $ua["PHANTOM_JS"]
63
+ browser = Browser.new(Browser["PHANTOM_JS"])
101
64
 
102
- assert_equal "PhantomJS", @browser.name
103
- assert @browser.phantom_js?
104
- refute @browser.tablet?
105
- refute @browser.mobile?
106
- assert @browser.modern?
107
- assert_equal "1.9.0", @browser.full_version
108
- assert_equal "1", @browser.version
109
- end
110
-
111
- test "detects other mobiles" do
112
- @browser.ua = "Symbian OS"
113
- assert @browser.mobile?
114
- refute @browser.tablet?
115
-
116
- @browser.ua = "MIDP-2.0"
117
- assert @browser.mobile?
118
- refute @browser.tablet?
119
- end
120
-
121
- test "detects windows mobile" do
122
- @browser.ua = $ua["WINDOWS_MOBILE"]
123
-
124
- assert @browser.mobile?
125
- assert @browser.windows?
126
- assert @browser.windows_mobile?
127
- refute @browser.windows_phone?
128
- refute @browser.tablet?
65
+ assert_equal "PhantomJS", browser.name
66
+ assert browser.phantom_js?
67
+ assert browser.modern?
68
+ assert_equal "1.9.0", browser.full_version
69
+ assert_equal "1", browser.version
129
70
  end
130
71
 
131
72
  test "returns a zero version" do
132
- @browser.ua = "Bot"
133
- assert_equal "0.0", @browser.full_version
134
- assert_equal "0", @browser.version
73
+ browser = Browser.new("Bot")
74
+ assert_equal "0.0", browser.full_version
75
+ assert_equal "0", browser.version
135
76
  end
136
77
 
137
78
  test "sets meta" do
138
- @browser.ua = $ua["CHROME"]
139
- assert_kind_of Array, @browser.meta
79
+ browser = Browser.new(Browser["CHROME"])
80
+ assert_kind_of Array, browser.meta
140
81
  end
141
82
 
142
83
  test "returns string representation" do
143
- @browser.ua = $ua["CHROME"]
144
- meta = @browser.to_s
84
+ browser = Browser.new(Browser["CHROME"])
85
+ meta = browser.to_s
145
86
 
146
87
  assert meta.include?("chrome")
147
88
  assert meta.include?("webkit")
@@ -150,99 +91,57 @@ class BrowserTest < Minitest::Test
150
91
  end
151
92
 
152
93
  test "returns string representation for mobile" do
153
- @browser.ua = $ua["BLACKBERRY"]
154
- meta = @browser.to_s
94
+ browser = Browser.new(Browser["BLACKBERRY"])
95
+ meta = browser.to_s
155
96
 
156
97
  assert meta.include?("blackberry")
157
- assert meta.include?("blackberry4")
158
- assert meta.include?("other")
159
98
  assert meta.include?("mobile")
160
99
  end
161
100
 
162
101
  test "detects unknown id" do
163
- @browser.ua = "Unknown"
164
- assert_equal :other, @browser.id
102
+ browser = Browser.new("Unknown")
103
+ assert_equal :generic, browser.id
165
104
  end
166
105
 
167
106
  test "detects unknown name" do
168
- @browser.ua = "Unknown"
169
- assert_equal "Other", @browser.name
107
+ browser = Browser.new("Unknown")
108
+ assert_equal "Generic Browser", browser.name
170
109
  end
171
110
 
172
- test "detects mac platform" do
173
- @browser.ua = "Mac OS X"
174
- assert_equal :mac, @browser.platform
175
- assert @browser.mac?
111
+ test "returns empty language set for missing accept language" do
112
+ browser = Browser.new("")
113
+ assert_equal [], browser.accept_language
176
114
  end
177
115
 
178
- test "detects linux platform" do
179
- @browser.ua = "Linux"
180
- assert_equal :linux, @browser.platform
181
- assert @browser.linux?
182
- end
116
+ test "sets accept language while instantiating object" do
117
+ browser = Browser.new("", accept_language: "pt-br")
183
118
 
184
- test "detects unknown platform" do
185
- @browser.ua = "Unknown"
186
- assert_equal :other, @browser.platform
119
+ assert_kind_of Array, browser.accept_language
120
+ assert_equal ["pt-BR"], browser.accept_language.map(&:full)
187
121
  end
188
122
 
189
123
  test "returns all known languages" do
190
- @browser.accept_language = "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3"
191
- assert_equal ["en-us", "en", "pt-br", "pt"], @browser.accept_language
192
- end
193
-
194
- test "detects xoom" do
195
- @browser.ua = $ua["XOOM"]
196
-
197
- assert @browser.android?
198
- assert @browser.tablet?
199
- refute @browser.mobile?
200
- end
201
-
202
- test "detects nexus tablet" do
203
- @browser.ua = $ua["NEXUS_TABLET"]
204
-
205
- assert @browser.android?
206
- assert @browser.tablet?
207
- refute @browser.mobile?
208
- end
209
-
210
- test "detects nook" do
211
- @browser.ua = $ua["NOOK"]
212
-
213
- assert @browser.tablet?
214
- refute @browser.mobile?
215
- end
216
-
217
- test "detects samsung" do
218
- @browser.ua = $ua["SAMSUNG"]
219
-
220
- assert @browser.tablet?
221
- refute @browser.mobile?
124
+ browser = Browser.new("", accept_language: "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3")
125
+ assert_equal ["en-US", "en", "pt-BR", "pt"], browser.accept_language.map(&:full)
222
126
  end
223
127
 
224
128
  test "removes duplicate items" do
225
- @browser.ua = $ua["SAFARI"]
226
- assert_equal ["safari"], @browser.meta.select {|item| item == "safari" }
129
+ browser = Browser.new(Browser["SAFARI"])
130
+ assert_equal ["safari"], browser.meta.select {|item| item == "safari" }
227
131
  end
228
132
 
229
133
  test "detects meta aliased as to_a" do
230
- @browser.ua = $ua["SAFARI"]
231
- assert_equal @browser.meta, @browser.to_a
232
- end
233
-
234
- test "detects tv" do
235
- @browser.ua = $ua["SMART_TV"]
236
- assert @browser.tv?
134
+ browser = Browser.new(Browser["SAFARI"])
135
+ assert_equal browser.meta, browser.to_a
237
136
  end
238
137
 
239
138
  test "knows a supported browser" do
240
- @browser.ua = "Chrome"
241
- assert @browser.known?
139
+ browser = Browser.new("Chrome")
140
+ assert browser.known?
242
141
  end
243
142
 
244
143
  test "does not know an unsupported browser" do
245
- @browser.ua = "Fancy new browser"
246
- refute @browser.known?
144
+ browser = Browser.new("Fancy new browser")
145
+ refute browser.known?
247
146
  end
248
147
  end