Sha256: cc9a911d1ee3d3d0c1192dac8bdc0dc76fa8c51d304e0571bdc8a33796c97a7f

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require 'device_map'

RSpec.describe DeviceMap::UserAgent do
  describe '#keyword_ngrams' do
    example do
      user_agent = described_class.new('iphone')
      ngrams = user_agent.keyword_ngrams(1)

      expect(ngrams.size).to eq 1
      expect(ngrams).to include ['iphone']
    end

    example do
      user_agent = described_class.new('iPhone; U')
      ngrams = user_agent.keyword_ngrams(2)

      expect(ngrams.size).to eq 3
      expect(ngrams).to include ['iphone']
      expect(ngrams).to include ['iphone', 'u']
      expect(ngrams).to include ['u']
    end

    example do
      user_agent = described_class.new('Mozilla/5.0')
      ngrams = user_agent.keyword_ngrams(3)

      expect(ngrams.size).to eq 3
      expect(ngrams).to include ['mozilla']
      expect(ngrams).to include ['mozilla', '50']
      expect(ngrams).to include ['50']
    end

    example do
      user_agent = described_class.new('Mozilla/5.0 (iPhone)')
      ngrams = user_agent.keyword_ngrams(3)

      expect(ngrams.size).to eq 6
      expect(ngrams).to include ['mozilla']
      expect(ngrams).to include ['mozilla', '50']
      expect(ngrams).to include ['mozilla', '50', 'iphone']
      expect(ngrams).to include ['50']
      expect(ngrams).to include ['50', 'iphone']
      expect(ngrams).to include ['iphone']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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