Sha256: a5ccc2c91af3cbd97b3ddbed8f962bf4dc10f92b1704e78d339dab4f05143aae

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'device_map'

RSpec.describe DeviceMap::Classifier do
  describe '#find_device' do
    let(:user_agent) { 'test' }

    let(:classifier) do
      described_class.instance
    end

    let(:device) do
      DeviceMap::DeviceData::Device.new(id: 'device_id')
    end

    context 'when device is found' do
      before do
        pattern = DeviceMap::Pattern.new(user_agent, device.id, 1)
        expect(classifier.patterns).to receive(:find) do
          Set.new [pattern]
        end
      end

      it 'returns device object' do
        expect(classifier.devices).to receive(:find).with(device.id) { device }

        found_device = classifier.find_device(user_agent)
        expect(found_device).to eq device
      end
    end

    context 'when device is not found' do
      before do
        expect(classifier.patterns).to receive(:find) do
          Set.new
        end
      end

      it 'returns unknown device object' do
        found_device = classifier.find_device(user_agent)
        expect(found_device).to eq DeviceMap::DeviceData::Device.unknown
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
device_map-0.1.2 spec/classifier_spec.rb
device_map-0.1.1 spec/classifier_spec.rb
device_map-0.1.0 spec/classifier_spec.rb