bri 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bri::Match::Method do
4
+ let( :fake_paragraph ) do
5
+ RDoc::Markup::Paragraph.new "This is line one", "This is line two"
6
+ end
7
+
8
+ let( :fake_description ) do
9
+ mock( RDoc::Markup::Document, :parts => [ fake_paragraph ] )
10
+ end
11
+
12
+ let( :rdoc_method ) do
13
+ mock( RDoc::AnyMethod, :full_name => "This::IS::My.full_name",
14
+ :arglists => "First\nSecond\nThird",
15
+ :comment => fake_description )
16
+ end
17
+
18
+ describe "#initialize" do
19
+ subject { Bri::Match::Method.new( rdoc_method ) }
20
+
21
+ its( :full_name ) { should == rdoc_method.full_name }
22
+ its( :call_syntaxes ) { should == " First\n Second\n Third\n" }
23
+ its( :description_paragraphs ) { should == [ " This is line one\n This is line two" ] }
24
+ end
25
+
26
+ describe "#full_name" do
27
+ subject do
28
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method" )
29
+ search_instance.search( :fully_qualified )
30
+ search_instance.matches.first
31
+ end
32
+
33
+ its( :full_name ) { should == "BriDummySpecClass#bri_dummy_spec_instance_method" }
34
+ end
35
+
36
+ describe "#call_syntaxes" do
37
+ context "for methods with no arguments" do
38
+ subject do
39
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method" )
40
+ search_instance.search( :fully_qualified )
41
+ search_instance.matches.first
42
+ end
43
+
44
+ its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method()\n" }
45
+ end
46
+
47
+ context "for methods with arguments" do
48
+ subject do
49
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_with_arguments" )
50
+ search_instance.search( :fully_qualified )
51
+ search_instance.matches.first
52
+ end
53
+
54
+ its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_with_arguments( a, b )\n" }
55
+ end
56
+
57
+ context "for methods with default arguments" do
58
+ subject do
59
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_with_default_arguments" )
60
+ search_instance.search( :fully_qualified )
61
+ search_instance.matches.first
62
+ end
63
+
64
+ its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_with_default_arguments( a, b, c = nil )\n" }
65
+ end
66
+
67
+ context "for methods that yield" do
68
+ subject do
69
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_which_yields" )
70
+ search_instance.search( :fully_qualified )
71
+ search_instance.matches.first
72
+ end
73
+
74
+ its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_which_yields() { |yield_param_one, yield_param_two| ... }\n" }
75
+ end
76
+
77
+ context "for methods with an rdoc yield override" do
78
+ subject do
79
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_with_yield_override" )
80
+ search_instance.search( :fully_qualified )
81
+ search_instance.matches.first
82
+ end
83
+
84
+ its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_with_yield_override() { |foo, bar| ... }\n" }
85
+ end
86
+ end
87
+
88
+ describe "#description_paragraphs" do
89
+ context "for an undocumented method" do
90
+ subject do
91
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method" )
92
+ search_instance.search( :fully_qualified )
93
+ search_instance.matches.first
94
+ end
95
+
96
+ its( :description_paragraphs ) { should == [] }
97
+ end
98
+
99
+ context "for a documented method" do
100
+ subject do
101
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#basic_headline_and_paragraph_rendering_test_method" )
102
+ search_instance.search( :fully_qualified )
103
+ search_instance.matches.first
104
+ end
105
+
106
+ its( :description_paragraphs ) { should_not be_empty }
107
+ it "should contain rendered paragraphs as the array elements" do
108
+ subject.description_paragraphs.first.should =~ /This is a headline/
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,338 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bri::Renderer do
4
+ def render_description_for_method( method_name )
5
+ search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass##{method_name}_rendering_test_method" )
6
+ search_instance.search( :fully_qualified )
7
+ search_instance.matches.first.to_s
8
+ end
9
+
10
+ let( :green ) { Regexp.escape( Term::ANSIColor::green ) }
11
+ let( :yellow ) { Regexp.escape( Term::ANSIColor::yellow ) }
12
+ let( :cyan ) { Regexp.escape( Term::ANSIColor::cyan ) }
13
+ let( :bold ) { Regexp.escape( Term::ANSIColor::bold ) }
14
+ let( :italic ) { Regexp.escape( Term::ANSIColor::italic ) }
15
+ let( :underline ) { Regexp.escape( Term::ANSIColor::underline ) }
16
+ let( :reset ) { Regexp.escape( Term::ANSIColor::reset ) }
17
+
18
+ describe "headers" do
19
+ context " for level one headlines" do
20
+ subject { render_description_for_method( "basic_headline_and_paragraph" ) }
21
+
22
+ it "should be marked in green" do
23
+ subject.should =~ /#{green}This is a headline#{reset}\n/
24
+ end
25
+ end
26
+
27
+ context "for level two headlines" do
28
+ subject { render_description_for_method( "level_two_headline_and_line_wrapping" ) }
29
+
30
+ it "should be marked in green" do
31
+ subject.should =~ /#{green}This is a level two headline#{reset}\n/
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "paragraphs" do
37
+ subject { render_description_for_method( "basic_headline_and_paragraph" ) }
38
+
39
+ it "should be indented by two spaces" do
40
+ subject.should =~ /^ Followed by some introduction text.\s*\n/
41
+ end
42
+
43
+ context "containing long rows" do
44
+ subject { render_description_for_method( "level_two_headline_and_line_wrapping" ) }
45
+
46
+ it "should be wrapped" do
47
+ subject.should =~ /\n This is a paragraph with a really really really really really really\s*\n really really really really long line that needs to be wrapped\.\n/
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "horizontal rules" do
53
+ subject { render_description_for_method( "horizontal_rule" ) }
54
+
55
+ it "should be rendered as an indented row of dashes" do
56
+ rule = "-" * Bri.width
57
+ subject.should =~ /\n #{rule}\n/
58
+ end
59
+ end
60
+
61
+ describe "bulleted lists with *" do
62
+ subject { render_description_for_method( "bulleted_list" ) }
63
+ it "should indent the list with one space" do
64
+ subject.should =~ /\n . First item in a bulleted list/
65
+ end
66
+
67
+ it "should prefix each list item with a '*' bullet" do
68
+ subject.should =~ /\* First item in a bulleted list/
69
+ subject.should =~ /\* Second item in a bulleted list/
70
+ subject.should =~ /\* Ending a bulleted list/
71
+ end
72
+
73
+ it "should wrap long lines" do
74
+ subject.should =~ /\n \* Ending a bulleted list with a really really really really really \n really really really long line that needs to be wrapped\n/
75
+ end
76
+
77
+ it "should start second lines of a list item with the same left alignment as the first list items content" do
78
+ subject.should =~ /\n \* First item in a bulleted list\n With a second line\n/
79
+ end
80
+
81
+ context "contained verbatim text" do
82
+ subject { render_description_for_method( "list_containing_verbatim_text" ) }
83
+
84
+ it "should correctly display verbatim text" do
85
+ subject.should =~ /\n Containing verbatim text\n/
86
+ end
87
+ end
88
+
89
+ context "a nested bulleted list" do
90
+ it "should indent the second level with five spaces" do
91
+ subject.should =~ /\n . First item of a nested bulleted list/
92
+ subject.should =~ /\n . Second item of a nested bulleted list/
93
+ end
94
+ end
95
+
96
+ context "a nested numbered list" do
97
+ subject { render_description_for_method( "mixed_list" ) }
98
+ it "should indent the second level with four spaces" do
99
+ subject.should =~ /\n \d\. And numbers in a sublist\n/
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "bulleted lists with -" do
105
+ subject { render_description_for_method "second_bulleted_list" }
106
+ it "should indent the list with one space" do
107
+ subject.should =~ /\n . A second bulleted list/
108
+ end
109
+
110
+ it "should prefix each list item with a '*' bullet" do
111
+ subject.should =~ /\* A second bulleted list/
112
+ subject.should =~ /\* Second item in second bulleted list/
113
+ subject.should =~ /\* Ending the second bulleted list/
114
+ end
115
+
116
+ it "should indent the second level with four spaces" do
117
+ subject.should =~ /\n . Nested bulleted list/
118
+ subject.should =~ /\n . Second nested bulleted list item/
119
+ end
120
+ end
121
+
122
+ describe "numbered lists" do
123
+ subject { render_description_for_method "numbered_list" }
124
+
125
+ it "should not indent the list items" do
126
+ subject.should =~ /\n\d\. First numbered list item/
127
+ end
128
+
129
+ it "should prefix each list item with a consecutive number" do
130
+ subject.should =~ /1\. First numbered list item/
131
+ subject.should =~ /2\. Second numbered list/
132
+ subject.should =~ /3\. Ending the main numbered list item/
133
+ end
134
+
135
+ context "nested numbered lists" do
136
+ it "should indent the second level with four spaces" do
137
+ subject.should =~ /\n \d\. Nested numbered list item/
138
+ subject.should =~ /\n \d\. Second nested numbered list item/
139
+ end
140
+
141
+ it "should restart the numbering for nested lists" do
142
+ subject.should =~ /1\. Nested numbered list item/
143
+ subject.should =~ /2\. Second nested numbered list item/
144
+ end
145
+ end
146
+
147
+ context "nested bulleted lists" do
148
+ subject { render_description_for_method "second_mixed_list" }
149
+ it "should indent the second level with five spaces" do
150
+ subject.should =~ /\n . Nested bulleted list/
151
+ end
152
+
153
+ it "should prefix each nested list item with a '*' bullet" do
154
+ subject.should =~ /\* Nested bulleted list/
155
+ end
156
+ end
157
+ end
158
+
159
+ describe "lettered lists" do
160
+ subject { render_description_for_method "lettered_list" }
161
+
162
+ it "should not indent the list items" do
163
+ subject.should =~ /\n.\. Some goes for lettered lists/
164
+ end
165
+
166
+ it "should prefix each list item with a consecutive letter" do
167
+ subject.should =~ /a\. Some goes for lettered lists/
168
+ subject.should =~ /b\. Second item in a lettered list/
169
+ subject.should =~ /c\. Ending the main lettered list item/
170
+ end
171
+
172
+ context "nested lettered lists" do
173
+ it "should indent the second level with four spaces" do
174
+ subject.should =~ /\n .\. And a nested lettered list item/
175
+ end
176
+
177
+ it "should restart the lettering for nested lists" do
178
+ subject.should =~ /a\. And a nested lettered list item/
179
+ subject.should =~ /b\. Second nested lettered list item/
180
+ end
181
+ end
182
+ end
183
+
184
+ describe "labeled lists" do
185
+ subject { render_description_for_method "labeled_list" }
186
+
187
+ context "with plain labels" do
188
+ it "should indent the list with two spaces" do
189
+ subject.should =~ /\n \w+: And this is the list item body/
190
+ end
191
+
192
+ it "should prefix each list item with its note" do
193
+ subject.should =~ /First: And this is the list item body/
194
+ subject.should =~ /Second: Another labled list item/
195
+ end
196
+ end
197
+
198
+ context "with aligned labels" do
199
+ subject { render_description_for_method "lined_up_labeled_list" }
200
+
201
+ it "should intent the list with two spaces" do
202
+ subject.should =~ /\n \w+:\s+With some text\./
203
+ end
204
+
205
+ it "should prefix each list item with its note" do
206
+ subject.should =~ /First:\s+With some text\./
207
+ subject.should =~ /Secondarily:\s+Lets see if this lines up\./
208
+ end
209
+
210
+ it "should have the list item bodies left aligned to the same position" do
211
+ subject.should =~ /First: With some text\./
212
+ subject.should =~ /Secondarily: Lets see if this lines up\./
213
+ end
214
+ end
215
+ end
216
+
217
+ describe "text stylings" do
218
+ context "for bold text" do
219
+ it "should mark *bold* text with an ANSI bold code" do
220
+ text = render_description_for_method( "simple_styling" )
221
+ text.should =~ /#{bold}bold#{reset},/
222
+ end
223
+
224
+ it "should mark <b>bold</b> text with an ANSI bold code" do
225
+ text = render_description_for_method( "html_styling" )
226
+ text.should =~ /#{bold}Bold#{reset},/
227
+ end
228
+
229
+ it "should not mark escaped \<b>bold\</b> text" do
230
+ text = render_description_for_method( "escaped_styling" )
231
+ text.should =~ /<b>Not bold<\/b>,/
232
+ end
233
+ end
234
+
235
+ context "for emphasized text" do
236
+ it "should mark _emphasized_ text with an ANSI yellow code" do
237
+ text = render_description_for_method( "simple_styling" )
238
+ text.should =~ /, #{yellow}emphasized#{reset} and/
239
+ end
240
+
241
+ it "should mark <em>emphasized</em> text with an ANSI yellow code" do
242
+ text = render_description_for_method( "html_styling" )
243
+ text.should =~ /, #{yellow}emphasized#{reset},/
244
+ end
245
+
246
+ it "should mark <i>emphasized</i> text with an ANSI yellow code" do
247
+ text = render_description_for_method( "html_styling" )
248
+ text.should =~ /, #{yellow}also emphasized#{reset}/
249
+ end
250
+
251
+ it "should not mark escaped \<em>emphasized\</em> text" do
252
+ text = render_description_for_method( "escaped_styling" )
253
+ text.should =~ /<em>not emphasized<\/em>/
254
+ end
255
+ end
256
+
257
+ context "for code" do
258
+ it "should mark +code+ with an ANSI cyan code" do
259
+ text = render_description_for_method( "simple_styling" )
260
+ text.should =~ /and #{cyan}monospaced#{reset}/
261
+ end
262
+
263
+ it "should mark <tt>code</tt> with an ANSI cyan code" do
264
+ text = render_description_for_method( "html_styling" )
265
+ text.should =~ /#{cyan}monospaced tt#{reset}/
266
+ end
267
+
268
+ it "should mark <code>code</code> with an ANSI cyan code" do
269
+ text = render_description_for_method( "html_styling" )
270
+ text.should =~ /#{cyan}monospaced code#{reset}/
271
+ end
272
+ end
273
+ end
274
+
275
+ describe "links" do
276
+ context "raw links" do
277
+ subject { render_description_for_method "raw_link" }
278
+
279
+ it "should underline raw http links" do
280
+ subject.should =~ /#{underline}http:\/\/www.google.com#{reset}/
281
+ end
282
+
283
+ it "should underline raw mailto links" do
284
+ subject.should =~ /#{underline}mailto:spamidyspam@spam.com#{reset}/
285
+ end
286
+
287
+ it "should underline raw ftp links" do
288
+ subject.should =~ /#{underline}ftp:\/\/warez.teuto.de#{reset}/
289
+ end
290
+
291
+ it "should underline plain www links" do
292
+ subject.should =~ /#{underline}www.test.com#{reset}/
293
+ end
294
+
295
+ it "should underline local file links" do
296
+ subject.should =~ /#{underline}\/etc\/fstab#{reset}/
297
+ end
298
+ end
299
+
300
+ context "labeled links" do
301
+ subject { render_description_for_method "labeled_link" }
302
+
303
+ context "with single word labels" do
304
+ it "should show the link underlined after the label in brackets" do
305
+ subject.should =~ /Labled links SingleWordLabel \(#{underline}http:\/\/duckduckgo.com#{reset}\)/
306
+ end
307
+ end
308
+
309
+ context "with multi word labels" do
310
+ it "should show the link underlined after the label in brackets and remove the rdoc label curly braces" do
311
+ subject.should =~ /Multi Word Labels \(#{underline}http:\/\/www.github.com#{reset}\)/
312
+ end
313
+ end
314
+ end
315
+ end
316
+
317
+ describe "conversion characters" do
318
+ subject { render_description_for_method "conversion_character" }
319
+
320
+ it "should leave -- as is" do
321
+ subject.should =~ /this: -- or/
322
+ end
323
+
324
+ it "should leave --- as is" do
325
+ subject.should =~ /or --- should/
326
+ end
327
+
328
+ it "should leave (c) as is" do
329
+ subject.should =~ /Copyright: \(c\)/
330
+ end
331
+
332
+ it "should leave (r) as is" do
333
+ subject.should =~ /registered trademark \(r\)/
334
+ end
335
+ end
336
+
337
+
338
+ end
@@ -87,4 +87,84 @@ describe Bri::Search::ClassMethod do
87
87
  end
88
88
  end
89
89
  end
90
+
91
+ context "real searches going through rdoc" do
92
+ context "a fully qualified search" do
93
+ context "with no matching methods" do
94
+ it "should have no matches" do
95
+ search_instance = Bri::Search::ClassMethod.new( "BriDummySpecClass.i_dont_exist" )
96
+ search_instance.search( :fully_qualified )
97
+ search_instance.matches.should be_empty
98
+ end
99
+ end
100
+
101
+ context "with a matching method" do
102
+ it "should have a match" do
103
+ search_instance = Bri::Search::ClassMethod.new( "BriDummySpecClass.bri_dummy_spec_singleton_method" )
104
+ search_instance.search( :fully_qualified )
105
+ search_instance.matches.should_not be_empty
106
+ search_instance.matches.first.full_name.should == "BriDummySpecClass::bri_dummy_spec_singleton_method"
107
+ end
108
+ end
109
+ end
110
+
111
+ context "a partially qualified search" do
112
+ context "with no matching methods" do
113
+ it "should have no matches" do
114
+ search_instance = Bri::Search::ClassMethod.new( ".i_dont_exist" )
115
+ search_instance.search( :partially_qualified )
116
+ search_instance.matches.should be_empty
117
+ end
118
+ end
119
+
120
+ context "with one matching method" do
121
+ it "should have one match" do
122
+ search_instance = Bri::Search::ClassMethod.new( ".bri_dummy_spec_singleton_method" )
123
+ search_instance.search( :partially_qualified )
124
+ search_instance.matches.should_not be_empty
125
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be_true
126
+ end
127
+ end
128
+
129
+ context "with multiple matching methods" do
130
+ it "should have all matches" do
131
+ search_instance = Bri::Search::ClassMethod.new( ".bri_dummy_spec_second_singleton_method" )
132
+ search_instance.search( :partially_qualified )
133
+ search_instance.matches.should_not be_empty
134
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_second_singleton_method" }.should be_true
135
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo::bri_dummy_spec_second_singleton_method" }.should be_true
136
+ end
137
+ end
138
+ end
139
+
140
+ context "an unqualified search" do
141
+ context "with no matching methods" do
142
+ it "should have no matches" do
143
+ search_instance = Bri::Search::ClassMethod.new( "i_dont_exist_go_away" )
144
+ search_instance.search( :unqualified )
145
+ search_instance.matches.should be_empty
146
+ end
147
+ end
148
+
149
+ context "with one matching method" do
150
+ it "should have one match" do
151
+ search_instance = Bri::Search::ClassMethod.new( "bri_dummy_spec_singleton_method" )
152
+ search_instance.search( :unqualified )
153
+ search_instance.matches.should_not be_empty
154
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be_true
155
+ end
156
+ end
157
+
158
+ context "with multiple matching methods" do
159
+ it "should have all matches" do
160
+ search_instance = Bri::Search::ClassMethod.new( "bri_dummy_spec" )
161
+ search_instance.search( :unqualified )
162
+ search_instance.matches.should_not be_empty
163
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be_true
164
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_second_singleton_method" }.should be_true
165
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo::bri_dummy_spec_second_singleton_method" }.should be_true
166
+ end
167
+ end
168
+ end
169
+ end
90
170
  end