opal-jquery 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ describe "Element animation methods" do
11
11
  # so the values are being compared using greater than
12
12
 
13
13
  it "should animate a set of properties and values" do
14
- foo = Document.id "animate-foo"
14
+ foo = Element.find "#animate-foo"
15
15
  foo.animate :width => "200px"
16
16
 
17
17
  set_timeout 400 do
@@ -20,7 +20,7 @@ describe "Element animation methods" do
20
20
  end
21
21
 
22
22
  it "should allow you to set a speed in the params" do
23
- foo = Document.id "animate-foo"
23
+ foo = Element.find "#animate-foo"
24
24
  foo.animate :width => "200px", :speed => 100
25
25
 
26
26
  set_timeout 105 do
@@ -29,7 +29,7 @@ describe "Element animation methods" do
29
29
  end
30
30
 
31
31
  it "should accept a block as a callback" do
32
- foo = Document.id "animate-foo"
32
+ foo = Element.find "#animate-foo"
33
33
  foo.animate :width => "200px" do
34
34
  foo.add_class "finished"
35
35
  end
@@ -9,15 +9,15 @@ describe "Element#append" do
9
9
  HTML
10
10
 
11
11
  it "should insert the HTML string to the end of each element" do
12
- Document.find('.first-append').append '<p class="woosh"></p>'
12
+ Element.find('.first-append').append '<p class="woosh"></p>'
13
13
 
14
- Document.id('foo').children.class_name.should == "woosh"
15
- Document.id('bar').children.class_name.should == "woosh"
14
+ Element.find('#foo').children.class_name.should == "woosh"
15
+ Element.find('#bar').children.class_name.should == "woosh"
16
16
  end
17
17
 
18
18
  it "should insert the given DOM node at the end of the element" do
19
- baz = Document.id 'baz'
20
- buz = Document.id 'buz'
19
+ baz = Element.find('#baz')
20
+ buz = Element.find('#buz')
21
21
 
22
22
  baz.children.size.should == 0
23
23
  baz.append buz
@@ -8,12 +8,12 @@ describe "Element#append_to" do
8
8
  HTML
9
9
 
10
10
  it "should insert the receiver into the target element" do
11
- Document.id('foo').children.size.should == 0
11
+ Element.find('#foo').children.size.should == 0
12
12
 
13
- Document.parse('<ul class="kapow"></ul>').append_to Document.id('foo')
14
- Document.id('foo').children.class_name.should == "kapow"
13
+ Element.parse('<ul class="kapow"></ul>').append_to Element.find('#foo')
14
+ Element.find('#foo').children.class_name.should == "kapow"
15
15
 
16
- Document.id('bar').append_to Document.id('baz')
17
- Document.id('baz').children.id.should == "bar"
16
+ Element.find('#bar').append_to Element.find('#baz')
17
+ Element.find('#baz').children.id.should == "bar"
18
18
  end
19
19
  end
@@ -8,7 +8,7 @@ describe "Element#at" do
8
8
  HTML
9
9
 
10
10
  it "returns the element at the given index" do
11
- foos = Document.find '.foo'
11
+ foos = Element.find '.foo'
12
12
  foos.length.should == 3
13
13
 
14
14
  foos.at(0).id.should == "blah"
@@ -17,7 +17,7 @@ describe "Element#at" do
17
17
  end
18
18
 
19
19
  it "counts from the last index for negative values" do
20
- foos = Document.find '.foo'
20
+ foos = Element.find '.foo'
21
21
 
22
22
  foos.at(-1).id.should == "bluh"
23
23
  foos.at(-2).id.should == "bleh"
@@ -25,7 +25,7 @@ describe "Element#at" do
25
25
  end
26
26
 
27
27
  it "returns nil for indexes outside range" do
28
- foos = Document.find '.foo'
28
+ foos = Element.find '.foo'
29
29
 
30
30
  foos.at(-4).should == nil
31
31
  foos.at(4).should == nil
@@ -42,18 +42,18 @@ describe Element do
42
42
 
43
43
  describe '#[]' do
44
44
  it 'should retrieve the attr value from the element' do
45
- Document.id('attr-foo')[:title].should == "Hello there!"
45
+ Element.find('#attr-foo')[:title].should == "Hello there!"
46
46
  end
47
47
 
48
48
  it 'should return an empty string for an empty attribute value' do
49
- Document.id('attr-bar')[:title].should == ""
50
- Document.id('attr-baz')[:title].should == ""
49
+ Element.find('#attr-bar')[:title].should == ""
50
+ Element.find('#attr-baz')[:title].should == ""
51
51
  end
52
52
  end
53
53
 
54
54
  describe '#[]=' do
55
55
  it 'should set the attr value on the element' do
56
- woosh = Document.id 'attr-woosh'
56
+ woosh = Element.find '#attr-woosh'
57
57
  woosh[:title].should == ""
58
58
 
59
59
  woosh[:title] = "Oranges"
@@ -61,7 +61,7 @@ describe Element do
61
61
  end
62
62
 
63
63
  it 'should replace the old value for the attribute' do
64
- kapow = Document.id 'attr-kapow'
64
+ kapow = Element.find '#attr-kapow'
65
65
  kapow[:title].should == "Apples"
66
66
 
67
67
  kapow[:title] = "Pineapple"
@@ -71,21 +71,21 @@ describe Element do
71
71
 
72
72
  describe "#add_class" do
73
73
  it "should add the given class name to the element" do
74
- foo = Document.id 'foo'
74
+ foo = Element.find '#foo'
75
75
  foo.has_class?('lemons').should be_false
76
76
  foo.add_class 'lemons'
77
77
  foo.has_class?('lemons').should be_true
78
78
  end
79
79
 
80
80
  it "should not duplicate class names on an element" do
81
- bar = Document.id 'bar'
81
+ bar = Element.find '#bar'
82
82
  bar.has_class?('apples').should be_true
83
83
  bar.add_class 'apples'
84
84
  bar.class_name.should == 'apples'
85
85
  end
86
86
 
87
87
  it "should return self" do
88
- baz = Document.id 'baz'
88
+ baz = Element.find '#baz'
89
89
  baz.add_class('oranges').should equal(baz)
90
90
  baz.add_class('oranges').should equal(baz)
91
91
  end
@@ -93,48 +93,48 @@ describe Element do
93
93
 
94
94
  describe '#has_class?' do
95
95
  it "should return true if the element has the given class" do
96
- Document.id('has-foo').has_class?("apples").should be_true
97
- Document.id('has-foo').has_class?("oranges").should be_false
98
- Document.id('has-bar').has_class?("lemons").should be_true
96
+ Element.find('#has-foo').has_class?("apples").should be_true
97
+ Element.find('#has-foo').has_class?("oranges").should be_false
98
+ Element.find('#has-bar').has_class?("lemons").should be_true
99
99
  end
100
100
  end
101
101
 
102
102
  describe '#html' do
103
103
  it "should return the html content of the element" do
104
- Document.id('html-foo').html.should == "Hey there"
105
- Document.id('html-bar').html.downcase.should == "<p>erm</p>"
104
+ Element.find('#html-foo').html.should == "Hey there"
105
+ Element.find('#html-bar').html.downcase.should == "<p>erm</p>"
106
106
  end
107
107
 
108
108
  it "should only return html for first matched element" do
109
- Document.find('.html-bridge').html.should == "Hello"
109
+ Element.find('.html-bridge').html.should == "Hello"
110
110
  end
111
111
 
112
112
  it "should return empty string for empty set" do
113
- Document.find('.html-nothing-here').html.should == ""
113
+ Element.find('.html-nothing-here').html.should == ""
114
114
  end
115
115
  end
116
116
 
117
117
  describe '#remove_class' do
118
118
  it "should have no effect on elements without class" do
119
- foo = Document.id 'remove-foo'
119
+ foo = Element.find '#remove-foo'
120
120
  foo.class_name.should == ''
121
121
  foo.remove_class 'blah'
122
122
  foo.class_name.should == ''
123
123
  end
124
124
 
125
125
  it "should remove the given class from the element" do
126
- bar = Document.id 'remove-bar'
126
+ bar = Element.find '#remove-bar'
127
127
  bar.remove_class "lemons"
128
128
  bar.class_name.should == ''
129
129
 
130
- baz = Document.id 'remove-baz'
130
+ baz = Element.find '#remove-baz'
131
131
  baz.remove_class 'lemons'
132
132
  baz.class_name.should == 'apples oranges'
133
133
 
134
134
  baz.remove_class 'apples'
135
135
  baz.class_name.should == 'oranges'
136
136
 
137
- buz = Document.id 'remove-buz'
137
+ buz = Element.find '#remove-buz'
138
138
  buz.remove_class 'mangos'
139
139
  buz.class_name.should == 'pineapples'
140
140
 
@@ -143,7 +143,7 @@ describe Element do
143
143
  end
144
144
 
145
145
  it "should return self" do
146
- bleh = Document.id 'remove-bleh'
146
+ bleh = Element.find '#remove-bleh'
147
147
  bleh.remove_class('fruit').should equal(bleh)
148
148
  bleh.remove_class('hmmmm').should equal(bleh)
149
149
  end
@@ -151,14 +151,14 @@ describe Element do
151
151
 
152
152
  describe '#toggle_class' do
153
153
  it 'adds the given class name to the element if not already present' do
154
- foo = Document['#foo']
154
+ foo = Element.find('#foo')
155
155
  foo.has_class?('oranges').should be_false
156
156
  foo.toggle_class 'oranges'
157
157
  foo.has_class?('oranges').should be_true
158
158
  end
159
159
 
160
160
  it 'removes the class if the element already has it' do
161
- bar = Document['#bar']
161
+ bar = Element.find('#bar')
162
162
  bar.has_class?('apples').should be_true
163
163
  bar.toggle_class 'apples'
164
164
  bar.has_class?('apples').should be_false
@@ -167,21 +167,21 @@ describe Element do
167
167
 
168
168
  describe "#value" do
169
169
  it "should return the selected value of select elements" do
170
- Document.id('value-foo').value.should == "Hello"
170
+ Element.find('#value-foo').value.should == "Hello"
171
171
  end
172
172
 
173
173
  it "should return the value of normal input fields" do
174
- Document.id('value-bar').value.should == "Blah"
174
+ Element.find('#value-bar').value.should == "Blah"
175
175
  end
176
176
 
177
177
  it "should return an empty string for elements with no value attr" do
178
- Document.id('value-baz').value.should == ""
178
+ Element.find('#value-baz').value.should == ""
179
179
  end
180
180
  end
181
181
 
182
182
  describe "#value=" do
183
183
  it "should set the value of the element to the given value" do
184
- foo = Document.id 'value-woosh'
184
+ foo = Element.find '#value-woosh'
185
185
  foo.value.should == ""
186
186
 
187
187
  foo.value = "Hi"
@@ -9,17 +9,17 @@ describe "Element#before" do
9
9
  HTML
10
10
 
11
11
  it "should insert the given html string before each element" do
12
- el = Document['.before-spec-first']
12
+ el = Element.find('.before-spec-first')
13
13
  el.size.should == 2
14
14
 
15
15
  el.before '<p class="woosh"></p>'
16
16
 
17
- Document['#foo'].prev.class_name.should == "woosh"
18
- Document['#bar'].prev.class_name.should == "woosh"
17
+ Element.find('#foo').prev.class_name.should == "woosh"
18
+ Element.find('#bar').prev.class_name.should == "woosh"
19
19
  end
20
20
 
21
21
  it "should insert the given DOM element before this element" do
22
- Document['#baz'].before Document['#some-header']
23
- Document['#baz'].prev.id.should == "some-header"
22
+ Element.find('#baz').before Element.find('#some-header')
23
+ Element.find('#baz').prev.id.should == "some-header"
24
24
  end
25
25
  end
@@ -12,27 +12,27 @@ describe "Element#class_name" do
12
12
  HTML
13
13
 
14
14
  it "should return the elements' class name" do
15
- Document.id('foo').class_name.should == "whiskey"
16
- Document.id('bar').class_name.should == "scotch brandy"
15
+ Element.find('#foo').class_name.should == "whiskey"
16
+ Element.find('#bar').class_name.should == "scotch brandy"
17
17
  end
18
18
 
19
19
  it "should return an empty string for element with no class name" do
20
- Document.id('baz').class_name.should == ""
21
- Document.id('buz').class_name.should == ""
20
+ Element.find('#baz').class_name.should == ""
21
+ Element.find('#buz').class_name.should == ""
22
22
  end
23
23
 
24
24
  it "should return class name for first element if more than 1 in set" do
25
- Document.find('.red').class_name.should == "red dark"
25
+ Element.find('.red').class_name.should == "red dark"
26
26
  end
27
27
 
28
28
  it "should return an empty string for instances with no elements" do
29
- Document.find('.no-elements').class_name.should == ""
29
+ Element.find('.no-elements').class_name.should == ""
30
30
  end
31
31
  end
32
32
 
33
33
  describe "Element#class_name=" do
34
34
  before do
35
- @div = Document.parse <<-HTML
35
+ @div = Element.parse <<-HTML
36
36
  <div id="class-name-set-spec">
37
37
  <div id="foo" class=""></div>
38
38
  <div id="bar" class="oranges"></div>
@@ -50,12 +50,12 @@ describe "Element#class_name=" do
50
50
  end
51
51
 
52
52
  it "should set the given class name on the element" do
53
- Document.id('foo').class_name = "apples"
54
- Document.id('foo').class_name.should == "apples"
53
+ Element.find('#foo').class_name = "apples"
54
+ Element.find('#foo').class_name.should == "apples"
55
55
  end
56
56
 
57
57
  it "should replace any existing class name" do
58
- bar = Document.id('bar')
58
+ bar = Element.find('#bar')
59
59
  bar.class_name.should == "oranges"
60
60
 
61
61
  bar.class_name = "lemons"
@@ -63,12 +63,12 @@ describe "Element#class_name=" do
63
63
  end
64
64
 
65
65
  it "should set the class name on all elements in instance" do
66
- el = Document.find '.banana'
66
+ el = Element.find '.banana'
67
67
  el.length.should == 2
68
68
 
69
69
  el.class_name = "pop"
70
70
 
71
- Document.id('baz').class_name.should == "pop"
72
- Document.id('buz').class_name.should == "pop"
71
+ Element.find('#baz').class_name.should == "pop"
72
+ Element.find('#buz').class_name.should == "pop"
73
73
  end
74
74
  end
@@ -9,35 +9,35 @@ describe "Element#css" do
9
9
 
10
10
  describe "with a given name" do
11
11
  it "returns the value of the CSS property for the given name" do
12
- Document.id('foo').css('backgroundColor').should be_kind_of(String)
12
+ Element.find('#foo').css('backgroundColor').should be_kind_of(String)
13
13
  end
14
14
 
15
15
  it "should return an empty string when no style property is defined for name" do
16
- Document.id('foo').css('color').should be_kind_of(String)
16
+ Element.find('#foo').css('color').should be_kind_of(String)
17
17
  end
18
18
  end
19
19
 
20
20
  describe "with a name and value" do
21
21
  it "should set the CSS property to the given value" do
22
- Document.id('bar').css('backgroundColor', 'blue')
22
+ Element.find('#bar').css('backgroundColor', 'blue')
23
23
  end
24
24
 
25
25
  it "returns self" do
26
- bar = Document.id('bar')
26
+ bar = Element.find('#bar')
27
27
  bar.css("background", "green").should equal(bar)
28
28
  end
29
29
  end
30
30
 
31
31
  describe "with a set of names and values" do
32
32
  it "should set the properties" do
33
- hash = Document.id("hash")
33
+ hash = Element.find("#hash")
34
34
  hash.css(:width => "100px", :height => "200px")
35
35
  hash.css("width").should be_kind_of(String)
36
36
  hash.css("height").should be_kind_of(String)
37
37
  end
38
38
 
39
39
  it "should return self" do
40
- hash = Document.id("hash")
40
+ hash = Element.find("#hash")
41
41
  hash.css(:border => "1px solid #000").should equal(hash)
42
42
  end
43
43
  end
@@ -7,28 +7,28 @@ describe "Element display methods" do
7
7
  HTML
8
8
 
9
9
  it "hides an element" do
10
- element = Document.id('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
16
  it "shows an element" do
17
- element = Document.id('hidden')
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 = Document.id('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 = Document.id('shown')
31
+ element = Element.find('#shown')
32
32
  element.css('display').should == 'block'
33
33
  element.toggle
34
34
  element.css('display').should == 'none'
@@ -8,11 +8,11 @@ describe "Element#inspect" do
8
8
  HTML
9
9
 
10
10
  it "should return a string representation of the elements" do
11
- Document.id('foo').inspect.should == '[<div id="foo">]'
12
- Document.find('.bar').inspect.should == '[<div class="bar">, <p id="lol" class="bar">]'
11
+ Element.find('#foo').inspect.should == '[<div id="foo">]'
12
+ Element.find('.bar').inspect.should == '[<div class="bar">, <p id="lol" class="bar">]'
13
13
  end
14
14
 
15
15
  it "should return '[]' when called on empty element set" do
16
- Document['.inspect-spec-none'].inspect.should == '[]'
16
+ Element.find('.inspect-spec-none').inspect.should == '[]'
17
17
  end
18
18
  end
@@ -17,18 +17,17 @@ describe Element do
17
17
 
18
18
  describe '#each' do
19
19
  it "should change all td to pippa" do
20
- Document.find('table.players td').each do |el|
20
+ Element.find('table.players td').each do |el|
21
21
  el.html = "pippa"
22
22
  end
23
23
 
24
- Document.find('table.players td').first.html.should == 'pippa'
25
- #Document.find('table.players td').last.html.should == 'pippa'
24
+ Element.find('table.players td').first.html.should == 'pippa'
26
25
  end
27
26
  end
28
27
 
29
28
  describe '#map' do
30
29
  it "should change all td.surname as array of stirng" do
31
- lst=Document.find('table.players td.surname').map {|el| el.html }
30
+ lst = Element.find('table.players td.surname').map {|el| el.html }
32
31
 
33
32
  lst.should == ['rossi','bianchi']
34
33
  end
@@ -36,16 +35,16 @@ describe Element do
36
35
 
37
36
  describe "#to_a" do
38
37
  it "should return a list of class Array" do
39
- Document.find('table.players td.surname').to_a.class.should == Array
38
+ Element.find('table.players td.surname').to_a.class.should == Array
40
39
  end
41
40
 
42
41
  it "should check first and last element" do
43
- Document.find('table.players td.surname').to_a.first.html == "rossi"
44
- Document.find('table.players td.surname').to_a.last.html == "bianchi"
42
+ Element.find('table.players td.surname').to_a.first.html == "rossi"
43
+ Element.find('table.players td.surname').to_a.last.html == "bianchi"
45
44
  end
46
45
 
47
46
  it "should get only element with class surname" do
48
- Document.find('table.players td').to_a.select {|el| el.has_class?('surname') }.
47
+ Element.find('table.players td').to_a.select {|el| el.has_class?('surname') }.
49
48
  map {|el| el.class }.uniq == ['surname']
50
49
  end
51
50
  end