brauser 3.3.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.travis-gemfile +4 -5
- data/.travis.yml +2 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -8
- data/README.md +31 -95
- data/Rakefile +0 -1
- data/brauser.gemspec +4 -4
- data/default_definitions/browsers.rb +50 -0
- data/default_definitions/languages.rb +118 -0
- data/default_definitions/platforms.rb +24 -0
- data/doc/Brauser.html +6 -6
- data/doc/Brauser/Browser.html +3867 -580
- data/doc/Brauser/Definitions.html +537 -0
- data/doc/Brauser/Definitions/Base.html +342 -0
- data/doc/Brauser/Definitions/Browser.html +1047 -0
- data/doc/Brauser/Definitions/Language.html +496 -0
- data/doc/Brauser/Definitions/Platform.html +686 -0
- data/doc/Brauser/Hooks.html +2 -2
- data/doc/Brauser/Hooks/RubyOnRails.html +9 -9
- data/doc/Brauser/Parser.html +513 -0
- data/doc/Brauser/Value.html +601 -0
- data/doc/Brauser/Version.html +5 -5
- data/doc/_index.html +25 -108
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +33 -97
- data/doc/index.html +33 -97
- data/doc/method_list.html +72 -120
- data/doc/top-level-namespace.html +2 -2
- data/lib/brauser.rb +13 -15
- data/lib/brauser/browser.rb +195 -66
- data/lib/brauser/definitions/base.rb +71 -0
- data/lib/brauser/definitions/browser.rb +80 -0
- data/lib/brauser/definitions/language.rb +29 -0
- data/lib/brauser/definitions/platform.rb +42 -0
- data/lib/brauser/hooks.rb +1 -2
- data/lib/brauser/parser.rb +47 -0
- data/lib/brauser/value.rb +39 -0
- data/lib/brauser/version.rb +3 -4
- data/spec/brauser/browser_spec.rb +73 -564
- data/spec/brauser/default_definitions_spec.rb +129 -0
- data/spec/brauser/definitions/base_spec.rb +48 -0
- data/spec/brauser/definitions/browser_spec.rb +47 -0
- data/spec/brauser/definitions/language_spec.rb +18 -0
- data/spec/brauser/definitions/platform_spec.rb +36 -0
- data/spec/brauser/hooks_spec.rb +5 -6
- data/spec/brauser/parser_spec.rb +31 -0
- data/spec/brauser/value_spec.rb +34 -0
- data/spec/coverage_helper.rb +0 -1
- data/spec/spec_helper.rb +0 -1
- metadata +50 -23
- data/lib/brauser/browseable/attributes.rb +0 -95
- data/lib/brauser/browseable/general.rb +0 -104
- data/lib/brauser/browseable/parsing.rb +0 -127
- data/lib/brauser/browseable/partial_querying.rb +0 -116
- data/lib/brauser/browseable/querying.rb +0 -63
- data/lib/brauser/browseable/register.rb +0 -73
- data/lib/brauser/definition.rb +0 -80
- data/lib/brauser/definitions/browsers.rb +0 -68
- data/lib/brauser/definitions/languages.rb +0 -130
- data/lib/brauser/definitions/platforms.rb +0 -30
- data/lib/brauser/query.rb +0 -36
- data/lib/brauser/queryable/chainers.rb +0 -56
- data/lib/brauser/queryable/queries.rb +0 -60
- data/spec/brauser/definition_spec.rb +0 -39
- data/spec/brauser/query_spec.rb +0 -111
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Brauser
|
7
|
+
module Definitions
|
8
|
+
# A definition of a language.
|
9
|
+
#
|
10
|
+
# @attribute [r] code
|
11
|
+
# @return [String] The language code.
|
12
|
+
# @attribute [r] name
|
13
|
+
# @return [String] The language name.
|
14
|
+
class Language < Base
|
15
|
+
attr_reader :code, :name
|
16
|
+
|
17
|
+
# Creates a new definition.
|
18
|
+
#
|
19
|
+
# @param code [String] The language code.
|
20
|
+
# @param name [String] The language name.
|
21
|
+
def initialize(code, name, **_)
|
22
|
+
code = code.downcase.gsub("_", "-")
|
23
|
+
@id = code.to_sym
|
24
|
+
@code = code
|
25
|
+
@name = name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Brauser
|
7
|
+
module Definitions
|
8
|
+
# A definition of a platform.
|
9
|
+
#
|
10
|
+
# @attribute [r] name
|
11
|
+
# @return [String] The platform name.
|
12
|
+
# @attribute [r] matcher
|
13
|
+
# @return [Regexp|Proc] The pattern or the block to recognize the platform.
|
14
|
+
class Platform < Base
|
15
|
+
attr_reader :name, :matcher
|
16
|
+
|
17
|
+
# Creates a new definition.
|
18
|
+
#
|
19
|
+
# @param id [Symbol] The platform id.
|
20
|
+
# @param name [String] The platform name.
|
21
|
+
# @param matcher [Regexp|Proc] The pattern or the block to recognize the platform. **Ignore if a block is given**
|
22
|
+
def initialize(id, name, matcher = /.*/, **_, &block)
|
23
|
+
@id = id
|
24
|
+
@name = name
|
25
|
+
@matcher = block ? block : matcher
|
26
|
+
end
|
27
|
+
|
28
|
+
# Matches against an header.
|
29
|
+
#
|
30
|
+
# @param header [String] The header to match.
|
31
|
+
# @param engine [Symbol] The engine to match.
|
32
|
+
# @return [Boolean|NilClass] True if match succeeded, `false` or `nil` otherwise.
|
33
|
+
def match(header, engine)
|
34
|
+
if @matcher.is_a?(Regexp)
|
35
|
+
@matcher.match(header)
|
36
|
+
else
|
37
|
+
@matcher.call(header, engine)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/brauser/hooks.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
#
|
3
2
|
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
4
3
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
@@ -22,7 +21,7 @@ module Brauser
|
|
22
21
|
# @return [Browser] The detected browser.
|
23
22
|
def browser(force = false)
|
24
23
|
@browser = nil if force
|
25
|
-
@browser ||= Browser.new(request.headers["User-Agent"], request.headers["Accept-Language"])
|
24
|
+
@browser ||= ::Brauser::Browser.new(request.headers["User-Agent"], request.headers["Accept-Language"])
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Brauser
|
7
|
+
# A parser for the HTTP headers.
|
8
|
+
class Parser
|
9
|
+
# Makes sure a subject matches a pattern AND NOT another pattern.
|
10
|
+
#
|
11
|
+
# @param subject [String] The subject to match.
|
12
|
+
# @param positive_matcher [Regexp] The expression to match.
|
13
|
+
# @param negative_matcher [Regexp] The expression NOT to match.
|
14
|
+
# @return [Boolean] `true` if matching succeeded, `false otherwise`.
|
15
|
+
def self.disambiguate(subject, positive_matcher, negative_matcher)
|
16
|
+
subject =~ positive_matcher && subject !~ negative_matcher
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parses the User-Agent header.
|
20
|
+
#
|
21
|
+
# @param header [String] The User-Agent header.
|
22
|
+
# @return [Array|NilClass] An array of engine, version and platform if the match succeeded, `nil` otherwise.
|
23
|
+
def parse_agent(header)
|
24
|
+
# First of all match the agent and the version
|
25
|
+
catch(:result) {
|
26
|
+
Brauser::Definitions.browsers.each do |_, definition|
|
27
|
+
result = definition.match(header)
|
28
|
+
throw(:result, result) if result
|
29
|
+
end
|
30
|
+
|
31
|
+
nil
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Parses a Accept-Language header.
|
36
|
+
#
|
37
|
+
# @param header [String] The Accept-Language header.
|
38
|
+
# @return [Hash] The list of accepted languages with their priorities.
|
39
|
+
def parse_accept_language(header)
|
40
|
+
header.ensure_string.tokenize.reduce({}) { |rv, token|
|
41
|
+
code, priority = token.split(";q=")
|
42
|
+
rv[code.downcase.gsub("_", "-").to_sym] = priority.to_float if code && priority
|
43
|
+
rv
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Brauser
|
7
|
+
# A defined entity, which supports comparison against a single or multiple values.
|
8
|
+
#
|
9
|
+
# @attribute [r] value
|
10
|
+
# @return [Object] The wrapped value.
|
11
|
+
class Value
|
12
|
+
attr_reader :value
|
13
|
+
delegate :to_s, :inspect, to: :value
|
14
|
+
|
15
|
+
# Creates a new value
|
16
|
+
#
|
17
|
+
# @param value [Object] The wrapped value.
|
18
|
+
def initialize(value)
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
# Check if an object is equal to another object or if it is contained in a list of objects.
|
23
|
+
#
|
24
|
+
# @param other [Array|Object] The other object to match.
|
25
|
+
# @return [Boolean] `true` if the current object is either equal or contained in the other object, `false` otherwise.
|
26
|
+
def ==(other)
|
27
|
+
other.is_a?(Array) ? other.include?(@value) : (@value == other)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Delegates all the other values to the wrapped value.
|
31
|
+
#
|
32
|
+
# @param method [Symbol] The method to call.
|
33
|
+
# @param args [Array] The arguments to pass to the method.
|
34
|
+
# @param block [Proc] The block to pass to the method.
|
35
|
+
def method_missing(method, *args, &block)
|
36
|
+
@value.send(method, *args, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/brauser/version.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
#
|
3
2
|
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
4
3
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
@@ -11,13 +10,13 @@ module Brauser
|
|
11
10
|
# @see http://semver.org
|
12
11
|
module Version
|
13
12
|
# The major version.
|
14
|
-
MAJOR =
|
13
|
+
MAJOR = 4
|
15
14
|
|
16
15
|
# The minor version.
|
17
|
-
MINOR =
|
16
|
+
MINOR = 0
|
18
17
|
|
19
18
|
# The patch version.
|
20
|
-
PATCH =
|
19
|
+
PATCH = 0
|
21
20
|
|
22
21
|
# The current version of brauser.
|
23
22
|
STRING = [MAJOR, MINOR, PATCH].compact.join(".")
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
#
|
3
2
|
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
4
3
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
@@ -7,599 +6,109 @@
|
|
7
6
|
require "spec_helper"
|
8
7
|
|
9
8
|
describe Brauser::Browser do
|
10
|
-
|
9
|
+
subject {
|
10
|
+
Brauser::Browser.new(
|
11
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.82 Safari/537.1",
|
12
|
+
"IT;q=0.7, EN;q=0.3"
|
13
|
+
)
|
14
|
+
}
|
11
15
|
|
12
|
-
describe "
|
13
|
-
it "should
|
14
|
-
|
15
|
-
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
end
|
19
|
-
|
20
|
-
it "add the definition to the right hash" do
|
21
|
-
::Brauser::Browser.instance_variable_set("@definitions", nil)
|
22
|
-
definition = ::Brauser::Definition.new(:tag)
|
23
|
-
|
24
|
-
expect(::Brauser::Browser.add(:platforms, definition)).to be_true
|
25
|
-
definitions = ::Brauser::Browser.instance_variable_get("@definitions")
|
26
|
-
expect(definitions[:platforms][:tag]).to be(definition)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "support adding more definitions in one call" do
|
30
|
-
::Brauser::Browser.instance_variable_set("@definitions", nil)
|
31
|
-
expect(::Brauser::Browser.add(:platforms, [::Brauser::Definition.new(:tag1), ::Brauser::Definition.new(:tag2)])).to be_true
|
32
|
-
definitions = ::Brauser::Browser.instance_variable_get("@definitions")
|
33
|
-
expect(definitions[:platforms].length).to eq(2)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe ".add_default_browsers" do
|
38
|
-
it "should call .add" do
|
39
|
-
expect(::Brauser::Browser).to receive(:add).with(:browsers, an_instance_of(Array)).and_call_original
|
40
|
-
::Brauser::Browser.add_default_browsers
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return a good return code" do
|
44
|
-
expect(::Brauser::Browser.add_default_browsers).to be_true
|
45
|
-
|
46
|
-
allow(::Brauser::Browser).to receive(:add).and_return(false)
|
47
|
-
expect(::Brauser::Browser.add_default_browsers).to be_false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe ".add_default_platforms" do
|
52
|
-
it "should call .add" do
|
53
|
-
expect(::Brauser::Browser).to receive(:add).with(:platforms, an_instance_of(Array))
|
54
|
-
::Brauser::Browser.add_default_platforms
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should return a good return code" do
|
58
|
-
expect(::Brauser::Browser.add_default_platforms).to be_true
|
59
|
-
|
60
|
-
allow(::Brauser::Browser).to receive(:add).and_return(false)
|
61
|
-
expect(::Brauser::Browser.add_default_platforms).to be_false
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe ".add_default_languages" do
|
66
|
-
it "should call .add" do
|
67
|
-
expect(::Brauser::Browser).to receive(:add).with(:languages, an_instance_of(Array))
|
68
|
-
::Brauser::Browser.add_default_languages
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should return a good return code" do
|
72
|
-
expect(::Brauser::Browser.add_default_languages).to be_true
|
73
|
-
|
74
|
-
allow(::Brauser::Browser).to receive(:add).and_return(false)
|
75
|
-
expect(::Brauser::Browser.add_default_languages).to be_false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe ".browsers" do
|
80
|
-
it "should return the list of browsers" do
|
81
|
-
::Brauser::Browser.add_default_browsers
|
82
|
-
|
83
|
-
expect(::Brauser::Browser.browsers).to be_a(Hash)
|
84
|
-
expect(::Brauser::Browser.browsers[:chrome]).to be_a(::Brauser::Definition)
|
85
|
-
expect(::Brauser::Browser.browsers[:chrome].label).to eq("Google Chrome")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe ".platforms" do
|
90
|
-
it "should return the list of platforms" do
|
91
|
-
::Brauser::Browser.add_default_platforms
|
92
|
-
|
93
|
-
expect(::Brauser::Browser.platforms).to be_a(Hash)
|
94
|
-
expect(::Brauser::Browser.platforms[:osx]).to be_a(::Brauser::Definition)
|
95
|
-
expect(::Brauser::Browser.platforms[:osx].label).to eq("Apple MacOS X")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe ".languages" do
|
100
|
-
it "should return the list of languages" do
|
101
|
-
::Brauser::Browser.add_default_languages
|
102
|
-
|
103
|
-
expect(::Brauser::Browser.languages).to be_a(Hash)
|
104
|
-
expect(::Brauser::Browser.languages["it"]).to be_a(::Brauser::Definition)
|
105
|
-
expect(::Brauser::Browser.languages["it"].label).to eq("Italian")
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe ".compare_versions" do
|
110
|
-
it "should correctly compare versions" do
|
111
|
-
expect(::Brauser::Browser.compare_versions(nil, :eq, nil)).to be_false
|
112
|
-
|
113
|
-
expect(::Brauser::Browser.compare_versions("3", :eq, nil)).to be_false
|
114
|
-
expect(::Brauser::Browser.compare_versions("3", :eq, "7")).to be_false
|
115
|
-
expect(::Brauser::Browser.compare_versions("7.1", :eq, "7")).to be_false
|
116
|
-
expect(::Brauser::Browser.compare_versions("7.1.2", :eq, "7.1.2")).to be_true
|
117
|
-
|
118
|
-
expect(::Brauser::Browser.compare_versions("3", :lt, "3")).to be_false
|
119
|
-
expect(::Brauser::Browser.compare_versions("3", :lt, "3.4")).to be_true
|
120
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :lt, "3.4.5")).to be_false
|
121
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :lt, "3.2")).to be_false
|
122
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :lt, "3.4.6")).to be_true
|
123
|
-
expect(::Brauser::Browser.compare_versions("3.4.beta", :lt, "3.4")).to be_true
|
124
|
-
expect(::Brauser::Browser.compare_versions("3.4.alpha", :lt, "3.4beta")).to be_true
|
125
|
-
|
126
|
-
expect(::Brauser::Browser.compare_versions("3", :lte, "3")).to be_true
|
127
|
-
expect(::Brauser::Browser.compare_versions("3", :lte, "3.4")).to be_true
|
128
|
-
expect(::Brauser::Browser.compare_versions("4", :lte, "3.4")).to be_false
|
129
|
-
expect(::Brauser::Browser.compare_versions("4.1", :lte, "3.4")).to be_false
|
130
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :lte, "3.4.5")).to be_true
|
131
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :lte, "3.4.4")).to be_false
|
132
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :lt, "3.2")).to be_false
|
133
|
-
expect(::Brauser::Browser.compare_versions("3.4.beta", :lte, "3.4")).to be_true
|
134
|
-
|
135
|
-
expect(::Brauser::Browser.compare_versions("3", :gt, "3")).to be_false
|
136
|
-
expect(::Brauser::Browser.compare_versions("3", :gt, "3.4")).to be_false
|
137
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :gt, "3.4.3")).to be_true
|
138
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :gt, "3.4.5")).to be_false
|
139
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :gt, "3.4.6")).to be_false
|
140
|
-
expect(::Brauser::Browser.compare_versions("3.5", :gt, "3")).to be_true
|
141
|
-
expect(::Brauser::Browser.compare_versions("3.4.beta", :gt, "3.4")).to be_false
|
142
|
-
expect(::Brauser::Browser.compare_versions("3.4.alpha", :gt, "3.4beta")).to be_false
|
143
|
-
|
144
|
-
expect(::Brauser::Browser.compare_versions("3", :gte, "3")).to be_true
|
145
|
-
expect(::Brauser::Browser.compare_versions("3", :gte, "3.4")).to be_false
|
146
|
-
expect(::Brauser::Browser.compare_versions("4", :gte, "3.4")).to be_true
|
147
|
-
expect(::Brauser::Browser.compare_versions("4.1", :gte, "3.4")).to be_true
|
148
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :gte, "3.4.5")).to be_true
|
149
|
-
expect(::Brauser::Browser.compare_versions("3.4.5", :gte, "3.4.4")).to be_true
|
150
|
-
expect(::Brauser::Browser.compare_versions("3.4.beta", :gte, "3.4")).to be_false
|
151
|
-
expect(::Brauser::Browser.compare_versions("3.5", :gt, "3")).to be_true
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "#readable_name" do
|
156
|
-
before(:each) do
|
157
|
-
::Brauser::Browser.add_default_browsers
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should return the correct name" do
|
161
|
-
browser.name = :msie
|
162
|
-
expect(browser.readable_name).to eq("Microsoft Internet Explorer")
|
163
|
-
|
164
|
-
browser.name = :chrome
|
165
|
-
expect(browser.readable_name).to eq("Google Chrome")
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should return a default name" do
|
169
|
-
browser.name = :none
|
170
|
-
expect(browser.readable_name).to eq("Unknown Browser")
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "#platform_name" do
|
175
|
-
before(:each) do
|
176
|
-
::Brauser::Browser.add_default_platforms
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should return the correct name" do
|
180
|
-
browser.platform = :windows
|
181
|
-
expect(browser.platform_name).to eq("Microsoft Windows")
|
182
|
-
|
183
|
-
browser.platform = :ios
|
184
|
-
expect(browser.platform_name).to eq("Apple iOS")
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should return a default name" do
|
188
|
-
browser.platform = :none
|
189
|
-
expect(browser.platform_name).to eq("Unknown Platform")
|
16
|
+
describe "#initialize" do
|
17
|
+
it "should save agent and language, then call #parse" do
|
18
|
+
expect_any_instance_of(::Brauser::Browser).to receive(:parse)
|
19
|
+
subject = ::Brauser::Browser.new("AGENT", "LANGUAGE")
|
20
|
+
expect(subject.agent).to eq("AGENT")
|
21
|
+
expect(subject.accept_language).to eq("LANGUAGE")
|
190
22
|
end
|
191
23
|
end
|
192
24
|
|
193
25
|
describe "#classes" do
|
194
|
-
|
195
|
-
|
196
|
-
browser.version = "1.2.A.4"
|
197
|
-
browser.platform = :osx
|
26
|
+
it "should return CSS compatible version of the classes" do
|
27
|
+
expect(subject.classes).to eq("chrome version-21 version-21_0 version-21_0_1180 version-21_0_1180_82 version-21_0_1180_82_final version-21_0_1180_82_final_0 version-21_0_1180_82_final_0_0 platform-osx")
|
198
28
|
end
|
199
29
|
|
200
|
-
it "should return
|
201
|
-
expect(
|
202
|
-
expect(browser.classes(false, "name-")).to eq(["name-chrome", "version-1", "version-1_2", "version-1_2_A", "version-1_2_A_4", "platform-osx"])
|
203
|
-
expect(browser.classes(false, true, "v-")).to eq(["chrome", "v-1", "v-1_2", "v-1_2_A", "v-1_2_A_4", "platform-osx"])
|
204
|
-
expect(browser.classes(false, true, true, "p-")).to eq(["chrome", "version-1", "version-1_2", "version-1_2_A", "version-1_2_A_4", "p-osx"])
|
205
|
-
expect(browser.classes(false, false)).to eq(["version-1", "version-1_2", "version-1_2_A", "version-1_2_A_4", "platform-osx"])
|
206
|
-
expect(browser.classes(false, true, false)).to eq(["chrome", "platform-osx"])
|
207
|
-
expect(browser.classes(false, true, true, false)).to eq(["chrome", "version-1", "version-1_2", "version-1_2_A", "version-1_2_A_4"])
|
30
|
+
it "should return results as an array" do
|
31
|
+
expect(subject.classes(nil)).to eq(["chrome", "version-21", "version-21_0", "version-21_0_1180", "version-21_0_1180_82", "version-21_0_1180_82_final", "version-21_0_1180_82_final_0", "version-21_0_1180_82_final_0_0", "platform-osx"])
|
208
32
|
end
|
209
33
|
|
210
|
-
it "should
|
211
|
-
expect(
|
212
|
-
expect(
|
34
|
+
it "should use prefixes" do
|
35
|
+
expect(subject.classes(name: "NAME-")).to eq("NAME-chrome version-21 version-21_0 version-21_0_1180 version-21_0_1180_82 version-21_0_1180_82_final version-21_0_1180_82_final_0 version-21_0_1180_82_final_0_0 platform-osx")
|
36
|
+
expect(subject.classes(version: "VERSION-")).to eq("chrome VERSION-21 VERSION-21_0 VERSION-21_0_1180 VERSION-21_0_1180_82 VERSION-21_0_1180_82_final VERSION-21_0_1180_82_final_0 VERSION-21_0_1180_82_final_0_0 platform-osx")
|
37
|
+
expect(subject.classes(platform: "PLATFORM-")).to eq("chrome version-21 version-21_0 version-21_0_1180 version-21_0_1180_82 version-21_0_1180_82_final version-21_0_1180_82_final_0 version-21_0_1180_82_final_0_0 PLATFORM-osx")
|
213
38
|
end
|
214
39
|
|
215
|
-
it "should
|
216
|
-
|
217
|
-
expect(
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should transform name" do
|
221
|
-
expect(browser.classes(" ", true, false, false) { |name, *| name.to_s.upcase }).to eq("CHROME")
|
40
|
+
it "should skip unwanted parts" do
|
41
|
+
expect(subject.classes(version: nil)).to eq("chrome platform-osx")
|
42
|
+
expect(subject.classes(platform: nil)).to eq("chrome version-21 version-21_0 version-21_0_1180 version-21_0_1180_82 version-21_0_1180_82_final version-21_0_1180_82_final_0 version-21_0_1180_82_final_0_0")
|
222
43
|
end
|
223
44
|
end
|
224
45
|
|
225
|
-
describe "#
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
only_rv ? true : []
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should return true for known names" do
|
236
|
-
expect(recognize("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.82 Safari/537.1", true)).to be_true
|
237
|
-
expect(recognize("Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2", true)).to be_true
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should return false for unknown names" do
|
241
|
-
expect(recognize("UNKNOWN", true)).to be_false
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should detect the correct name, version and platform" do
|
245
|
-
# Google Chrome
|
246
|
-
expect(recognize("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.82 Safari/537.1")).to eq([:chrome, "21.0.1180.82", :osx])
|
247
|
-
expect(recognize("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5")).to eq([:chrome, "19.0.1084.9", :linux])
|
248
|
-
expect(recognize("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1")).to eq([:chrome, "13.0.782.215", :windows])
|
249
|
-
|
250
|
-
# Mozilla Firefox
|
251
|
-
expect(recognize("Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2")).to eq([:firefox, "15.0a2", :windows])
|
252
|
-
expect(recognize("Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1")).to eq([:firefox, "14.0.1", :linux])
|
253
|
-
expect(recognize("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8")).to eq([:firefox, "4.0b8", :osx])
|
254
|
-
|
255
|
-
# Apple Safari
|
256
|
-
expect(recognize("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10")).to eq([:safari, "5.1.3", :osx])
|
257
|
-
expect(recognize("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-en) AppleWebKit/533.16 (KHTML, like Gecko) Version/4.1 Safari/533.16")).to eq([:safari, "4.1", :windows])
|
258
|
-
|
259
|
-
# Opera Mobile
|
260
|
-
expect(recognize("Opera/9.80 (Android 2.3.3; Linux; Opera Mobi/ADR-1111101157; U; es-ES) Presto/2.9.201 Version/11.50")).to eq([:opera_mobile, "11.50", :android])
|
261
|
-
expect(recognize("Mozilla/5.0 (S60; SymbOS; Opera Mobi/SYB-1103211396; U; es-LA; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Opera 11.00")).to eq([:opera_mobile, "11.00", :symbian])
|
262
|
-
|
263
|
-
# Opera
|
264
|
-
expect(recognize("Opera/9.80 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00")).to eq([:opera, "12.00", :windows])
|
265
|
-
expect(recognize("Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/5.0 Opera 11.11")).to eq([:opera, "11.11", :windows])
|
266
|
-
expect(recognize("Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52")).to eq([:opera, "11.52", :osx])
|
267
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")).to eq([:opera, "11.51", :windows])
|
268
|
-
|
269
|
-
# Microsoft Internet Explorer in compatibility view
|
270
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0)")).to eq([:msie_compatibility, "10.0", :windows])
|
271
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; .NET4.0C; Tablet PC 2.0)")).to eq([:msie_compatibility, "9.0", :windows])
|
272
|
-
expect(recognize("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 3.0)")).to eq([:msie_compatibility, "8.0", :windows])
|
273
|
-
|
274
|
-
# Microsoft Internet Explorer
|
275
|
-
expect(recognize("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko")).to eq([:msie, "11.0", :windows])
|
276
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64;0)")).to eq([:msie, "10.0", :windows])
|
277
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; .NET4.0C; Tablet PC 2.0)")).to eq([:msie, "9.0", :windows])
|
278
|
-
expect(recognize("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 3.0)")).to eq([:msie, "8.0", :windows])
|
279
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; fr-FR)")).to eq([:msie, "7.0", :windows])
|
280
|
-
expect(recognize("Mozilla/4.01 (compatible; MSIE 6.0; Windows NT 5.1)")).to eq([:msie, "6.0", :windows])
|
281
|
-
|
282
|
-
# Netscape
|
283
|
-
expect(recognize("Mozilla/5.0 (Windows; U; Win 9x 4.90; SG; rv:1.9.2.4) Gecko/20101104 Netscape/9.1.0285")).to eq([:netscape, "9.1.0285", :windows])
|
284
|
-
expect(recognize("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.8pre) Gecko/20071001 Firefox/2.0.0.7 Navigator/9.0RC1")).to eq([:netscape, "9.0RC1", :osx])
|
285
|
-
|
286
|
-
# Chrome IOS
|
287
|
-
expect(recognize("Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-gb) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3")).to eq([:chrome_ios, "19.0.1084.60", :ios])
|
288
|
-
expect(recognize("Mozilla/5.0 (iPad; U; CPU iPhone OS 5_1_1 like Mac OS X; en-gb) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/21.0.1180.82 Safari/536.5")).to eq([:chrome_ios, "21.0.1180.82", :ios])
|
289
|
-
|
290
|
-
# Apple iPhone
|
291
|
-
expect(recognize("Mozilla/5.0 (iPhone; U; fr; CPU iPhone OS 4_2_1 like Mac OS X; fr) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5")).to eq([:iphone, "5.0.2", :ios])
|
292
|
-
expect(recognize("Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7")).to eq([:iphone, "4.0.5", :ios])
|
293
|
-
|
294
|
-
# Apple iPad
|
295
|
-
expect(recognize("Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3")).to eq([:ipad, "5.1", :ios])
|
296
|
-
expect(recognize("Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; nl-nl) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5")).to eq([:ipad, "5.0.2", :ios])
|
297
|
-
|
298
|
-
# Apple iPod Touch
|
299
|
-
expect(recognize("Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5")).to eq([:ipod, "5.0.2", :ios])
|
300
|
-
expect(recognize("Mozilla/5.0 (iPod; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16")).to eq([:ipod, "4.0", :ios])
|
301
|
-
|
302
|
-
# Android
|
303
|
-
expect(recognize("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30")).to eq([:android, "4.0.3", :android])
|
304
|
-
expect(recognize("Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1")).to eq([:android, "2.3.3", :android])
|
305
|
-
|
306
|
-
# RIM Blackberry
|
307
|
-
expect(recognize("Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+")).to eq([:blackberry, "7.1.0.346", :blackberry])
|
308
|
-
expect(recognize("Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; pt) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+")).to eq([:blackberry, "6.0.0.546", :blackberry])
|
309
|
-
|
310
|
-
# Windows Phone
|
311
|
-
expect(recognize("Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; SGH-i917)")).to eq([:windows_phone, "9.0", :windows_phone])
|
312
|
-
expect(recognize("Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro")).to eq([:windows_phone, "7.0", :windows_phone])
|
313
|
-
|
314
|
-
# Symbian
|
315
|
-
expect(recognize("Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaC6-00/20.0.042; Profile/MIDP-2.1 Configuration/CLDC-1.1; zh-hk) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.2.6.9 3gpp-gba")).to eq([:mobile, "7.2.6.9", :symbian])
|
316
|
-
|
317
|
-
# Amazon Kindle
|
318
|
-
expect(recognize("Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 600x800)")).to eq([:kindle, "2.0", :kindle])
|
319
|
-
expect(recognize("Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)")).to eq([:kindle, "1.0", :kindle])
|
320
|
-
|
321
|
-
# Sony Playstation Portable
|
322
|
-
expect(recognize("PSP (PlayStation Portable); 2.00")).to eq([:psp, "2.00", :psp])
|
323
|
-
expect(recognize("Mozilla/4.0 (PSP (PlayStation Portable); 2.00)")).to eq([:psp, "2.00", :psp])
|
324
|
-
|
325
|
-
# Sony Playstation 3
|
326
|
-
expect(recognize("Mozilla/5.0 (PLAYSTATION 3; 3.55)")).to eq([:ps3, "3.55", :ps3])
|
327
|
-
expect(recognize("Mozilla/5.0 (PLAYSTATION 3; 1.70)")).to eq([:ps3, "1.70", :ps3])
|
328
|
-
|
329
|
-
# Nintendo Wii
|
330
|
-
expect(recognize("Opera/9.30 (Nintendo Wii; U; ; 2071; Wii Shop Channel/1.0; en)")).to eq([:opera, "2071", :wii])
|
331
|
-
expect(recognize("Opera/9.30 (Nintendo Wii; U; ; 2047-7;pt-br)")).to eq([:opera, "2047", :wii])
|
332
|
-
|
333
|
-
# Mobile browsers
|
334
|
-
expect(recognize("Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint;PPC-i830; PPC; 240x320)")).to eq([:mobile, "4.0", :windows])
|
335
|
-
|
336
|
-
# Generic Webkit
|
337
|
-
expect(recognize("Midori/0.2.0 (X11; Linux i686; U; de-de) WebKit/531.2+")).to eq([:webkit, "531.2", :linux])
|
338
|
-
expect(recognize("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-de) AppleWebKit/531.21.8 (KHTML, like Gecko) NetNewsWire/3.2.3")).to eq([:webkit, "531.21.8", :osx])
|
339
|
-
|
340
|
-
# Generic Gecko
|
341
|
-
expect(recognize("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a3pre) Gecko/20070330")).to eq([:gecko, "1.9a3pre", :linux])
|
342
|
-
expect(recognize("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko")).to eq([:gecko, "1.9.2a1pre", :windows])
|
343
|
-
|
344
|
-
# QuickTime
|
345
|
-
expect(recognize("QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)")).to eq([:quicktime, "7.6.2", :windows])
|
346
|
-
expect(recognize("QuickTime/7.6 (qtver=7.6;cpu=IA32;os=Mac 10,5,7)")).to eq([:quicktime, "7.6", :osx])
|
347
|
-
|
348
|
-
# CoreMedia
|
349
|
-
expect(recognize("Apple iPhone v1.1.1 CoreMedia v1.0.0.3A110a")).to eq([:coremedia, "1.0.0.3A110a", :ios])
|
350
|
-
expect(recognize("Apple Mac OS X v10.6.6 CoreMedia v1.0.0.10J567")).to eq([:coremedia, "1.0.0.10J567", :osx])
|
351
|
-
|
352
|
-
# Generic
|
353
|
-
browser.class.add(:browsers, ::Brauser::Definition.new(:generic, "NAME", "NAME", "NAME"))
|
354
|
-
browser.class.add(:platforms, ::Brauser::Definition.new(:generic, "NAME", "NAME"))
|
355
|
-
expect(recognize("NAME")).to eq([:generic, "NAME", :generic])
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
describe "#parse_accept_language" do
|
360
|
-
it "should parse languages" do
|
361
|
-
expect(browser.parse_accept_language).to eq([])
|
362
|
-
expect(browser.parse_accept_language(nil)).to eq([])
|
363
|
-
expect(browser.parse_accept_language("IT")).to eq(["it"])
|
364
|
-
expect(browser.parse_accept_language("IT;q=0.7, EN;q=0.3")).to eq(["it", "en"])
|
365
|
-
expect(browser.parse_accept_language("It;q=0.7, eN;q=0.3")).to eq(["it", "en"])
|
366
|
-
expect(browser.parse_accept_language("IT;q=0.7, ")).to eq(["it"])
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
describe "#is" do
|
371
|
-
it "should at first call #parse_agent" do
|
372
|
-
browser.name = nil
|
373
|
-
expect(browser).to receive(:parse_agent)
|
374
|
-
browser.is
|
375
|
-
end
|
376
|
-
|
377
|
-
it "should recognized names" do
|
378
|
-
browser.name = :chrome
|
379
|
-
expect(browser.is.result).to be_true
|
380
|
-
expect(browser.is(:chrome).result).to be_true
|
381
|
-
expect(browser.is(:capable).result).to be_true
|
382
|
-
|
383
|
-
browser.name = :ipad
|
384
|
-
expect(browser.is([:tablet, :blackberry]).result).to be_true
|
385
|
-
|
386
|
-
browser.name = :msie
|
387
|
-
browser.version = "7.0"
|
388
|
-
expect(browser.is(:capable).result).to be_false
|
389
|
-
browser.version = "9.0"
|
390
|
-
expect(browser.is(:capable).result).to be_true
|
391
|
-
|
392
|
-
expect(browser).to receive(:version?).exactly(2).and_call_original
|
393
|
-
expect(browser).to receive(:on?).and_call_original
|
394
|
-
expect(browser.is(:capable, {gte: 8}).result).to be_true
|
395
|
-
browser.platform = :windows
|
396
|
-
|
397
|
-
expect(browser.is(:capable, {gt: 7}, [:windows]).result).to be_true
|
46
|
+
describe "#accepts?" do
|
47
|
+
it "should return whether the browser accept at least one of the languages" do
|
48
|
+
expect(subject.accepts?("IT")).to be_truthy
|
49
|
+
expect(subject.accepts?("IT", :en)).to be_truthy
|
50
|
+
expect(subject.accepts?("ES", :de)).to be_falsey
|
51
|
+
expect(subject.accepts?).to be_falsey
|
398
52
|
end
|
399
53
|
end
|
400
54
|
|
401
55
|
describe "#is?" do
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
expect(browser.is?(:msie)).to be_true
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
describe "#version" do
|
413
|
-
it "should at first call #parse_agent" do
|
414
|
-
browser.version = nil
|
415
|
-
expect(browser).to receive(:parse_agent)
|
416
|
-
browser.v
|
417
|
-
end
|
418
|
-
|
419
|
-
it "should return the version if called without arguments" do
|
420
|
-
browser.version = "3.4.5"
|
421
|
-
expect(browser.version).to eq("3.4.5")
|
422
|
-
end
|
423
|
-
|
424
|
-
it "should compare browser versions" do
|
425
|
-
browser.version = "3.4.5"
|
426
|
-
|
427
|
-
expect(browser.version(lt: 7).result).to be_true
|
428
|
-
expect(browser.version(lte: 3).result).to be_false
|
429
|
-
expect(browser.version(eq: 3).result).to be_false
|
430
|
-
expect(browser.version(gte: 3).result).to be_true
|
431
|
-
expect(browser.version(gt: 4).result).to be_false
|
432
|
-
expect(browser.version(gt: 3.5).result).to be_false
|
433
|
-
expect(browser.version(foo: "3").result).to be_false
|
434
|
-
expect(browser.v(">= 3.5").result).to be_false
|
435
|
-
expect(browser.v("< 7 && > 3").result).to be_true
|
436
|
-
expect(browser.v("< 7 && > 3 && FOO NO").result).to be_true
|
437
|
-
expect(browser.v("<= 7 && >= 3 && FOO NO").result).to be_true
|
438
|
-
expect(browser.v("= 7 && == 3 && FOO NO").result).to be_false
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
describe "#version?" do
|
443
|
-
it "should call the query and then fetch the result" do
|
444
|
-
browser.version = "7.0"
|
445
|
-
expect(browser.version?(">= 8")).to be_false
|
446
|
-
expect(browser.v?(">= 7")).to be_true
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
describe "#on" do
|
451
|
-
it "should at first call #parse_agent" do
|
452
|
-
browser.platform = nil
|
453
|
-
expect(browser).to receive(:parse_agent)
|
454
|
-
browser.on
|
455
|
-
end
|
456
|
-
|
457
|
-
it "should detect platforms" do
|
458
|
-
browser.platform = :windows
|
459
|
-
expect(browser.on.result).to be_true
|
460
|
-
expect(browser.on(:windows).result).to be_true
|
461
|
-
expect(browser.on([:osx, :linux]).result).to be_false
|
462
|
-
end
|
463
|
-
end
|
464
|
-
|
465
|
-
describe "#on?" do
|
466
|
-
it "should call the query and then fetch the result" do
|
467
|
-
browser.platform = :windows
|
468
|
-
|
469
|
-
expect(browser).to receive("on").exactly(2).and_call_original
|
470
|
-
|
471
|
-
expect(browser.on?(:osx)).to be_false
|
472
|
-
expect(browser.on?(:windows)).to be_true
|
473
|
-
end
|
474
|
-
end
|
475
|
-
|
476
|
-
describe "#accepts" do
|
477
|
-
it "should at first call #parse_accept_language" do
|
478
|
-
browser.languages = nil
|
479
|
-
expect(browser).to receive(:parse_accept_language)
|
480
|
-
browser.accepts
|
481
|
-
end
|
482
|
-
|
483
|
-
it "should detect languages" do
|
484
|
-
browser.languages = []
|
485
|
-
expect(browser.accepts.result).to be_false
|
486
|
-
expect(browser.accepts("it").result).to be_false
|
487
|
-
expect(browser.accepts(["it", "en"]).result).to be_false
|
488
|
-
|
489
|
-
browser.languages = ["it", "en"]
|
490
|
-
expect(browser.accepts(nil).result).to be_false
|
491
|
-
expect(browser.accepts([]).result).to be_false
|
492
|
-
expect(browser.accepts("it").result).to be_true
|
493
|
-
expect(browser.accepts(["it", "en"]).result).to be_true
|
494
|
-
expect(browser.accepts(["it", "es"]).result).to be_true
|
495
|
-
expect(browser.accepts(["es", "en"]).result).to be_true
|
496
|
-
expect(browser.accepts("es").result).to be_false
|
497
|
-
expect(browser.accepts(["es", "de"]).result).to be_false
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
describe "#accepts?" do
|
502
|
-
it "should call the query and then fetch the result" do
|
503
|
-
browser.languages = ["it"]
|
56
|
+
describe "should check if the browser matches several criteria" do
|
57
|
+
it "- name" do
|
58
|
+
expect(subject.is?(name: :chrome)).to be_truthy
|
59
|
+
expect(subject.is?(name: [:firefox, :chrome])).to be_truthy
|
60
|
+
expect(subject.is?(name: :opera)).to be_falsey
|
61
|
+
end
|
504
62
|
|
505
|
-
|
63
|
+
it "- engine" do
|
64
|
+
expect(subject.is?(engine: :chrome)).to be_truthy
|
65
|
+
expect(subject.is?(engine: [:firefox, :chrome])).to be_truthy
|
66
|
+
expect(subject.is?(engine: :opera)).to be_falsey
|
67
|
+
expect(subject.is?(name: :chrome, engine: :opera)).to be_truthy
|
68
|
+
end
|
506
69
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
70
|
+
it "- version" do
|
71
|
+
expect(subject.is?(version: "> 21")).to be_truthy
|
72
|
+
expect(subject.is?(version: "> 21 && < 22")).to be_truthy
|
73
|
+
expect(subject.is?(version: "> 23")).to be_falsey
|
74
|
+
expect(subject.is?(version: "> 21 && > 21.0.2000")).to be_falsey
|
75
|
+
expect(subject.is?(version: "capable")).to be_truthy
|
511
76
|
|
512
|
-
|
513
|
-
|
514
|
-
browser.parse_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.82 Safari/537.1")
|
515
|
-
expect(browser.supported?(chrome: 21)).to be_true
|
516
|
-
expect(browser.supported?(chrome: 31)).to be_false
|
517
|
-
expect(browser.supported?(chrome: "21.2")).to be_false
|
518
|
-
expect(browser.supported?(firefox: 11)).to be_false
|
519
|
-
end
|
77
|
+
subject = Brauser::Browser.new("Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/32.0")
|
78
|
+
expect(subject.is?(version: "capable")).to be_truthy
|
520
79
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
expect(browser.supported?(path)).to be_true
|
525
|
-
end
|
526
|
-
end
|
80
|
+
subject = Brauser::Browser.new("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; .NET4.0C; Tablet PC 2.0")
|
81
|
+
expect(subject.is?(version: "capable")).to be_falsey
|
82
|
+
end
|
527
83
|
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
::Brauser::Browser.new
|
534
|
-
end
|
84
|
+
it "- platform" do
|
85
|
+
expect(subject.is?(platform: :osx)).to be_truthy
|
86
|
+
expect(subject.is?(platform: [:windows, :osx])).to be_truthy
|
87
|
+
expect(subject.is?(engine: :linux)).to be_falsey
|
88
|
+
end
|
535
89
|
|
536
|
-
|
537
|
-
|
538
|
-
|
90
|
+
it "- languages" do
|
91
|
+
expect(subject.is?(languages: :it)).to be_truthy
|
92
|
+
expect(subject.is?(languages: [:es, :en])).to be_truthy
|
93
|
+
expect(subject.is?(languages: :de)).to be_falsey
|
94
|
+
end
|
539
95
|
|
540
|
-
|
541
|
-
|
542
|
-
|
96
|
+
it "- combination" do
|
97
|
+
expect(subject.is?(name: :chrome, version: "> 21")).to be_truthy
|
98
|
+
expect(subject.is?(name: :chrome, version: "> 21 && < 22")).to be_truthy
|
99
|
+
expect(subject.is?(version: "> 21", platform: :osx)).to be_truthy
|
100
|
+
end
|
543
101
|
end
|
544
102
|
end
|
545
103
|
|
546
|
-
describe "
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
browser.platform = :windows
|
551
|
-
end
|
552
|
-
|
553
|
-
it "calling the right method" do
|
554
|
-
expect(browser).to receive(:is?).with("opera_mobile", {}, []).and_call_original
|
555
|
-
expect(browser).to receive(:version?).with("< 3").and_call_original
|
556
|
-
expect(browser).to receive(:on?).with("windows").and_call_original
|
557
|
-
|
558
|
-
expect(browser.is_opera_mobile_v_lt_3_on_windows?).to be_true
|
559
|
-
end
|
560
|
-
|
561
|
-
it "returning as query" do
|
562
|
-
expect(browser.is_opera_mobile_version_lt_3_on_windows).to be_a(::Brauser::Query)
|
563
|
-
end
|
564
|
-
|
565
|
-
it "returning as boolean" do
|
566
|
-
expect(browser.is_opera_mobile_v_gt_3_on_windows?).to be_false
|
567
|
-
end
|
568
|
-
|
569
|
-
it "correctly analyzing version" do
|
570
|
-
expect(browser).to receive(:is?).with("opera_mobile", {}, []).at_least(1).and_call_original
|
571
|
-
|
572
|
-
expect(browser).to receive(:version?).with("<= 3").and_call_original
|
573
|
-
expect(browser.is_opera_mobile_v_lte_3).to be_true
|
574
|
-
|
575
|
-
expect(browser).to receive(:version?).with("< 3 && >= 3").and_call_original
|
576
|
-
expect(browser.is_opera_mobile_v_lt_3_and_gte_3?).to be_false
|
577
|
-
|
578
|
-
expect(browser).to receive(:version?).with("&& >= 3").and_call_original
|
579
|
-
expect(browser.is_opera_mobile_v_and_gte_3?).to be_false
|
580
|
-
|
581
|
-
expect(browser).to receive(:version?).with("< 3 &&").and_call_original
|
582
|
-
expect(browser.is_opera_mobile_v_lt_3_and?).to be_true
|
583
|
-
|
584
|
-
expect(browser).to receive(:version?).with("> 2").and_return(true)
|
585
|
-
expect(browser.is_opera_mobile_v_gt_2?).to be_true
|
586
|
-
|
587
|
-
expect(browser).to receive(:version?).with("== 3.4.5alpha").and_return(false)
|
588
|
-
expect(browser.is_opera_mobile_v_eq_3_4_5alpha_is_3?).to be_false
|
589
|
-
end
|
590
|
-
|
591
|
-
it "immediately invalidate a query if one of the methods is invalid" do
|
592
|
-
expect(browser).not_to receive(:is)
|
593
|
-
expect(browser).not_to receive(:v)
|
594
|
-
expect(browser).not_to receive(:on)
|
595
|
-
|
596
|
-
expect{ browser.is_opera_mobile_vv_lt_3_on_windows? }.to raise_error(NoMethodError)
|
104
|
+
describe "#method_missing" do
|
105
|
+
it "should attempt to run #is? with the method as name if it ends with a ?" do
|
106
|
+
expect(subject.chrome?).to be_truthy
|
107
|
+
expect(subject.firefox?).to be_falsey
|
597
108
|
end
|
598
109
|
|
599
|
-
it "
|
600
|
-
expect{
|
601
|
-
expect{ browser.isa_opera_mobile_vv_lt_3_on_windows? }.to raise_error(NoMethodError)
|
602
|
-
expect{ browser.is_opera_mobile_v_lt_3_ona_windows? }.to raise_error(NoMethodError)
|
110
|
+
it "should fallback to the original for the rest" do
|
111
|
+
expect { subject.not_supported }.to raise_error(NoMethodError)
|
603
112
|
end
|
604
113
|
end
|
605
114
|
end
|