File: device_fixtures_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 (36 lines) | stat: -rw-r--r-- 1,016 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
require_relative '../spec_helper'

describe DeviceDetector::Device do

  fixture_dir = File.expand_path('../../fixtures/devices', __FILE__)
  fixture_files = Dir["#{fixture_dir}/*.yml"]
  fixture_files.each do |fixture_file|

    describe File.basename(fixture_file) do

      fixtures = YAML.load_file(fixture_file)
      fixtures.each do |f|

        user_agent = f["user_agent"]
        device = DeviceDetector::Device.new(user_agent)

        describe user_agent do

          it "should be known" do
            assert device.known?, "isn't known as a device"
          end

          it "should have the expected model" do
            assert_equal f["device"]["model"], device.name, "failed model detection"
          end

          it "should have the expected type" do
            expected_device_type = DeviceDetector::Device::DEVICE_NAMES[f["device"]["type"]]
            assert_equal expected_device_type, device.type, "failed device name detection"
          end

        end
      end
    end
  end
end