brauser 2.1.4 → 3.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.
- data/Gemfile +3 -3
- data/README.md +3 -3
- data/brauser.gemspec +1 -1
- data/doc/Brauser.html +6 -5
- data/doc/Brauser/Browser.html +553 -541
- data/doc/Brauser/BrowserMethods.html +1 -1
- data/doc/Brauser/BrowserMethods/Attributes.html +21 -21
- data/doc/Brauser/BrowserMethods/General.html +1 -1
- data/doc/Brauser/BrowserMethods/General/ClassMethods.html +29 -29
- data/doc/Brauser/BrowserMethods/Parsing.html +15 -15
- data/doc/Brauser/BrowserMethods/PartialQuerying.html +45 -55
- data/doc/Brauser/BrowserMethods/Querying.html +21 -21
- data/doc/Brauser/BrowserMethods/Register.html +1 -1
- data/doc/Brauser/BrowserMethods/Register/ClassMethods.html +116 -425
- data/doc/Brauser/Hooks.html +1 -1
- data/doc/Brauser/Hooks/RubyOnRails.html +2 -2
- data/doc/Brauser/Query.html +45 -1267
- data/doc/Brauser/Version.html +4 -4
- data/doc/_index.html +33 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +4 -4
- data/doc/index.html +4 -4
- data/doc/method_list.html +89 -65
- data/doc/top-level-namespace.html +1 -1
- data/lib/brauser.rb +1 -0
- data/lib/brauser/browser.rb +163 -234
- data/lib/brauser/definition.rb +54 -0
- data/lib/brauser/hooks.rb +1 -1
- data/lib/brauser/query.rb +68 -59
- data/lib/brauser/version.rb +3 -3
- data/spec/brauser/browser_spec.rb +222 -292
- data/spec/brauser/definition_spec.rb +39 -0
- data/spec/brauser/hooks_spec.rb +2 -3
- data/spec/brauser/query_spec.rb +29 -33
- metadata +8 -5
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
|
4
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "spec_helper"
|
8
|
+
|
9
|
+
describe Brauser::Definition do
|
10
|
+
let(:definition) { ::Brauser::Definition.new(:tag, "Label", "ABC", /(abc)+/) }
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "should assign attributes" do
|
14
|
+
other = ::Brauser::Definition.new("A", "B", "C", "D")
|
15
|
+
expect(other.tag).to eq("A")
|
16
|
+
expect(other.label).to eq("B")
|
17
|
+
expect(other.primary).to eq("C")
|
18
|
+
expect(other.secondary).to eq("D")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#match" do
|
23
|
+
it "should apply the correct matcher and return the correct value" do
|
24
|
+
expect(definition.match(:primary, nil, "ABC")).to eq("ABC")
|
25
|
+
expect(definition.match(:primary, nil, "CDE")).to be_nil
|
26
|
+
expect(definition.match(:secondary, nil, "abcabc")).to be_a(MatchData)
|
27
|
+
expect(definition.match(:secondary, nil, "abx")).to be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should support a block matcher" do
|
31
|
+
definition.primary = Proc.new { |definition, a, b, c| a + b + c }
|
32
|
+
expect(definition.match(:primary, nil, 1, 2, 3)).to eq(6)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return nil when the matcher is not valid" do
|
36
|
+
expect(definition.match(:tertiary)).to be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/brauser/hooks_spec.rb
CHANGED
@@ -15,13 +15,12 @@ describe Brauser::Hooks::RubyOnRails do
|
|
15
15
|
|
16
16
|
it "should memoize browser" do
|
17
17
|
browser = controller.browser
|
18
|
-
expect(browser).to be_a(Brauser::Browser)
|
18
|
+
expect(browser).to be_a(::Brauser::Browser)
|
19
19
|
expect(controller.browser).to eq(browser)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should
|
22
|
+
it "should detect browser again" do
|
23
23
|
browser = controller.browser
|
24
24
|
expect(controller.browser(true)).not_to eq(browser)
|
25
|
-
|
26
25
|
end
|
27
26
|
end
|
data/spec/brauser/query_spec.rb
CHANGED
@@ -17,104 +17,100 @@ describe Brauser::Query do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
let(:browser){ Brauser::Browser.new("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", "it;q=0.7, en;q=0.3") }
|
21
|
-
let(:query) { Brauser::Query.new(browser, true) }
|
20
|
+
let(:browser){ ::Brauser::Browser.new("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", "it;q=0.7, en;q=0.3") }
|
21
|
+
let(:query) { ::Brauser::Query.new(browser, true) }
|
22
22
|
|
23
23
|
describe "#is" do
|
24
24
|
it "should call the final corresponding method and then return self" do
|
25
|
-
query.should_receive(:is?).
|
25
|
+
query.should_receive(:is?).and_call_original
|
26
26
|
expect(query.is(:msie)).to be(query)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#is?" do
|
31
31
|
it "should call the browser's corresponding method and update the result" do
|
32
|
-
|
33
|
-
browser.should_receive(:is?).with(:msie, {}, []).and_return(false)
|
32
|
+
browser.should_receive(:is?).with(:msie, {}, []).and_call_original
|
34
33
|
expect(query.is?(:msie)).to be_false
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
describe "#v" do
|
39
38
|
it "should call the final corresponding method and then return self" do
|
40
|
-
query.should_receive(:v?).
|
39
|
+
query.should_receive(:v?).and_call_original
|
41
40
|
expect(query.v(">= 9")).to be(query)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
44
|
describe "#v?" do
|
46
45
|
it "should call the browser's corresponding method and update the result" do
|
47
|
-
|
48
|
-
|
49
|
-
expect(query.v?(">= 9")).to be_false
|
46
|
+
browser.should_receive(:v?).with(">= 9").and_call_original
|
47
|
+
expect(query.v?(">= 9")).to be_true
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
51
|
describe "#on" do
|
54
52
|
it "should call the final corresponding method and then return self" do
|
55
|
-
query.should_receive(:on?).
|
53
|
+
query.should_receive(:on?).and_call_original
|
56
54
|
expect(query.on(:osx)).to be(query)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
58
|
describe "#on?" do
|
61
59
|
it "should call the browser's corresponding method and update the result" do
|
62
|
-
|
63
|
-
|
64
|
-
expect(query.on?(:osx)).to be_false
|
60
|
+
browser.should_receive(:on?).with(:osx).and_call_original
|
61
|
+
expect(query.on?(:osx)).to be_true
|
65
62
|
end
|
66
63
|
|
67
64
|
end
|
68
65
|
|
69
66
|
describe "#accepts" do
|
70
67
|
it "should call the final corresponding method and then return self" do
|
71
|
-
query.should_receive(:accepts?).
|
68
|
+
query.should_receive(:accepts?).and_call_original
|
72
69
|
expect(query.accepts("it")).to be(query)
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
76
73
|
describe "#accepts?" do
|
77
74
|
it "should call the browser's corresponding method and update the result" do
|
78
|
-
|
79
|
-
|
80
|
-
expect(query.accepts?("it")).to be_false
|
75
|
+
browser.should_receive(:accepts?).with("es").and_call_original
|
76
|
+
expect(query.accepts?("es")).to be_false
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
84
80
|
describe "concatenation" do
|
85
81
|
before(:each) do
|
86
|
-
browser.
|
87
|
-
browser.
|
88
|
-
browser.
|
82
|
+
browser.name = :chrome
|
83
|
+
browser.version = "7.1.2"
|
84
|
+
browser.platform = :windows
|
89
85
|
end
|
90
86
|
|
91
87
|
it "should call requested methods on the browser and return a query" do
|
92
|
-
browser.should_receive(:is).
|
93
|
-
browser.should_receive(:v?).
|
94
|
-
browser.should_receive(:on?).
|
88
|
+
browser.should_receive(:is).and_call_original
|
89
|
+
browser.should_receive(:v?).and_call_original
|
90
|
+
browser.should_receive(:on?).and_call_original
|
95
91
|
|
96
|
-
expect(browser.is(:chrome).v(">= 7").on(:osx)).to be_a(Brauser::Query)
|
92
|
+
expect(browser.is(:chrome).v(">= 7").on(:osx)).to be_a(::Brauser::Query)
|
97
93
|
end
|
98
94
|
|
99
95
|
it "should call methods while result is true" do
|
100
|
-
browser.should_receive(:is).
|
101
|
-
browser.should_receive(:v?).
|
96
|
+
browser.should_receive(:is).and_call_original
|
97
|
+
browser.should_receive(:v?).and_call_original
|
102
98
|
browser.should_not_receive(:on?)
|
103
99
|
|
104
|
-
expect(browser.is(:chrome).v(">=
|
100
|
+
expect(browser.is(:chrome).v(">= 9").on(:osx)).to be_a(::Brauser::Query)
|
105
101
|
end
|
106
102
|
|
107
103
|
it "when the last method is the question mark, it should return the evaluation to boolean" do
|
108
|
-
browser.should_receive(:is).
|
109
|
-
browser.should_receive(:v?).
|
110
|
-
browser.should_receive(:on?).
|
104
|
+
browser.should_receive(:is).and_call_original
|
105
|
+
browser.should_receive(:v?).and_call_original
|
106
|
+
browser.should_receive(:on?).and_call_original
|
111
107
|
|
112
|
-
expect(browser.is(:chrome).v(">= 7").on?(:osx)).to
|
108
|
+
expect(browser.is(:chrome).v(">= 7").on?(:osx)).to be_false
|
113
109
|
end
|
114
110
|
|
115
111
|
it "should return the result when ending the query with #result" do
|
116
|
-
browser.should_receive(:is).
|
117
|
-
browser.should_receive(:v?).
|
112
|
+
browser.should_receive(:is).and_call_original
|
113
|
+
browser.should_receive(:v?).and_call_original
|
118
114
|
browser.should_not_receive(:on?)
|
119
115
|
|
120
116
|
expect(browser.is(:chrome).v(">= 9").on(:osx).result).to be_false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brauser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: lazier
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 3.0.0
|
30
30
|
description: A framework agnostic browser detection and querying helper.
|
31
31
|
email:
|
32
32
|
- shogun_panda@me.com
|
@@ -73,10 +73,12 @@ files:
|
|
73
73
|
- doc/top-level-namespace.html
|
74
74
|
- lib/brauser.rb
|
75
75
|
- lib/brauser/browser.rb
|
76
|
+
- lib/brauser/definition.rb
|
76
77
|
- lib/brauser/hooks.rb
|
77
78
|
- lib/brauser/query.rb
|
78
79
|
- lib/brauser/version.rb
|
79
80
|
- spec/brauser/browser_spec.rb
|
81
|
+
- spec/brauser/definition_spec.rb
|
80
82
|
- spec/brauser/hooks_spec.rb
|
81
83
|
- spec/brauser/query_spec.rb
|
82
84
|
- spec/brauser_spec.rb
|
@@ -103,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
105
|
version: '0'
|
104
106
|
segments:
|
105
107
|
- 0
|
106
|
-
hash: -
|
108
|
+
hash: -647433580112480760
|
107
109
|
requirements: []
|
108
110
|
rubyforge_project: brauser
|
109
111
|
rubygems_version: 1.8.25
|
@@ -112,6 +114,7 @@ specification_version: 3
|
|
112
114
|
summary: A framework agnostic browser detection and querying helper.
|
113
115
|
test_files:
|
114
116
|
- spec/brauser/browser_spec.rb
|
117
|
+
- spec/brauser/definition_spec.rb
|
115
118
|
- spec/brauser/hooks_spec.rb
|
116
119
|
- spec/brauser/query_spec.rb
|
117
120
|
- spec/brauser_spec.rb
|