device_detector 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +5 -5
- data/lib/device_detector/device.rb +82 -3
- data/lib/device_detector/os.rb +4 -2
- data/lib/device_detector/parser.rb +1 -1
- data/lib/device_detector/version.rb +1 -1
- data/lib/device_detector/version_extractor.rb +20 -1
- data/regexes/bots.yml +49 -6
- data/regexes/client/browsers.yml +170 -16
- data/regexes/client/libraries.yml +20 -1
- data/regexes/client/mediaplayers.yml +2 -2
- data/regexes/client/mobile_apps.yml +447 -13
- data/regexes/client/pim.yml +16 -1
- data/regexes/device/consoles.yml +7 -1
- data/regexes/device/mobiles.yml +3169 -912
- data/regexes/device/portable_media_player.yml +16 -6
- data/regexes/oss.yml +380 -467
- metadata +3 -164
- data/.gitignore +0 -14
- data/.rubocop.yml +0 -49
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/Gemfile +0 -8
- data/Rakefile +0 -86
- data/device_detector.gemspec +0 -27
- data/spec/device_detector/bot_fixtures_spec.rb +0 -30
- data/spec/device_detector/client_fixtures_spec.rb +0 -31
- data/spec/device_detector/concrete_user_agent_spec.rb +0 -123
- data/spec/device_detector/detector_fixtures_spec.rb +0 -99
- data/spec/device_detector/device_fixtures_spec.rb +0 -36
- data/spec/device_detector/device_spec.rb +0 -147
- data/spec/device_detector/memory_cache_spec.rb +0 -148
- data/spec/device_detector/model_extractor_spec.rb +0 -63
- data/spec/device_detector/os_fixtures_spec.rb +0 -26
- data/spec/device_detector/version_extractor_spec.rb +0 -79
- data/spec/device_detector_spec.rb +0 -189
- data/spec/fixtures/client/browser.yml +0 -3935
- data/spec/fixtures/client/feed_reader.yml +0 -187
- data/spec/fixtures/client/library.yml +0 -253
- data/spec/fixtures/client/mediaplayer.yml +0 -193
- data/spec/fixtures/client/mobile_app.yml +0 -703
- data/spec/fixtures/client/pim.yml +0 -175
- data/spec/fixtures/detector/bots.yml +0 -4434
- data/spec/fixtures/detector/camera.yml +0 -127
- data/spec/fixtures/detector/car_browser.yml +0 -217
- data/spec/fixtures/detector/console.yml +0 -343
- data/spec/fixtures/detector/desktop.yml +0 -7580
- data/spec/fixtures/detector/feature_phone.yml +0 -1597
- data/spec/fixtures/detector/feed_reader.yml +0 -524
- data/spec/fixtures/detector/mediaplayer.yml +0 -306
- data/spec/fixtures/detector/mobile_apps.yml +0 -1233
- data/spec/fixtures/detector/peripheral.yml +0 -271
- data/spec/fixtures/detector/phablet.yml +0 -7366
- data/spec/fixtures/detector/portable_media_player.yml +0 -527
- data/spec/fixtures/detector/smart_display.yml +0 -235
- data/spec/fixtures/detector/smart_speaker.yml +0 -60
- data/spec/fixtures/detector/smartphone-1.yml +0 -9622
- data/spec/fixtures/detector/smartphone-10.yml +0 -8981
- data/spec/fixtures/detector/smartphone-11.yml +0 -8938
- data/spec/fixtures/detector/smartphone-12.yml +0 -8989
- data/spec/fixtures/detector/smartphone-13.yml +0 -9412
- data/spec/fixtures/detector/smartphone-14.yml +0 -9477
- data/spec/fixtures/detector/smartphone-15.yml +0 -9281
- data/spec/fixtures/detector/smartphone-16.yml +0 -9678
- data/spec/fixtures/detector/smartphone-17.yml +0 -9965
- data/spec/fixtures/detector/smartphone-18.yml +0 -9806
- data/spec/fixtures/detector/smartphone-19.yml +0 -9965
- data/spec/fixtures/detector/smartphone-2.yml +0 -12242
- data/spec/fixtures/detector/smartphone-20.yml +0 -9710
- data/spec/fixtures/detector/smartphone-21.yml +0 -8693
- data/spec/fixtures/detector/smartphone-22.yml +0 -10178
- data/spec/fixtures/detector/smartphone-23.yml +0 -9453
- data/spec/fixtures/detector/smartphone-24.yml +0 -9843
- data/spec/fixtures/detector/smartphone-25.yml +0 -9703
- data/spec/fixtures/detector/smartphone-26.yml +0 -10007
- data/spec/fixtures/detector/smartphone-27.yml +0 -4927
- data/spec/fixtures/detector/smartphone-3.yml +0 -9909
- data/spec/fixtures/detector/smartphone-4.yml +0 -8954
- data/spec/fixtures/detector/smartphone-5.yml +0 -8981
- data/spec/fixtures/detector/smartphone-6.yml +0 -8948
- data/spec/fixtures/detector/smartphone-7.yml +0 -8975
- data/spec/fixtures/detector/smartphone-8.yml +0 -9810
- data/spec/fixtures/detector/smartphone-9.yml +0 -8925
- data/spec/fixtures/detector/smartphone.yml +0 -9001
- data/spec/fixtures/detector/tablet-1.yml +0 -10155
- data/spec/fixtures/detector/tablet-2.yml +0 -9064
- data/spec/fixtures/detector/tablet-3.yml +0 -9035
- data/spec/fixtures/detector/tablet-4.yml +0 -9062
- data/spec/fixtures/detector/tablet-5.yml +0 -9273
- data/spec/fixtures/detector/tablet-6.yml +0 -4588
- data/spec/fixtures/detector/tablet.yml +0 -8979
- data/spec/fixtures/detector/tv-1.yml +0 -2501
- data/spec/fixtures/detector/tv.yml +0 -10045
- data/spec/fixtures/detector/unknown.yml +0 -3071
- data/spec/fixtures/detector/wearable.yml +0 -915
- data/spec/fixtures/device/camera.yml +0 -19
- data/spec/fixtures/device/car_browser.yml +0 -13
- data/spec/fixtures/device/console.yml +0 -79
- data/spec/fixtures/device/notebook.yml +0 -7
- data/spec/fixtures/parser/oss.yml +0 -2418
- data/spec/fixtures/parser/vendorfragments.yml +0 -168
- data/spec/spec_helper.rb +0 -9
@@ -1,99 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe DeviceDetector do
|
4
|
-
fixture_dir = File.expand_path('../fixtures/detector', __dir__)
|
5
|
-
fixture_files = Dir["#{fixture_dir}/*.yml"]
|
6
|
-
fixture_files.each do |fixture_file|
|
7
|
-
describe File.basename(fixture_file) do
|
8
|
-
fixtures = nil
|
9
|
-
begin
|
10
|
-
fixtures = YAML.load(File.read(fixture_file))
|
11
|
-
rescue Psych::SyntaxError => e
|
12
|
-
raise "Failed to parse #{fixture_file}, reason: #{e}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def str_or_nil(string)
|
16
|
-
return nil if string.nil?
|
17
|
-
return nil if string == ''
|
18
|
-
|
19
|
-
string.to_s
|
20
|
-
end
|
21
|
-
|
22
|
-
fixtures.each do |f|
|
23
|
-
user_agent = f['user_agent']
|
24
|
-
detector = DeviceDetector.new(user_agent)
|
25
|
-
os = detector.send(:os)
|
26
|
-
|
27
|
-
describe user_agent do
|
28
|
-
it 'should be detected' do
|
29
|
-
if detector.bot?
|
30
|
-
assert_equal str_or_nil(f['bot']['name']), detector.bot_name,
|
31
|
-
'failed bot name detection'
|
32
|
-
else
|
33
|
-
if f['client']
|
34
|
-
assert_equal str_or_nil(f['client']['name']), detector.name,
|
35
|
-
'failed client name detection'
|
36
|
-
end
|
37
|
-
|
38
|
-
os_family = str_or_nil(f['os_family'])
|
39
|
-
if os_family != 'Unknown'
|
40
|
-
if os_family.nil?
|
41
|
-
assert_nil os.family, 'failed os family detection'
|
42
|
-
else
|
43
|
-
assert_equal os_family, os.family, 'failed os family detection'
|
44
|
-
end
|
45
|
-
|
46
|
-
name = str_or_nil(f['os']['name'])
|
47
|
-
if name.nil?
|
48
|
-
assert_nil os.name, 'failed os name detection'
|
49
|
-
else
|
50
|
-
assert_equal name, os.name, 'failed os name detection'
|
51
|
-
end
|
52
|
-
|
53
|
-
short_name = str_or_nil(f['os']['short_name'])
|
54
|
-
if short_name.nil? && f['os']['name']
|
55
|
-
short_name = DeviceDetector::OS::OPERATING_SYSTEMS[f['os']['name']]
|
56
|
-
end
|
57
|
-
|
58
|
-
unless short_name.nil?
|
59
|
-
assert_equal short_name, os.short_name, 'failed os short name detection'
|
60
|
-
end
|
61
|
-
|
62
|
-
os_version = str_or_nil(f['os']['version'])
|
63
|
-
if os_version.nil?
|
64
|
-
assert_nil os.full_version, 'failed os version detection'
|
65
|
-
else
|
66
|
-
assert_equal os_version, os.full_version, 'failed os version detection'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
if f['device']
|
70
|
-
expected_type = str_or_nil(f['device']['type'])
|
71
|
-
actual_type = detector.device_type
|
72
|
-
|
73
|
-
if expected_type != actual_type
|
74
|
-
# puts "\n", f.inspect, expected_type, actual_type, detector.device_name, regex_meta.inspect
|
75
|
-
# debugger
|
76
|
-
# detector.device_type
|
77
|
-
end
|
78
|
-
if expected_type.nil?
|
79
|
-
assert_nil actual_type, 'failed device type detection'
|
80
|
-
else
|
81
|
-
assert_equal expected_type, actual_type, 'failed device type detection'
|
82
|
-
end
|
83
|
-
|
84
|
-
model = str_or_nil(f['device']['model'])
|
85
|
-
model = model.to_s unless model.nil?
|
86
|
-
|
87
|
-
if model.nil?
|
88
|
-
assert_nil detector.device_name, 'failed device name detection'
|
89
|
-
else
|
90
|
-
assert_equal model, detector.device_name, 'failed device name detection'
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe DeviceDetector::Device do
|
4
|
-
|
5
|
-
fixture_dir = File.expand_path('../../fixtures/devices', __FILE__)
|
6
|
-
fixture_files = Dir["#{fixture_dir}/*.yml"]
|
7
|
-
fixture_files.each do |fixture_file|
|
8
|
-
|
9
|
-
describe File.basename(fixture_file) do
|
10
|
-
|
11
|
-
fixtures = YAML.load_file(fixture_file)
|
12
|
-
fixtures.each do |f|
|
13
|
-
|
14
|
-
user_agent = f["user_agent"]
|
15
|
-
device = DeviceDetector::Device.new(user_agent)
|
16
|
-
|
17
|
-
describe user_agent do
|
18
|
-
|
19
|
-
it "should be known" do
|
20
|
-
assert device.known?, "isn't known as a device"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should have the expected model" do
|
24
|
-
assert_equal f["device"]["model"], device.name, "failed model detection"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should have the expected type" do
|
28
|
-
expected_device_type = DeviceDetector::Device::DEVICE_NAMES[f["device"]["type"]]
|
29
|
-
assert_equal expected_device_type, device.type, "failed device name detection"
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../spec_helper'
|
4
|
-
|
5
|
-
describe DeviceDetector::Device do
|
6
|
-
subject { DeviceDetector::Device.new(user_agent) }
|
7
|
-
|
8
|
-
alias_method :device, :subject
|
9
|
-
|
10
|
-
describe '#name' do
|
11
|
-
describe 'when models are nested' do
|
12
|
-
let(:user_agent) do
|
13
|
-
'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]'
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'finds an Apple iPhone 6' do
|
17
|
-
value(device.name).must_equal 'iPhone 6'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'when models are NOT nested' do
|
22
|
-
let(:user_agent) { 'AIRNESS-AIR99/REV 2.2.1/Teleca Q03B1' }
|
23
|
-
|
24
|
-
it 'finds an Airness AIR99' do
|
25
|
-
value(device.name).must_equal 'AIR99'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'when it cannot find a device name' do
|
30
|
-
let(:user_agent) { 'UNKNOWN MODEL NAME' }
|
31
|
-
|
32
|
-
it 'returns nil' do
|
33
|
-
value(device.name).must_be_nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#type' do
|
39
|
-
describe 'when models are nested' do
|
40
|
-
let(:user_agent) do
|
41
|
-
'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]'
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'finds device of Apple iPhone 6' do
|
45
|
-
value(device.type).must_equal 'smartphone'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'when models are NOT nested' do
|
50
|
-
let(:user_agent) { 'AIRNESS-AIR99/REV 2.2.1/Teleca Q03B1' }
|
51
|
-
|
52
|
-
it 'finds the device of Airness AIR99' do
|
53
|
-
value(device.type).must_equal 'feature phone'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe 'when it cannot find a device type' do
|
58
|
-
let(:user_agent) { 'UNKNOWN MODEL TYPE' }
|
59
|
-
|
60
|
-
it 'returns nil' do
|
61
|
-
value(device.type).must_be_nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'device not specified in nested block' do
|
66
|
-
let(:user_agent) do
|
67
|
-
'Mozilla/5.0 (Linux; Android 4.4.2; es-us; SAMSUNG SM-G900F Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko)'
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'falls back to top-level device' do
|
71
|
-
value(device.type).must_equal 'smartphone'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'concrete device types' do
|
77
|
-
describe 'mobiles' do
|
78
|
-
let(:user_agent) do
|
79
|
-
'Mozilla/5.0 (Linux; Android 4.4.2; es-us; SAMSUNG SM-G900F Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko)'
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'identifies the device' do
|
83
|
-
value(device.name).must_equal 'Galaxy S5'
|
84
|
-
value(device.type).must_equal 'smartphone'
|
85
|
-
value(device.brand).must_equal 'Samsung'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'cameras' do
|
90
|
-
let(:user_agent) do
|
91
|
-
'Mozilla/5.0 (Linux; U; Android 4.0; xx-xx; EK-GC100 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'identifies the device' do
|
95
|
-
value(device.name).must_equal 'Galaxy Camera'
|
96
|
-
value(device.type).must_equal 'camera'
|
97
|
-
value(device.brand).must_equal 'Samsung'
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'car browsers' do
|
102
|
-
let(:user_agent) do
|
103
|
-
'Mozilla/5.0 (X11; Linux) AppleWebKit/534.34 (KHTML, like Gecko) QtCarBrowser Safari/534.34'
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'identifies the device' do
|
107
|
-
value(device.name).must_equal 'Model S'
|
108
|
-
value(device.type).must_equal 'car browser'
|
109
|
-
value(device.brand).must_equal 'Tesla'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe '(gaming) consoles' do
|
114
|
-
let(:user_agent) { 'Opera/9.30 (Nintendo Wii; U; ; 2047-7;en)' }
|
115
|
-
|
116
|
-
it 'identifies the device' do
|
117
|
-
value(device.name).must_equal 'Wii'
|
118
|
-
value(device.type).must_equal 'console'
|
119
|
-
value(device.brand).must_be_nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe 'portable media players' do
|
124
|
-
let(:user_agent) do
|
125
|
-
'Mozilla/5.0 (iPod touch; CPU iPhone OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B651 Safari/9537.53'
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'identifies the device' do
|
129
|
-
value(device.name).must_equal 'iPod Touch'
|
130
|
-
value(device.type).must_equal 'portable media player'
|
131
|
-
value(device.brand).must_equal 'Apple'
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe 'televisions' do
|
136
|
-
let(:user_agent) do
|
137
|
-
'Mozilla/5.0 (Unknown; Linux armv7l) AppleWebKit/537.1+ (KHTML, like Gecko) Safari/537.1+ HbbTV/1.1.1 ( ;LGE ;NetCast 4.0 ;03.10.81 ;1.0M ;)'
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'identifies the device' do
|
141
|
-
value(device.name).must_equal 'NetCast 4.0'
|
142
|
-
value(device.type).must_equal 'tv'
|
143
|
-
value(device.brand).must_equal 'LG'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../spec_helper'
|
4
|
-
|
5
|
-
describe DeviceDetector::MemoryCache do
|
6
|
-
let(:subject) { DeviceDetector::MemoryCache.new(config) }
|
7
|
-
|
8
|
-
let(:config) { {} }
|
9
|
-
|
10
|
-
describe '#set' do
|
11
|
-
describe 'string key' do
|
12
|
-
let(:key) { 'string' }
|
13
|
-
|
14
|
-
it 'sets the value under the key' do
|
15
|
-
subject.set(key, 'value')
|
16
|
-
|
17
|
-
value(subject.data[key]).must_equal 'value'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns the value' do
|
21
|
-
value(subject.set(key, 'value')).must_equal 'value'
|
22
|
-
value(subject.set(key, false)).must_equal false
|
23
|
-
assert_nil subject.set(key, nil)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'array key' do
|
28
|
-
let(:key) { %w[string1 string2] }
|
29
|
-
|
30
|
-
it 'sets the value under the key' do
|
31
|
-
subject.set(key, 'value')
|
32
|
-
|
33
|
-
value(subject.data[String(key)]).must_equal 'value'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'nil value' do
|
38
|
-
let(:key) { 'string' }
|
39
|
-
let(:internal_value) { DeviceDetector::MemoryCache::STORES_NIL_VALUE }
|
40
|
-
|
41
|
-
it 'sets the value under the key' do
|
42
|
-
subject.set(key, nil)
|
43
|
-
|
44
|
-
value(subject.data[String(key)]).must_equal internal_value
|
45
|
-
assert_nil subject.get(key)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'sets the value under the key' do
|
49
|
-
subject.get_or_set(key, nil)
|
50
|
-
|
51
|
-
value(subject.data[String(key)]).must_equal internal_value
|
52
|
-
assert_nil subject.get(key)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'false value' do
|
57
|
-
let(:key) { 'string' }
|
58
|
-
|
59
|
-
it 'sets the value under the key' do
|
60
|
-
subject.set(key, false)
|
61
|
-
|
62
|
-
value(subject.data[String(key)]).must_equal false
|
63
|
-
value(subject.get(key)).must_equal false
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'sets the value under the key' do
|
67
|
-
subject.get_or_set(key, false)
|
68
|
-
|
69
|
-
value(subject.data[String(key)]).must_equal false
|
70
|
-
value(subject.get(key)).must_equal false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#get' do
|
76
|
-
describe 'string key' do
|
77
|
-
let(:key) { 'string' }
|
78
|
-
|
79
|
-
it 'gets the value for the key' do
|
80
|
-
subject.data[key] = 'value'
|
81
|
-
|
82
|
-
value(subject.get(key)).must_equal 'value'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'array key' do
|
87
|
-
let(:key) { %w[string1 string2] }
|
88
|
-
|
89
|
-
it 'gets the value for the key' do
|
90
|
-
subject.data[String(key)] = 'value'
|
91
|
-
|
92
|
-
value(subject.get(key)).must_equal 'value'
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe '#get_or_set' do
|
98
|
-
let(:key) { 'string' }
|
99
|
-
|
100
|
-
describe 'value already present' do
|
101
|
-
it 'gets the value for the key from cache' do
|
102
|
-
subject.data[key] = 'value'
|
103
|
-
|
104
|
-
block_called = false
|
105
|
-
value = subject.get_or_set(key) do
|
106
|
-
block_called = true
|
107
|
-
end
|
108
|
-
|
109
|
-
value(value).must_equal 'value'
|
110
|
-
value(block_called).must_equal false
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'returns the value' do
|
114
|
-
subject.data[key] = 'value2'
|
115
|
-
value(subject.get_or_set(key, 'value')).must_equal 'value2'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe 'value not yet present' do
|
120
|
-
it 'evaluates the block and sets the result' do
|
121
|
-
block_called = false
|
122
|
-
subject.get_or_set(key) do
|
123
|
-
block_called = true
|
124
|
-
end
|
125
|
-
|
126
|
-
value(block_called).must_equal true
|
127
|
-
value(subject.data[key]).must_equal true
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'returns the value' do
|
131
|
-
value(subject.get_or_set(key, 'value')).must_equal 'value'
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe 'cache purging' do
|
137
|
-
let(:config) { { max_cache_keys: 3 } }
|
138
|
-
|
139
|
-
it 'purges the cache when key size arrives at max' do
|
140
|
-
subject.set('1', 'foo')
|
141
|
-
subject.set('2', 'bar')
|
142
|
-
subject.set('3', 'baz')
|
143
|
-
subject.set('4', 'boz')
|
144
|
-
|
145
|
-
value(subject.data.keys.size).must_equal 3
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe DeviceDetector::ModelExtractor do
|
4
|
-
|
5
|
-
subject { DeviceDetector::ModelExtractor.new(user_agent, regex_meta) }
|
6
|
-
|
7
|
-
alias :extractor :subject
|
8
|
-
|
9
|
-
describe '#call' do
|
10
|
-
|
11
|
-
describe 'when matching against dynamic model' do
|
12
|
-
|
13
|
-
let(:regex_meta) do
|
14
|
-
{
|
15
|
-
:regex => '(?:Apple-)?iPhone ?(3GS?|4S?|5[CS]?|6(:? Plus)?)?',
|
16
|
-
:model => 'iPhone $1',
|
17
|
-
:device => 'smartphone'
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'when no dynamic match is found' do
|
22
|
-
let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4' }
|
23
|
-
let(:device_name) { 'iPhone' }
|
24
|
-
|
25
|
-
it 'returns the textual portion without trailing whitespace' do
|
26
|
-
value(extractor.call).must_equal device_name
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'when a dynamic match is found' do
|
32
|
-
let(:user_agent) { 'Mozilla/5.0 (iPhone 5S; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4' }
|
33
|
-
let(:device_name) { 'iPhone 5S' }
|
34
|
-
|
35
|
-
it 'returns the full device name' do
|
36
|
-
value(extractor.call).must_equal device_name
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'when matching against static model' do
|
44
|
-
|
45
|
-
let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12A365 Weibo (iPhone7,2)' }
|
46
|
-
let(:device_name) { 'iPhone 6' }
|
47
|
-
let(:regex_meta) do
|
48
|
-
{
|
49
|
-
:regex => '(?:Apple-)?iPhone7[C,]2',
|
50
|
-
:model => 'iPhone 6',
|
51
|
-
:device => 'smartphone'
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns the model name' do
|
56
|
-
value(extractor.call).must_equal device_name
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe DeviceDetector::OS do
|
4
|
-
|
5
|
-
fixture_dir = File.expand_path('../../fixtures/parser', __FILE__)
|
6
|
-
fixture_files = Dir["#{fixture_dir}/oss.yml"]
|
7
|
-
fixture_files.each do |fixture_file|
|
8
|
-
|
9
|
-
describe File.basename(fixture_file) do
|
10
|
-
|
11
|
-
fixtures = YAML.load(File.read(fixture_file))
|
12
|
-
fixtures.each do |f|
|
13
|
-
user_agent = f["user_agent"]
|
14
|
-
|
15
|
-
describe user_agent do
|
16
|
-
|
17
|
-
it "should have the expected name" do
|
18
|
-
os = DeviceDetector::OS.new(user_agent)
|
19
|
-
assert_equal f["os"]["name"], os.name, "failed OS name detection"
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe DeviceDetector::VersionExtractor do
|
4
|
-
|
5
|
-
subject { DeviceDetector::VersionExtractor.new(user_agent, regex_meta) }
|
6
|
-
|
7
|
-
alias :extractor :subject
|
8
|
-
|
9
|
-
describe '#call' do
|
10
|
-
|
11
|
-
describe 'extractor without version' do
|
12
|
-
|
13
|
-
let(:user_agent) { 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; Avant Browser; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)' }
|
14
|
-
|
15
|
-
let(:regex_meta) do
|
16
|
-
{
|
17
|
-
:regex => 'Avant Browser',
|
18
|
-
:name => 'Avant Browser',
|
19
|
-
:version => ''
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns nil' do
|
24
|
-
value(extractor.call).must_equal ''
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'regex with dynamic matching' do
|
30
|
-
|
31
|
-
let(:user_agent) { 'Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.8.1b2) Gecko/20060821 BonEcho/2.0b2 (Debian-1.99+2.0b2+dfsg-1)' }
|
32
|
-
let(:version) { 'BonEcho (2.0)' }
|
33
|
-
let(:regex_meta) do
|
34
|
-
{
|
35
|
-
:regex => '(BonEcho|GranParadiso|Lorentz|Minefield|Namoroka|Shiretoko)/(\d+[\.\d]+)',
|
36
|
-
:name => 'Firefox',
|
37
|
-
:version => '$1 ($2)'
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns the correct version' do
|
42
|
-
value(extractor.call).must_equal version
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'removes trailing white spaces' do
|
46
|
-
regex_meta[:version] = regex_meta[:version] + ' '
|
47
|
-
value(extractor.call).must_equal version
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'extractor with fixed version' do
|
53
|
-
|
54
|
-
let(:user_agent) { 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)' }
|
55
|
-
let(:regex_meta) do
|
56
|
-
{
|
57
|
-
:regex => 'MSIE.*Trident/4.0',
|
58
|
-
:version => '8.0'
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns the correct version' do
|
63
|
-
value(extractor.call).must_equal '8.0'
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'unknown user agent' do
|
69
|
-
|
70
|
-
let(:user_agent) { 'garbage' }
|
71
|
-
let(:regex_meta) { {} }
|
72
|
-
|
73
|
-
it 'returns nil' do
|
74
|
-
value(extractor.call).must_be_nil
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|