opal-jquery 0.4.2 → 0.4.3
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 +5 -5
- data/.editorconfig +12 -0
- data/.travis.yml +22 -15
- data/CHANGELOG.md +41 -3
- data/Gemfile +13 -2
- data/README.md +1 -1
- data/Rakefile +22 -4
- data/config.ru +4 -6
- data/lib/opal/jquery/element.rb +77 -24
- data/lib/opal/jquery/http.rb +5 -1
- data/lib/opal/jquery/version.rb +1 -1
- data/opal-jquery.gemspec +7 -6
- data/{spec → spec-opal}/document_spec.rb +11 -4
- data/{spec → spec-opal}/element/after_spec.rb +1 -1
- data/{spec → spec-opal}/element/animations_spec.rb +5 -5
- data/{spec → spec-opal}/element/append_spec.rb +1 -1
- data/{spec → spec-opal}/element/append_to_spec.rb +1 -1
- data/{spec → spec-opal}/element/at_spec.rb +1 -1
- data/{spec → spec-opal}/element/attributes_spec.rb +1 -1
- data/{spec → spec-opal}/element/before_spec.rb +1 -1
- data/{spec → spec-opal}/element/class_name_spec.rb +2 -2
- data/{spec → spec-opal}/element/css_spec.rb +3 -3
- data/{spec → spec-opal}/element/display_spec.rb +6 -6
- data/spec-opal/element/expose_spec.rb +73 -0
- data/{spec → spec-opal}/element/height_width_spec.rb +1 -1
- data/{spec → spec-opal}/element/inspect_spec.rb +1 -1
- data/{spec → spec-opal}/element/iterable_spec.rb +1 -1
- data/{spec → spec-opal}/element/length_spec.rb +1 -1
- data/spec-opal/element/method_missing_spec.rb +34 -0
- data/{spec → spec-opal}/element/prepend_spec.rb +1 -1
- data/{spec → spec-opal}/element/to_s_spec.rb +1 -1
- data/{spec → spec-opal}/element/traversing_spec.rb +5 -5
- data/spec-opal/element_spec.rb +261 -0
- data/{spec → spec-opal}/event_spec.rb +1 -1
- data/{spec → spec-opal}/fixtures/simple.txt +0 -0
- data/{spec → spec-opal}/fixtures/user.json +0 -0
- data/{spec → spec-opal}/http_spec.rb +1 -1
- data/{spec → spec-opal}/jquery/index.html.erb +1 -1
- data/spec-opal/jquery/index3.html.erb +10 -0
- data/{spec/jquery/jquery.js → spec-opal/jquery/jquery-1.8.3.js} +0 -0
- data/spec-opal/jquery/jquery-3.0.0.js +4 -0
- data/spec-opal/kernel_spec.rb +15 -0
- data/{spec → spec-opal}/local_storage_spec.rb +1 -1
- data/{spec → spec-opal}/spec_helper.rb +10 -0
- data/{spec → spec-opal}/zepto/index.html.erb +0 -0
- data/{spec → spec-opal}/zepto/zepto.js +0 -0
- metadata +63 -76
- data/spec/element/method_missing_spec.rb +0 -32
- data/spec/element_spec.rb +0 -273
- data/spec/kernel_spec.rb +0 -7
@@ -1,22 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Document do
|
3
|
+
RSpec.describe 'Document' do
|
4
4
|
subject { Document }
|
5
5
|
|
6
6
|
describe "ready?" do
|
7
|
+
it "accepts a block" do
|
8
|
+
Document.ready? {
|
9
|
+
puts `$.fn.jquery`
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
7
13
|
it "accepts a block" do
|
8
14
|
Document.ready? { }
|
9
15
|
end
|
10
16
|
end
|
11
|
-
|
17
|
+
|
12
18
|
describe "ready" do
|
19
|
+
p self.ancestors
|
13
20
|
async "resolves when document is ready" do
|
14
|
-
Document.ready.then do
|
21
|
+
Document.ready.then do
|
15
22
|
async { Document.ready.resolved?.should be_truthy }
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
19
|
-
|
26
|
+
|
20
27
|
describe "title" do
|
21
28
|
it "gets the document title" do
|
22
29
|
Document.title.should be_kind_of(String)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element animation methods" do
|
3
|
+
RSpec.describe "Element animation methods" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="animate-foo"></div>
|
6
6
|
HTML
|
@@ -41,16 +41,16 @@ describe "Element animation methods" do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe "Element effects methods" do
|
44
|
+
RSpec.describe "Element effects methods" do
|
45
45
|
html <<-HTML
|
46
46
|
<div id="effects-foo"></div>
|
47
47
|
HTML
|
48
|
-
|
48
|
+
|
49
49
|
describe "#fadeout / #fadein" do
|
50
50
|
async "should fade the element out first" do
|
51
51
|
foo = Element.find "#effects-foo"
|
52
52
|
foo.effect(:fade_out)
|
53
|
-
|
53
|
+
|
54
54
|
delay 1 do
|
55
55
|
async {
|
56
56
|
foo.css("display").should eq("none")
|
@@ -64,4 +64,4 @@ describe "Element effects methods" do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element#class_name" do
|
3
|
+
RSpec.describe "Element#class_name" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="foo" class="whiskey"></div>
|
6
6
|
<div id="bar" class="scotch brandy"></div>
|
@@ -30,7 +30,7 @@ describe "Element#class_name" do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe "Element#class_name=" do
|
33
|
+
RSpec.describe "Element#class_name=" do
|
34
34
|
before do
|
35
35
|
@div = Element.parse <<-HTML
|
36
36
|
<div id="class-name-set-spec">
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element#css" do
|
3
|
+
RSpec.describe "Element#css" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="foo" style="background-color:rgb(15,99,30); color:;"></div>
|
6
6
|
<div id="bar"></div>
|
@@ -32,8 +32,8 @@ describe "Element#css" do
|
|
32
32
|
it "should set the properties" do
|
33
33
|
hash = Element.find("#hash")
|
34
34
|
hash.css(:width => "100px", :height => "200px")
|
35
|
-
hash.css("width").should be_kind_of(String)
|
36
|
-
hash.css("height").should be_kind_of(String)
|
35
|
+
hash.css("width").should be_kind_of(String)
|
36
|
+
hash.css("height").should be_kind_of(String)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return self" do
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element display methods" do
|
3
|
+
RSpec.describe "Element display methods" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="shown"></div>
|
6
6
|
<div id="hidden" style="display: none"></div>
|
7
7
|
HTML
|
8
8
|
|
9
9
|
it "hides an element" do
|
10
|
-
element = Element.find('#shown')
|
10
|
+
element = Element.find('#shown')
|
11
11
|
element.css('display').should == 'block'
|
12
12
|
element.hide
|
13
13
|
element.css('display').should == 'none'
|
14
14
|
end
|
15
15
|
|
16
|
-
it "shows an element" do
|
17
|
-
element = Element.find('#hidden')
|
16
|
+
it "shows an element" do
|
17
|
+
element = Element.find('#hidden')
|
18
18
|
element.css('display').should == 'none'
|
19
19
|
element.show
|
20
20
|
element.css('display').should == 'block'
|
21
21
|
end
|
22
22
|
|
23
23
|
it "toggles on a hidden element" do
|
24
|
-
element = Element.find('#hidden')
|
24
|
+
element = Element.find('#hidden')
|
25
25
|
element.css('display').should == 'none'
|
26
26
|
element.toggle
|
27
27
|
element.css('display').should == 'block'
|
28
28
|
end
|
29
29
|
|
30
30
|
it "toggles off a displayed element" do
|
31
|
-
element = Element.find('#shown')
|
31
|
+
element = Element.find('#shown')
|
32
32
|
element.css('display').should == 'block'
|
33
33
|
element.toggle
|
34
34
|
element.css('display').should == 'none'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Element#expose" do
|
4
|
+
subject(:element) { Element.new }
|
5
|
+
before do
|
6
|
+
`$.fn.exposableMethod = function() {return 123}`
|
7
|
+
`$.fn.exposableMethod2 = function() {return 12}`
|
8
|
+
`$.fn.opal_specs_extension = function() {return "foo_bar_baz";};`
|
9
|
+
`$.fn.opal_specs_args = function() {return Array.prototype.slice.call(arguments);};`
|
10
|
+
Element.expose :opal_specs_extension, :opal_specs_args
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
`delete $.fn.exposableMethod; delete $.fn.$exposableMethod;`
|
15
|
+
`delete $.fn.exposableMethod2; delete $.fn.$exposableMethod2;`
|
16
|
+
`delete $.fn.opal_specs_extension; delete $.fn.$opal_specs_extension;`
|
17
|
+
`delete $.fn.opal_specs_args; delete $.fn.$opal_specs_args;`
|
18
|
+
end
|
19
|
+
|
20
|
+
it "exposes jquery plugins by given name" do
|
21
|
+
Element.new.opal_specs_extension.should eq("foo_bar_baz")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "forwards any args onto native function" do
|
25
|
+
Element.new.opal_specs_args(:foo, 42, false).should eq([:foo, 42, false])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "only forwards calls when a native method exists" do
|
29
|
+
expect {
|
30
|
+
Element.new.some_unknown_plugin
|
31
|
+
}.to raise_error(Exception)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'exposes methods defined on $.fn' do
|
35
|
+
expect(element).to respond_to(:exposableMethod) # via #respond_to_missing?
|
36
|
+
expect(element.methods).not_to include(:exposableMethod)
|
37
|
+
Element.expose :exposableMethod
|
38
|
+
expect(element.methods).to include(:exposableMethod)
|
39
|
+
expect(element).to respond_to(:exposableMethod) # via method missing
|
40
|
+
expect(element.exposableMethod).to eq(123)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'work if exposing the same method multiple times' do
|
44
|
+
Element.expose :exposableMethod
|
45
|
+
Element.expose :exposableMethod
|
46
|
+
expect(element.exposableMethod).to eq(123)
|
47
|
+
|
48
|
+
Element.expose :exposableMethod, :exposableMethod
|
49
|
+
expect(element.exposableMethod).to eq(123)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'work if exposing multiple methods' do
|
53
|
+
Element.expose :exposableMethod, :exposableMethod2
|
54
|
+
expect(element.exposableMethod).to eq(123)
|
55
|
+
expect(element.exposableMethod2).to eq(12)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'does not call method_missing after the method is exposed' do
|
59
|
+
pending "broken on opal < 0.11" if RUBY_ENGINE_VERSION.to_f < 0.11
|
60
|
+
|
61
|
+
expect(element).to receive(:method_missing).once.with(:exposableMethod)
|
62
|
+
def element.method_missing(name)
|
63
|
+
"#{name} (via method_missing)"
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(element.exposableMethod).to eq("exposableMethod (via method_missing)")
|
67
|
+
Element.expose :exposableMethod
|
68
|
+
|
69
|
+
expect(element).not_to receive(:method_missing).once
|
70
|
+
element.exposableMethod
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Element#method_missing" do
|
4
|
+
context 'with missing property' do
|
5
|
+
html %{<div id="foo" class="bar"></div>}
|
6
|
+
|
7
|
+
it 'fallsback on method_missing when a method is unknown' do
|
8
|
+
expect(Element['#foo']).to respond_to(:offsetParent)
|
9
|
+
expect(Element['#foo'].offsetParent).to eq(Element['body'])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'jQuery plugin methods' do
|
14
|
+
subject(:element) { Element.new }
|
15
|
+
|
16
|
+
before do
|
17
|
+
`$.fn.pluginMethod = function() {return 123}`
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
`delete $.fn.pluginMethod; delete $.fn.$pluginMethod;`
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'calls method_missing' do
|
25
|
+
expect(element).to receive(:method_missing).once.with(:pluginMethod)
|
26
|
+
element.pluginMethod
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'calls forwards to the plugin', :focus do
|
30
|
+
pending "broken on opal < 0.11" if RUBY_ENGINE_VERSION.to_f < 0.11
|
31
|
+
expect(element.pluginMethod).to eq(123)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Element do
|
3
|
+
RSpec.describe Element do
|
4
4
|
before do
|
5
5
|
@div = Element.parse <<-HTML
|
6
6
|
<div id="traversing-spec">
|
@@ -76,7 +76,7 @@ describe Element do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
describe "Element#next" do
|
79
|
+
RSpec.describe "Element#next" do
|
80
80
|
before do
|
81
81
|
@div = Element.parse <<-HTML
|
82
82
|
<div id="next-spec">
|
@@ -101,7 +101,7 @@ describe "Element#next" do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe "Element#parent" do
|
104
|
+
RSpec.describe "Element#parent" do
|
105
105
|
before do
|
106
106
|
@div = Element.parse <<-HTML
|
107
107
|
<div id="foo">
|
@@ -126,7 +126,7 @@ describe "Element#parent" do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe "Element#succ" do
|
129
|
+
RSpec.describe "Element#succ" do
|
130
130
|
before do
|
131
131
|
@div = Element.parse <<-HTML
|
132
132
|
<div id="succ-spec">
|
@@ -151,7 +151,7 @@ describe "Element#succ" do
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
describe "Element#siblings" do
|
154
|
+
RSpec.describe "Element#siblings" do
|
155
155
|
before do
|
156
156
|
@div = Element.parse <<-HTML
|
157
157
|
<div id="siblings-spec">
|
@@ -0,0 +1,261 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Element do
|
4
|
+
context 'events' do
|
5
|
+
html <<-HTML
|
6
|
+
<div id="foo">
|
7
|
+
<div id="bar" class="apples"></div>
|
8
|
+
</div>
|
9
|
+
<div id="baz"></div>
|
10
|
+
HTML
|
11
|
+
|
12
|
+
describe '#on' do
|
13
|
+
it 'adds an event listener onto the elements' do
|
14
|
+
count = 0
|
15
|
+
foo = Element['#foo']
|
16
|
+
|
17
|
+
foo.on(:click) { count += 1 }
|
18
|
+
count.should == 0
|
19
|
+
foo.trigger(:click)
|
20
|
+
count.should == 1
|
21
|
+
foo.trigger(:click)
|
22
|
+
count.should == 2
|
23
|
+
foo.trigger(:mousedown)
|
24
|
+
count.should == 2
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'takes an optional second parameter to delegate events' do
|
28
|
+
count = 0
|
29
|
+
foo = Element['#foo']
|
30
|
+
bar = Element['#bar']
|
31
|
+
|
32
|
+
foo.on(:click, '#bar') { count += 1 }
|
33
|
+
count.should == 0
|
34
|
+
foo.trigger(:click)
|
35
|
+
count.should == 0
|
36
|
+
bar.trigger(:click)
|
37
|
+
count.should == 1
|
38
|
+
bar.trigger(:click)
|
39
|
+
count.should == 2
|
40
|
+
bar.trigger(:mousedown)
|
41
|
+
count.should == 2
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can listen for non-browser events' do
|
45
|
+
count = 0
|
46
|
+
foo = Element['#foo']
|
47
|
+
|
48
|
+
foo.on('opal-is-mega-lolz') { count += 1 }
|
49
|
+
count.should == 0
|
50
|
+
foo.trigger('opal-is-mega-lolz')
|
51
|
+
count.should == 1
|
52
|
+
foo.trigger('opal-is-mega-lolz')
|
53
|
+
count.should == 2
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns the given handler' do
|
57
|
+
handler = proc {}
|
58
|
+
Element['#foo'].on(:click, &handler).should == handler
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'has an Event instance passed to the handler' do
|
62
|
+
foo = Element['#foo']
|
63
|
+
foo.on :click do |event|
|
64
|
+
event.should be_kind_of(Event)
|
65
|
+
end
|
66
|
+
foo.trigger(:click)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'has an Event instance, plus any additional parameters passed to the handler' do
|
70
|
+
foo = Element['#foo']
|
71
|
+
foo.on :bozo do |event, foo, bar, baz, buz|
|
72
|
+
event.should be_kind_of(Event)
|
73
|
+
foo.should == 'foo'
|
74
|
+
bar.should == 'bar'
|
75
|
+
baz.should == 'baz'
|
76
|
+
buz.should == 'buz'
|
77
|
+
end
|
78
|
+
foo.trigger(:bozo, ['foo', 'bar', 'baz', 'buz'])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#off' do
|
83
|
+
it 'removes event handlers that were added using #on' do
|
84
|
+
count = 0
|
85
|
+
foo = Element['#foo']
|
86
|
+
|
87
|
+
handler = foo.on(:click) { count += 1 }
|
88
|
+
count.should == 0
|
89
|
+
foo.trigger(:click)
|
90
|
+
count.should == 1
|
91
|
+
foo.off(:click, handler)
|
92
|
+
count.should == 1
|
93
|
+
foo.trigger(:click)
|
94
|
+
count.should == 1
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'removes event handlers added with a selector' do
|
98
|
+
count = 0
|
99
|
+
foo = Element['#foo']
|
100
|
+
bar = Element['#bar']
|
101
|
+
|
102
|
+
handler = foo.on(:click, '#bar') { count += 1 }
|
103
|
+
count.should == 0
|
104
|
+
bar.trigger(:click)
|
105
|
+
count.should == 1
|
106
|
+
foo.off(:click, '#bar', handler)
|
107
|
+
count.should == 1
|
108
|
+
bar.trigger(:click)
|
109
|
+
count.should == 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'selectors/parse' do
|
115
|
+
html <<-HTML
|
116
|
+
<div id="foo" class="bar"></div>
|
117
|
+
<div class="woosh"></div>
|
118
|
+
<div class="woosh"></div>
|
119
|
+
<div class="find-foo"></div>
|
120
|
+
<div class="find-bar"></div>
|
121
|
+
<div class="find-foo"></div>
|
122
|
+
HTML
|
123
|
+
|
124
|
+
describe ".[]" do
|
125
|
+
it "should be able to find elements with given id" do
|
126
|
+
Element['#foo'].class_name.should == "bar"
|
127
|
+
Element['#foo'].size.should == 1
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should be able to match any valid CSS selector" do
|
131
|
+
Element['.woosh'].should be_kind_of(Element)
|
132
|
+
Element['.woosh'].size.should == 2
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return an empty Elements instance when not matching any elements" do
|
136
|
+
dom = Element['.some-non-existing-class']
|
137
|
+
|
138
|
+
dom.should be_kind_of(Element)
|
139
|
+
dom.size.should == 0
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should accept an HTML string and parse it into a Elements instance" do
|
143
|
+
el = Element['<div id="foo-bar-baz"></div>']
|
144
|
+
|
145
|
+
el.should be_kind_of(Element)
|
146
|
+
el.id.should == "foo-bar-baz"
|
147
|
+
el.size.should == 1
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe ".find" do
|
152
|
+
it "should find all elements matching CSS selector" do
|
153
|
+
foo = Element.find '.find-foo'
|
154
|
+
foo.should be_kind_of(Element)
|
155
|
+
foo.length.should == 2
|
156
|
+
|
157
|
+
bar = Element.find '.find-bar'
|
158
|
+
bar.should be_kind_of(Element)
|
159
|
+
bar.length.should == 1
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return an empty Element instance with length 0 when no matching" do
|
163
|
+
baz = Element.find '.find-baz'
|
164
|
+
baz.should be_kind_of(Element)
|
165
|
+
baz.length.should == 0
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe ".not" do
|
170
|
+
it "should subtract from a set of elements" do
|
171
|
+
divs = Element['#foo, .woosh']
|
172
|
+
divs.should be_kind_of(Element)
|
173
|
+
divs.size.should == 3
|
174
|
+
|
175
|
+
subtracted = divs.not('#foo')
|
176
|
+
subtracted.should be_kind_of(Element)
|
177
|
+
subtracted.length.should == 2
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '.id' do
|
182
|
+
it "should return a new instance with the element with given id" do
|
183
|
+
Element.id('foo').should be_kind_of(Element)
|
184
|
+
Element.id('foo').id.should == 'foo'
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should return nil if no element could be found" do
|
188
|
+
Element.id('bad-element-id').should be_nil
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '.parse' do
|
193
|
+
it "should return a new instance with parsed element as single element" do
|
194
|
+
foo = Element.parse '<div id="foo" class="bar"></div>'
|
195
|
+
foo.id.should == 'foo'
|
196
|
+
foo.class_name.should == 'bar'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#data" do
|
203
|
+
html <<-HTML
|
204
|
+
<div id="data-foo"></div>
|
205
|
+
<div id="data-ford" data-authur="dent" data-baz="bar"></div>
|
206
|
+
HTML
|
207
|
+
|
208
|
+
it "sets a data attribute" do
|
209
|
+
foo = Element.id('data-foo')
|
210
|
+
foo.data 'bar', 'baz'
|
211
|
+
expect(foo.data('bar')).to eq('baz')
|
212
|
+
end
|
213
|
+
|
214
|
+
it "can retrieve a data attribute" do
|
215
|
+
expect(Element.id('data-ford').data('authur')).to eq('dent')
|
216
|
+
end
|
217
|
+
|
218
|
+
it "can retrieve all data attributes" do
|
219
|
+
expect(Element.id('data-ford').data).to eq(
|
220
|
+
'authur' => 'dent', 'baz' => 'bar'
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "returns nil for an undefined data attribute" do
|
225
|
+
expect(Element.id('data-ford').data('not-here')).to be_nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "#html" do
|
230
|
+
html <<-HTML
|
231
|
+
<div id="foo">bar</div>
|
232
|
+
HTML
|
233
|
+
|
234
|
+
it "retrieves the inner html content for the element" do
|
235
|
+
expect(Element.id('foo').html).to include('bar')
|
236
|
+
end
|
237
|
+
|
238
|
+
it "can be used to set inner html of element by passing string" do
|
239
|
+
foo = Element.id 'foo'
|
240
|
+
foo.html "different content"
|
241
|
+
|
242
|
+
expect(foo.html).to_not include('bar')
|
243
|
+
expect(foo.html).to include('different content')
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '#prop' do
|
248
|
+
it 'converts nil to null' do
|
249
|
+
checkbox = Element.new(:input).attr(:type, :checkbox)
|
250
|
+
|
251
|
+
checkbox.prop(:checked, nil)
|
252
|
+
expect(checkbox.prop(:checked)).to be false
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe '#==' do
|
257
|
+
it 'uses .is()' do
|
258
|
+
expect(Element['body']).to eq(Element['body'])
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|