arbre 1.0.0 → 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
 
@@ -164,9 +170,22 @@ describe Arbre::Element do
164
170
 
165
171
  describe "rendering to html" do
166
172
 
173
+ before { @separator = $, }
174
+ after { $, = @separator }
175
+ let(:collection){ element + "hello world" }
176
+
167
177
  it "should render the children collection" do
168
- element.children.should_receive(:to_s).and_return("content")
169
- element.to_s.should == "content"
178
+ expect(element.children).to receive(:to_s).and_return("content")
179
+ expect(element.to_s).to eq("content")
180
+ end
181
+
182
+ it "should render collection when is set the default separator" do
183
+ $, = "_"
184
+ expect(collection.to_s).to eq("hello world")
185
+ end
186
+
187
+ it "should render collection when is not set the default separator" do
188
+ expect(collection.to_s).to eq("hello world")
170
189
  end
171
190
 
172
191
  end
@@ -179,13 +198,13 @@ describe Arbre::Element do
179
198
  let(:collection){ first + second }
180
199
 
181
200
  it "should return an instance of Collection" do
182
- collection.should be_an_instance_of(Arbre::ElementCollection)
201
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
183
202
  end
184
203
 
185
204
  it "should return the elements in the collection" do
186
- collection.size.should == 2
187
- collection.first.should == first
188
- 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)
189
208
  end
190
209
  end
191
210
 
@@ -196,14 +215,14 @@ describe Arbre::Element do
196
215
  let(:collection){ Arbre::ElementCollection.new([first, second]) + third}
197
216
 
198
217
  it "should return an instance of Collection" do
199
- collection.should be_an_instance_of(Arbre::ElementCollection)
218
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
200
219
  end
201
220
 
202
221
  it "should return the elements in the collection flattened" do
203
- collection.size.should == 3
204
- collection[0].should == first
205
- collection[1].should == second
206
- 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)
207
226
  end
208
227
  end
209
228
 
@@ -214,14 +233,14 @@ describe Arbre::Element do
214
233
  let(:collection){ first + Arbre::ElementCollection.new([second,third]) }
215
234
 
216
235
  it "should return an instance of Collection" do
217
- collection.should be_an_instance_of(Arbre::ElementCollection)
236
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
218
237
  end
219
238
 
220
239
  it "should return the elements in the collection flattened" do
221
- collection.size.should == 3
222
- collection[0].should == first
223
- collection[1].should == second
224
- 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)
225
244
  end
226
245
  end
227
246
 
@@ -230,13 +249,13 @@ describe Arbre::Element do
230
249
  let(:collection){ element + "Hello World"}
231
250
 
232
251
  it "should return an instance of Collection" do
233
- collection.should be_an_instance_of(Arbre::ElementCollection)
252
+ expect(collection).to be_an_instance_of(Arbre::ElementCollection)
234
253
  end
235
254
 
236
255
  it "should return the elements in the collection" do
237
- collection.size.should == 2
238
- collection[0].should == element
239
- 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)
240
259
  end
241
260
  end
242
261
 
@@ -244,7 +263,7 @@ describe Arbre::Element do
244
263
  let(:collection){ "hello World" + Arbre::Element.new}
245
264
 
246
265
  it "should return a string" do
247
- collection.strip.chomp.should == "hello World"
266
+ expect(collection.strip.chomp).to eq("hello World")
248
267
  end
249
268
  end
250
269
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arbre::HTML::ClassList do
4
+
5
+ describe ".build_from_string" do
6
+
7
+ it "should build a new list from a string of classes" do
8
+ list = Arbre::HTML::ClassList.build_from_string("first second")
9
+ expect(list.size).to eq(2)
10
+
11
+ expect(list.to_a.sort).to eq(%w{first second})
12
+ end
13
+
14
+ end
15
+
16
+ end