File: model_extractor_spec.rb

package info (click to toggle)
ruby-device-detector 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 3,104 kB
  • sloc: ruby: 1,224; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 1,786 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
58
59
60
61
62
63
require_relative '../spec_helper'

describe DeviceDetector::ModelExtractor do

  subject { DeviceDetector::ModelExtractor.new(user_agent, regex_meta) }

  alias :extractor :subject

  describe '#call' do

    describe 'when matching against dynamic model' do

      let(:regex_meta) do
        {
          :regex  => '(?:Apple-)?iPhone ?(3GS?|4S?|5[CS]?|6(:? Plus)?)?',
          :model  => 'iPhone $1',
          :device => 'smartphone'
        }
      end

      describe 'when no dynamic match is found' do
        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' }
        let(:device_name) { 'iPhone' }

        it 'returns the textual portion without trailing whitespace' do
          extractor.call.must_equal device_name
        end

      end

      describe 'when a dynamic match is found' do
        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' }
        let(:device_name) { 'iPhone 5S' }

        it 'returns the full device name' do
          extractor.call.must_equal device_name
        end

      end

    end

    describe 'when matching against static model' do

      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)' }
      let(:device_name) { 'iPhone 6' }
      let(:regex_meta) do
        {
          :regex  => '(?:Apple-)?iPhone7[C,]2',
          :model  => 'iPhone 6',
          :device => 'smartphone'
        }
      end

      it 'returns the model name' do
        extractor.call.must_equal device_name
      end

    end

  end

end