Sha256: b3d48fe64e8255a82931ef9f3190065211a9729ba452a666a025eaea9e6c206f

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

#
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "spec_helper"

describe Brauser::Definitions::Browser do
  subject { ::Brauser::Definitions.browsers[:opera] }

  describe "#initialize" do
    it "should save the id, the name and the pattern" do
      subject = ::Brauser::Definitions::Browser.new(:browser, "BROWSER", /engine/, /version/)
      expect(subject.id).to eq(:browser)
      expect(subject.name).to eq("BROWSER")
      expect(subject.engine_matcher).to eq(/engine/)
      expect(subject.version_matcher).to eq(/version/)
    end
  end

  describe "#match" do
    it "should run against the engine pattern and the version pattern" do
      result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")
      expect(result.first).to eq(:opera)
    end

    it "should also fetch the version" do
      result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")
      expect(result[1]).to eq(::Versionomy.parse("11.51"))

      result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera")
      expect(result[1]).to eq(::Versionomy.parse("0.0"))

      subject.instance_variable_set(:@version_matcher, ->(_) { "123" })
      result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera")
      expect(result[1]).to eq("123")
    end

    it "should also fetch the platform" do
      result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")
      expect(result[2]).to eq(:windows)

      result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; FOO 6.1; de) Opera 11.51")
      expect(result[2]).to eq(nil)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brauser-4.1.2 spec/brauser/definitions/browser_spec.rb
brauser-4.1.1 spec/brauser/definitions/browser_spec.rb
brauser-4.1.0 spec/brauser/definitions/browser_spec.rb
brauser-4.0.0 spec/brauser/definitions/browser_spec.rb