File tree Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Original file line number Diff line number Diff line change @@ -1148,12 +1148,12 @@ def self.cowsay(text, width=39)
1148
1148
# text in the cowsay banner, so just do it by hand. This big mess wraps
1149
1149
# the provided text in an ASCII-cloud and then makes it look like the cloud
1150
1150
# is a thought/word coming from the ASCII-cow. Each line in the
1151
- # ASCII-cloud is no more than the specified number-characters long, and the cloud corners are
1152
- # made to look rounded
1153
- text_lines = text . scan ( Regexp . new ( ".{1,#{ width } }" ) )
1151
+ # ASCII-cloud is no more than the specified number-characters long, and the
1152
+ # cloud corners are made to look rounded
1153
+ text_lines = text . scan ( Regexp . new ( ".{1,#{ width - 4 } }" ) )
1154
1154
max_length = text_lines . map ( &:size ) . sort . last
1155
1155
cloud_parts = [ ]
1156
- cloud_parts << " #{ '_' * ( max_length + 2 ) } "
1156
+ cloud_parts << " #{ '_' * ( max_length + 2 ) } "
1157
1157
if text_lines . size == 1
1158
1158
cloud_parts << "< #{ text } >"
1159
1159
else
@@ -1165,7 +1165,7 @@ def self.cowsay(text, width=39)
1165
1165
end
1166
1166
cloud_parts << "\\ #{ text_lines . last . ljust ( max_length , ' ' ) } /"
1167
1167
end
1168
- cloud_parts << " #{ '-' * ( max_length + 2 ) } "
1168
+ cloud_parts << " #{ '-' * ( max_length + 2 ) } "
1169
1169
cloud_parts << <<EOS
1170
1170
\\ ,__,
1171
1171
\\ (oo)____
Original file line number Diff line number Diff line change 167
167
end
168
168
end
169
169
170
+ context ".cowsay" do
171
+
172
+ def moo ( num )
173
+ ( %w( moo ) * num ) . join ( ' ' )
174
+ end
175
+
176
+ it "should cowsay single lines correctly" do
177
+ cowsaid = <<EOCOW
178
+ _____________________
179
+ < moo moo moo moo moo >
180
+ ---------------------
181
+ \\ ,__,
182
+ \\ (oo)____
183
+ (__) )\\
184
+ ||--|| *
185
+ EOCOW
186
+ described_class . cowsay ( moo ( 5 ) ) . should eq ( cowsaid )
187
+ end
188
+
189
+ it "should cowsay two lines correctly" do
190
+ cowsaid = <<EOCOW
191
+ _____________________________________
192
+ / moo moo moo moo moo moo moo moo moo \\
193
+ \\ moo moo moo moo moo moo /
194
+ -------------------------------------
195
+ \\ ,__,
196
+ \\ (oo)____
197
+ (__) )\\
198
+ ||--|| *
199
+ EOCOW
200
+ described_class . cowsay ( moo ( 15 ) ) . should eq ( cowsaid )
201
+ end
202
+
203
+ it "should cowsay three+ lines correctly" do
204
+ cowsaid = <<EOCOW
205
+ _____________________________________
206
+ / moo moo moo moo moo moo moo moo moo \\
207
+ | moo moo moo moo moo moo moo moo mo |
208
+ | o moo moo moo moo moo moo moo moo m |
209
+ \\ oo moo moo moo /
210
+ -------------------------------------
211
+ \\ ,__,
212
+ \\ (oo)____
213
+ (__) )\\
214
+ ||--|| *
215
+ EOCOW
216
+ described_class . cowsay ( moo ( 30 ) ) . should eq ( cowsaid )
217
+ end
218
+
219
+ it "should respect the wrap" do
220
+ wrap = 40 + rand ( 100 )
221
+ cowsaid = described_class . cowsay ( moo ( 1000 ) , wrap )
222
+ max_len = cowsaid . split ( /\n / ) . map ( &:length ) . sort . last
223
+ max_len . should eq ( wrap )
224
+ end
225
+ end
170
226
end
171
227
end
172
-
You can’t perform that action at this time.
0 commit comments