arbre 1.0.1 → 1.0.2

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.
@@ -20,21 +20,21 @@ describe Arbre::Component do
20
20
  let(:component){ component_class.new }
21
21
 
22
22
  it "should be a subclass of an html div" do
23
- Arbre::Component.ancestors.should include(Arbre::HTML::Div)
23
+ expect(Arbre::Component.ancestors).to include(Arbre::HTML::Div)
24
24
  end
25
25
 
26
26
  it "should render to a div, even as a subclass" do
27
- component.tag_name.should == 'div'
27
+ expect(component.tag_name).to eq('div')
28
28
  end
29
29
 
30
30
  it "should add a class by default" do
31
- component.class_list.should include("mock_component")
31
+ expect(component.class_list).to include("mock_component")
32
32
  end
33
33
 
34
34
  it "should render the object using the builder method name" do
35
- comp = arbre {
35
+ comp = expect(arbre {
36
36
  mock_component
37
- }.to_s.should == <<-HTML
37
+ }.to_s).to eq <<-HTML
38
38
  <div class="mock_component">
39
39
  <h2>Hello World</h2>
40
40
  </div>
@@ -10,26 +10,26 @@ describe Arbre::Context do
10
10
  end
11
11
 
12
12
  it "should not increment the indent_level" do
13
- context.indent_level.should == -1
13
+ expect(context.indent_level).to eq(-1)
14
14
  end
15
15
 
16
16
  it "should return a bytesize" do
17
- context.bytesize.should == 25
17
+ expect(context.bytesize).to eq(25)
18
18
  end
19
19
 
20
20
  it "should return a length" do
21
- context.length.should == 25
21
+ expect(context.length).to eq(25)
22
22
  end
23
23
 
24
24
  it "should delegate missing methods to the html string" do
25
- context.should respond_to(:index)
26
- context.index('<').should == 0
25
+ expect(context).to respond_to(:index)
26
+ expect(context.index('<')).to eq(0)
27
27
  end
28
28
 
29
29
  it "should use a cached version of the HTML for method delegation" do
30
- context.should_receive(:to_s).once.and_return("<h1>札幌市北区</h1>")
31
- context.index('<').should == 0
32
- context.index('<').should == 0
30
+ expect(context).to receive(:to_s).once.and_return("<h1>札幌市北区</h1>")
31
+ expect(context.index('<')).to eq(0)
32
+ expect(context.index('<')).to eq(0)
33
33
  end
34
34
 
35
35
  end
@@ -7,9 +7,9 @@ describe Arbre::Element, "Finder Methods" do
7
7
  describe "finding elements by tag name" do
8
8
 
9
9
  it "should return 0 when no elements exist" do
10
- arbre {
10
+ expect(arbre {
11
11
  div
12
- }.get_elements_by_tag_name("li").size.should == 0
12
+ }.get_elements_by_tag_name("li").size).to eq(0)
13
13
  end
14
14
 
15
15
  it "should return a child element" do
@@ -19,8 +19,8 @@ describe Arbre::Element, "Finder Methods" do
19
19
  ul
20
20
  end
21
21
  elements = html.get_elements_by_tag_name("li")
22
- elements.size.should == 1
23
- elements[0].should be_instance_of(Arbre::HTML::Li)
22
+ expect(elements.size).to eq(1)
23
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
24
24
  end
25
25
 
26
26
  it "should return multple child elements" do
@@ -31,9 +31,9 @@ describe Arbre::Element, "Finder Methods" do
31
31
  li
32
32
  end
33
33
  elements = html.get_elements_by_tag_name("li")
34
- elements.size.should == 2
35
- elements[0].should be_instance_of(Arbre::HTML::Li)
36
- elements[1].should be_instance_of(Arbre::HTML::Li)
34
+ expect(elements.size).to eq(2)
35
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
36
+ expect(elements[1]).to be_instance_of(Arbre::HTML::Li)
37
37
  end
38
38
 
39
39
  it "should return children's child elements" do
@@ -44,10 +44,10 @@ describe Arbre::Element, "Finder Methods" do
44
44
  end
45
45
  end
46
46
  elements = html.get_elements_by_tag_name("li")
47
- elements.size.should == 2
48
- elements[0].should be_instance_of(Arbre::HTML::Li)
49
- elements[1].should be_instance_of(Arbre::HTML::Li)
50
- elements[1].parent.should == elements[0]
47
+ expect(elements.size).to eq(2)
48
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Li)
49
+ expect(elements[1]).to be_instance_of(Arbre::HTML::Li)
50
+ expect(elements[1].parent).to eq(elements[0])
51
51
  end
52
52
  end
53
53
 
@@ -56,9 +56,15 @@ describe Arbre::Element, "Finder Methods" do
56
56
  describe "finding an element by a class name" do
57
57
 
58
58
  it "should return 0 when no elements exist" do
59
- arbre {
59
+ expect(arbre {
60
60
  div
61
- }.get_elements_by_class_name("my_class").size.should == 0
61
+ }.get_elements_by_class_name("my_class").size).to eq(0)
62
+ end
63
+
64
+ it "should allow text nodes on tree" do
65
+ expect(arbre {
66
+ text_node "text"
67
+ }.get_elements_by_class_name("my_class").size).to eq(0)
62
68
  end
63
69
 
64
70
  it "should return a child element" do
@@ -67,8 +73,8 @@ describe Arbre::Element, "Finder Methods" do
67
73
  div :class => "my_class"
68
74
  end
69
75
  elements = html.get_elements_by_class_name("my_class")
70
- elements.size.should == 1
71
- elements[0].should be_instance_of(Arbre::HTML::Div)
76
+ expect(elements.size).to eq(1)
77
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
72
78
  end
73
79
 
74
80
  it "should return multple child elements" do
@@ -78,9 +84,9 @@ describe Arbre::Element, "Finder Methods" do
78
84
  div :class => "my_class"
79
85
  end
80
86
  elements = html.get_elements_by_class_name("my_class")
81
- elements.size.should == 2
82
- elements[0].should be_instance_of(Arbre::HTML::Div)
83
- elements[1].should be_instance_of(Arbre::HTML::Div)
87
+ expect(elements.size).to eq(2)
88
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
89
+ expect(elements[1]).to be_instance_of(Arbre::HTML::Div)
84
90
  end
85
91
 
86
92
  it "should return elements that match one of several classes" do
@@ -91,11 +97,20 @@ describe Arbre::Element, "Finder Methods" do
91
97
 
92
98
  end
93
99
  elements = html.get_elements_by_class_name("this_class")
94
- elements.size.should == 1
95
- elements[0].should be_instance_of(Arbre::HTML::Div)
100
+ expect(elements.size).to eq(1)
101
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
96
102
  end
97
103
 
98
- # TODO: find children's children by class name
104
+ it "should return a grandchild element" do
105
+ html = arbre do
106
+ div :class => "some_class" do
107
+ div :class => "my_class"
108
+ end
109
+ end
110
+ elements = html.get_elements_by_class_name("my_class")
111
+ expect(elements.size).to eq(1)
112
+ expect(elements[0]).to be_instance_of(Arbre::HTML::Div)
113
+ end
99
114
 
100
115
  end
101
116
  end
@@ -7,25 +7,25 @@ describe Arbre::Element do
7
7
  context "when initialized" do
8
8
 
9
9
  it "should have no children" do
10
- element.children.should be_empty
10
+ expect(element.children).to be_empty
11
11
  end
12
12
 
13
13
  it "should have no parent" do
14
- element.parent.should be_nil
14
+ expect(element.parent).to be_nil
15
15
  end
16
16
 
17
17
  it "should respond to the HTML builder methods" do
18
- element.should respond_to(:span)
18
+ expect(element).to respond_to(:span)
19
19
  end
20
20
 
21
21
  it "should have a set of local assigns" do
22
22
  context = Arbre::Context.new :hello => "World"
23
23
  element = Arbre::Element.new(context)
24
- element.assigns[:hello].should == "World"
24
+ expect(element.assigns[:hello]).to eq("World")
25
25
  end
26
26
 
27
27
  it "should have an empty hash with no local assigns" do
28
- element.assigns.should == {}
28
+ expect(element.assigns).to eq({})
29
29
  end
30
30
 
31
31
  end
@@ -43,28 +43,34 @@ describe Arbre::Element do
43
43
  let(:element){ Arbre::Element.new(Arbre::Context.new(nil, helper.new)) }
44
44
 
45
45
  it "should call methods on the helper object and return TextNode objects" do
46
- element.helper_method.should == "helper method"
46
+ expect(element.helper_method).to eq("helper method")
47
47
  end
48
48
 
49
49
  it "should raise a NoMethodError if not found" do
50
- lambda {
50
+ expect {
51
51
  element.a_method_that_doesnt_exist
52
- }.should raise_error(NoMethodError)
52
+ }.to raise_error(NoMethodError)
53
53
  end
54
54
 
55
55
  end
56
56
 
57
57
  describe "passing in assigns" do
58
- let(:post){ stub }
58
+ let(:post){ double }
59
59
  let(:assigns){ {:post => post} }
60
60
 
61
61
  it "should be accessible via a method call" do
62
62
  element = Arbre::Element.new(Arbre::Context.new(assigns))
63
- element.post.should == post
63
+ expect(element.post).to eq(post)
64
64
  end
65
65
 
66
66
  end
67
67
 
68
+ it "to_a.flatten should not infinitely recurse" do
69
+ Timeout.timeout(1) do
70
+ element.to_a.flatten
71
+ end
72
+ end
73
+
68
74
  describe "adding a child" do
69
75
 
70
76
  let(:child){ Arbre::Element.new }
@@ -74,11 +80,11 @@ describe Arbre::Element do
74
80
  end
75
81
 
76
82
  it "should add the child to the parent" do
77
- element.children.first.should == child
83
+ expect(element.children.first).to eq(child)
78
84
  end
79
85
 
80
86
  it "should set the parent of the child" do
81
- child.parent.should == element
87
+ expect(child.parent).to eq(element)
82
88
  end
83
89
 
84
90
  context "when the child is nil" do
@@ -86,7 +92,7 @@ describe Arbre::Element do
86
92
  let(:child){ nil }
87
93
 
88
94
  it "should not add the child" do
89
- element.children.should be_empty
95
+ expect(element.children).to be_empty
90
96
  end
91
97
 
92
98
  end
@@ -96,8 +102,8 @@ describe Arbre::Element do
96
102
  let(:child){ "Hello World" }
97
103
 
98
104
  it "should add as a TextNode" do
99
- element.children.first.should be_instance_of(Arbre::HTML::TextNode)
100
- element.children.first.to_s.should == "Hello World"
105
+ expect(element.children.first).to be_instance_of(Arbre::HTML::TextNode)
106
+ expect(element.children.first.to_s).to eq("Hello World")
101
107
  end
102
108
 
103
109
  end
@@ -113,17 +119,17 @@ describe Arbre::Element do
113
119
  end
114
120
 
115
121
  it "should clear the existing children" do
116
- element.children.size.should == 1
122
+ expect(element.children.size).to eq(1)
117
123
  end
118
124
 
119
125
  it "should add the string as a child" do
120
- element.children.first.to_s.should == "Goodbye"
126
+ expect(element.children.first.to_s).to eq("Goodbye")
121
127
  end
122
128
 
123
129
  it "should html escape the string" do
124
130
  string = "Goodbye <br />"
125
131
  element.content = string
126
- element.content.to_s.should == "Goodbye &lt;br /&gt;"
132
+ expect(element.content.to_s).to eq("Goodbye &lt;br /&gt;")
127
133
  end
128
134
  end
129
135
 
@@ -135,11 +141,11 @@ describe Arbre::Element do
135
141
  end
136
142
 
137
143
  it "should set the content tag" do
138
- element.children.first.should == content_element
144
+ expect(element.children.first).to eq(content_element)
139
145
  end
140
146
 
141
147
  it "should set the tags parent" do
142
- content_element.parent.should == element
148
+ expect(content_element.parent).to eq(element)
143
149
  end
144
150
  end
145
151
 
@@ -152,11 +158,11 @@ describe Arbre::Element do
152
158
  end
153
159
 
154
160
  it "should set the content tag" do
155
- element.children.first.should == first
161
+ expect(element.children.first).to eq(first)
156
162
  end
157
163
 
158
164
  it "should set the tags parent" do
159
- element.children.first.parent.should == element
165
+ expect(element.children.first.parent).to eq(element)
160
166
  end
161
167
  end
162
168
 
@@ -169,17 +175,17 @@ describe Arbre::Element do
169
175
  let(:collection){ element + "hello world" }
170
176
 
171
177
  it "should render the children collection" do
172
- element.children.should_receive(:to_s).and_return("content")
173
- element.to_s.should == "content"
178
+ expect(element.children).to receive(:to_s).and_return("content")
179
+ expect(element.to_s).to eq("content")
174
180
  end
175
181
 
176
182
  it "should render collection when is set the default separator" do
177
183
  $, = "_"
178
- collection.to_s.should == "hello world"
184
+ expect(collection.to_s).to eq("hello world")
179
185
  end
180
186
 
181
187
  it "should render collection when is not set the default separator" do
182
- collection.to_s.should == "hello world"
188
+ expect(collection.to_s).to eq("hello world")
183
189
  end
184
190
 
185
191
  end
@@ -192,13 +198,13 @@ describe Arbre::Element do
192
198
  let(:collection){ first + second }
193
199
 
194
200
  it "should return an instance of Collection" do
195
- collection.should be_an_instance_of(Arbre::ElementCollection)
201
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
196
202
  end
197
203
 
198
204
  it "should return the elements in the collection" do
199
- collection.size.should == 2
200
- collection.first.should == first
201
- collection[1].should == second
205
+ expect(collection.size).to eq(2)
206
+ expect(collection.first).to eq(first)
207
+ expect(collection[1]).to eq(second)
202
208
  end
203
209
  end
204
210
 
@@ -209,14 +215,14 @@ describe Arbre::Element do
209
215
  let(:collection){ Arbre::ElementCollection.new([first, second]) + third}
210
216
 
211
217
  it "should return an instance of Collection" do
212
- collection.should be_an_instance_of(Arbre::ElementCollection)
218
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
213
219
  end
214
220
 
215
221
  it "should return the elements in the collection flattened" do
216
- collection.size.should == 3
217
- collection[0].should == first
218
- collection[1].should == second
219
- collection[2].should == third
222
+ expect(collection.size).to eq(3)
223
+ expect(collection[0]).to eq(first)
224
+ expect(collection[1]).to eq(second)
225
+ expect(collection[2]).to eq(third)
220
226
  end
221
227
  end
222
228
 
@@ -227,14 +233,14 @@ describe Arbre::Element do
227
233
  let(:collection){ first + Arbre::ElementCollection.new([second,third]) }
228
234
 
229
235
  it "should return an instance of Collection" do
230
- collection.should be_an_instance_of(Arbre::ElementCollection)
236
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
231
237
  end
232
238
 
233
239
  it "should return the elements in the collection flattened" do
234
- collection.size.should == 3
235
- collection[0].should == first
236
- collection[1].should == second
237
- collection[2].should == third
240
+ expect(collection.size).to eq(3)
241
+ expect(collection[0]).to eq(first)
242
+ expect(collection[1]).to eq(second)
243
+ expect(collection[2]).to eq(third)
238
244
  end
239
245
  end
240
246
 
@@ -243,13 +249,13 @@ describe Arbre::Element do
243
249
  let(:collection){ element + "Hello World"}
244
250
 
245
251
  it "should return an instance of Collection" do
246
- collection.should be_an_instance_of(Arbre::ElementCollection)
252
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
247
253
  end
248
254
 
249
255
  it "should return the elements in the collection" do
250
- collection.size.should == 2
251
- collection[0].should == element
252
- collection[1].should be_an_instance_of(Arbre::HTML::TextNode)
256
+ expect(collection.size).to eq(2)
257
+ expect(collection[0]).to eq(element)
258
+ expect(collection[1]).to be_an_instance_of(Arbre::HTML::TextNode)
253
259
  end
254
260
  end
255
261
 
@@ -257,7 +263,7 @@ describe Arbre::Element do
257
263
  let(:collection){ "hello World" + Arbre::Element.new}
258
264
 
259
265
  it "should return a string" do
260
- collection.strip.chomp.should == "hello World"
266
+ expect(collection.strip.chomp).to eq("hello World")
261
267
  end
262
268
  end
263
269
  end
@@ -6,9 +6,9 @@ describe Arbre::HTML::ClassList do
6
6
 
7
7
  it "should build a new list from a string of classes" do
8
8
  list = Arbre::HTML::ClassList.build_from_string("first second")
9
- list.size.should == 2
9
+ expect(list.size).to eq(2)
10
10
 
11
- list.to_a.sort.should == %w{first second}
11
+ expect(list.to_a.sort).to eq(%w{first second})
12
12
  end
13
13
 
14
14
  end
@@ -9,52 +9,54 @@ describe Arbre::HTML::Tag, "Attributes" do
9
9
  before { tag.build :id => "my_id" }
10
10
 
11
11
  it "should have an attributes hash" do
12
- tag.attributes.should == {:id => "my_id"}
12
+ expect(tag.attributes).to eq({:id => "my_id"})
13
13
  end
14
14
 
15
15
  it "should render the attributes to html" do
16
- tag.to_s.should == <<-HTML
17
- <tag id="my_id"></tag>
18
- HTML
16
+ expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n"
17
+ end
18
+
19
+ it "shouldn't render attributes that are empty" do
20
+ tag.class_list # initializes an empty ClassList
21
+ tag.set_attribute :foo, ''
22
+ tag.set_attribute :bar, nil
23
+
24
+ expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n"
19
25
  end
20
26
 
21
27
  it "should get an attribute value" do
22
- tag.attr(:id).should == "my_id"
28
+ expect(tag.attr(:id)).to eq("my_id")
23
29
  end
24
30
 
25
31
  describe "#has_attribute?" do
26
32
  context "when the attribute exists" do
27
33
  it "should return true" do
28
- tag.has_attribute?(:id).should == true
34
+ expect(tag.has_attribute?(:id)).to eq(true)
29
35
  end
30
36
  end
31
37
 
32
38
  context "when the attribute does not exist" do
33
39
  it "should return false" do
34
- tag.has_attribute?(:class).should == false
40
+ expect(tag.has_attribute?(:class)).to eq(false)
35
41
  end
36
42
  end
37
43
  end
38
44
 
39
45
  it "should remove an attribute" do
40
- tag.attributes.should == {:id => "my_id"}
41
- tag.remove_attribute(:id).should == "my_id"
42
- tag.attributes.should == {}
46
+ expect(tag.attributes).to eq({:id => "my_id"})
47
+ expect(tag.remove_attribute(:id)).to eq("my_id")
48
+ expect(tag.attributes).to eq({})
43
49
  end
44
50
  end
45
51
 
46
52
  describe "rendering attributes" do
47
53
  it "should html safe the attribute values" do
48
- tag.set_attribute(:class, "\">bad things!")
49
- tag.to_s.should == <<-HTML
50
- <tag class="&quot;&gt;bad things!"></tag>
51
- HTML
54
+ tag.set_attribute(:class, '">bad things!')
55
+ expect(tag.to_s).to eq "<tag class=\"&quot;&gt;bad things!\"></tag>\n"
52
56
  end
53
57
  it "should should escape the attribute names" do
54
58
  tag.set_attribute(">bad", "things")
55
- tag.to_s.should == <<-HTML
56
- <tag &gt;bad="things"></tag>
57
- HTML
59
+ expect(tag.to_s).to eq "<tag &gt;bad=\"things\"></tag>\n"
58
60
  end
59
61
  end
60
62
  end