lovely_rufus 0.1.2 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -12
- data/Gemfile.lock +30 -32
- data/Rakefile +5 -3
- data/bin/lovely-rufus +1 -0
- data/config/reek.yml +9 -12
- data/lib/lovely_rufus/basic_wrapper.rb +11 -6
- data/lib/lovely_rufus/cli_wrapper.rb +14 -24
- data/lib/lovely_rufus/hangout_wrapper.rb +30 -24
- data/lib/lovely_rufus/layer.rb +12 -10
- data/lib/lovely_rufus/one_letter_gluer.rb +11 -6
- data/lib/lovely_rufus/quote_stripper.rb +26 -21
- data/lib/lovely_rufus/settings.rb +14 -0
- data/lib/lovely_rufus/text_wrapper.rb +31 -22
- data/lib/lovely_rufus/wrap.rb +3 -6
- data/lib/lovely_rufus.rb +7 -9
- data/lovely_rufus.gemspec +8 -7
- data/spec/lovely_rufus/basic_wrapper_spec.rb +43 -39
- data/spec/lovely_rufus/cli_wrapper_spec.rb +24 -20
- data/spec/lovely_rufus/hangout_wrapper_spec.rb +24 -19
- data/spec/lovely_rufus/one_letter_gluer_spec.rb +25 -20
- data/spec/lovely_rufus/quote_stripper_spec.rb +109 -105
- data/spec/lovely_rufus/settings_spec.rb +20 -0
- data/spec/lovely_rufus/text_wrapper_spec.rb +42 -37
- data/spec/lovely_rufus/wrap_spec.rb +21 -18
- data/spec/lovely_rufus_spec.rb +51 -0
- data/spec/spec_helper.rb +0 -1
- metadata +11 -7
@@ -1,27 +1,31 @@
|
|
1
|
+
require 'stringio'
|
1
2
|
require_relative '../spec_helper'
|
3
|
+
require_relative '../../lib/lovely_rufus/cli_wrapper'
|
2
4
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
5
|
+
module LovelyRufus
|
6
|
+
describe CLIWrapper do
|
7
|
+
describe '#run' do
|
8
|
+
let(:text) { "all right: stop, collaborate and listen\n" }
|
9
|
+
let(:text_wrapper) { fake(:text_wrapper, as: :class) }
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
it 'reads the passed stream to TextWrapper and prints the results' do
|
12
|
+
stub(text_wrapper).wrap(text, width: 72) { text }
|
13
|
+
lambda do
|
14
|
+
CLIWrapper.new(text_wrapper: text_wrapper).run StringIO.new(text)
|
15
|
+
end.must_output text
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
it 'accepts the desired width and passes it to TextWrapper' do
|
19
|
+
wrap = <<-end.dedent
|
20
|
+
all right: stop,
|
21
|
+
collaborate and listen
|
22
|
+
end
|
23
|
+
stub(text_wrapper).wrap(text, width: 22) { wrap }
|
24
|
+
lambda do
|
25
|
+
stream = StringIO.new(text)
|
26
|
+
CLIWrapper.new(%w(--width=22), text_wrapper: text_wrapper).run stream
|
27
|
+
end.must_output wrap
|
19
28
|
end
|
20
|
-
stub(text_wrapper).wrap(text, width: 22) { wrap }
|
21
|
-
lambda do
|
22
|
-
stream = StringIO.new text
|
23
|
-
CLIWrapper.new(%w(--width 22), text_wrapper: text_wrapper).run stream
|
24
|
-
end.must_output wrap
|
25
29
|
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end
|
@@ -1,25 +1,30 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/lovely_rufus/hangout_wrapper'
|
3
|
+
require_relative '../../lib/lovely_rufus/wrap'
|
2
4
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
text
|
7
|
-
|
8
|
-
|
5
|
+
module LovelyRufus
|
6
|
+
describe HangoutWrapper do
|
7
|
+
describe '#call' do
|
8
|
+
it 'removes hangouts from the text' do
|
9
|
+
text = <<-end.dedent
|
10
|
+
I go crazy when I hear a cymbal and
|
11
|
+
a hi-hat with a souped-up tempo
|
12
|
+
end
|
13
|
+
wrap = <<-end.dedent
|
14
|
+
I go crazy when I hear a cymbal
|
15
|
+
and a hi-hat with a souped-up tempo
|
16
|
+
end
|
17
|
+
hw = HangoutWrapper.new
|
18
|
+
hw.call(Wrap[text, width: 35]).must_equal Wrap[wrap, width: 35]
|
9
19
|
end
|
10
|
-
wrap = <<-end.dedent
|
11
|
-
I go crazy when I hear a cymbal
|
12
|
-
and a hi-hat with a souped-up tempo
|
13
|
-
end
|
14
|
-
hw = HangoutWrapper.new
|
15
|
-
hw.call(Wrap[text, width: 35]).must_equal Wrap[wrap, width: 35]
|
16
|
-
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
it 'passes the fixed text to the next layer and returns its outcome' do
|
22
|
+
final = fake(:wrap)
|
23
|
+
layer = fake(:layer)
|
24
|
+
mock(layer).call(any(Wrap)) { final }
|
25
|
+
wrapped = HangoutWrapper.new(layer).call(Wrap["I O\nU", width: 4])
|
26
|
+
wrapped.must_equal final
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
25
|
-
end
|
30
|
+
end
|
@@ -1,26 +1,31 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/lovely_rufus/one_letter_gluer'
|
3
|
+
require_relative '../../lib/lovely_rufus/wrap'
|
2
4
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module LovelyRufus
|
6
|
+
describe OneLetterGluer do
|
7
|
+
describe '#call' do
|
8
|
+
it 'replaces spaces after one-letter words with non-break spaces' do
|
9
|
+
text = 'I go crazy when I hear a cymbal and a hi-hat'
|
10
|
+
glue = 'I go crazy when I hear a cymbal and a hi-hat'
|
11
|
+
olg = OneLetterGluer.new
|
12
|
+
olg.call(Wrap[text, width: 42]).must_equal Wrap[glue, width: 42]
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
it 'glues subsequent one-letter words' do
|
16
|
+
text = 'one-letter words in English: a, I & o'
|
17
|
+
glue = 'one-letter words in English: a, I & o'
|
18
|
+
olg = OneLetterGluer.new
|
19
|
+
olg.call(Wrap[text, width: 42]).must_equal Wrap[glue, width: 42]
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
it 'passes the fixed text to the next layer and returns its outcome' do
|
23
|
+
final = fake(:wrap)
|
24
|
+
layer = fake(:layer)
|
25
|
+
mock(layer).call(Wrap['I O U', width: 69]) { final }
|
26
|
+
glued = OneLetterGluer.new(layer).call(Wrap['I O U', width: 69])
|
27
|
+
glued.must_equal final
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
26
|
-
end
|
31
|
+
end
|
@@ -1,127 +1,131 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/lovely_rufus/quote_stripper'
|
3
|
+
require_relative '../../lib/lovely_rufus/wrap'
|
2
4
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module LovelyRufus
|
6
|
+
describe QuoteStripper do
|
7
|
+
describe '#call' do
|
8
|
+
it 'strips quotes and adjusts width before calling the next layer' do
|
9
|
+
quoted = <<-end.dedent
|
10
|
+
> to the extreme I rock a mic like a vandal
|
11
|
+
> light up a stage and wax a chump like a candle
|
12
|
+
end
|
13
|
+
unquoted = <<-end.dedent
|
14
|
+
to the extreme I rock a mic like a vandal
|
15
|
+
light up a stage and wax a chump like a candle
|
16
|
+
end
|
17
|
+
layer = fake(:layer, call: Wrap[unquoted, width: 70])
|
18
|
+
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
19
|
+
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
9
20
|
end
|
10
|
-
unquoted = <<-end.dedent
|
11
|
-
to the extreme I rock a mic like a vandal
|
12
|
-
light up a stage and wax a chump like a candle
|
13
|
-
end
|
14
|
-
layer = fake :layer, call: Wrap[unquoted, width: 70]
|
15
|
-
QuoteStripper.new(layer).call Wrap[quoted, width: 72]
|
16
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
17
|
-
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
it 'adds quotes back in (and adjusts width) before returning' do
|
23
|
+
quoted = <<-end.dedent
|
24
|
+
> take heed, ’cause I’m a lyrical poet
|
25
|
+
> Miami’s on the scene just in case you didn’t know it
|
26
|
+
end
|
27
|
+
wrap = Wrap[quoted, width: 72]
|
28
|
+
QuoteStripper.new.call(wrap).must_equal wrap
|
23
29
|
end
|
24
|
-
wrap = Wrap[quoted, width: 72]
|
25
|
-
QuoteStripper.new.call(wrap).must_equal wrap
|
26
|
-
end
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
it 'does not touch non-quoted texts' do
|
32
|
+
plain = <<-end.dedent
|
33
|
+
my town, that created all the bass sound
|
34
|
+
enough to shake and kick holes in the ground
|
35
|
+
end
|
36
|
+
wrap = Wrap[plain, width: 72]
|
37
|
+
QuoteStripper.new.call(wrap).must_equal wrap
|
32
38
|
end
|
33
|
-
wrap = Wrap[plain, width: 72]
|
34
|
-
QuoteStripper.new.call(wrap).must_equal wrap
|
35
|
-
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'strips multilevel quotes' do
|
43
|
-
quoted = <<-end.dedent
|
44
|
-
>> ’cause my style’s like a chemical spill
|
45
|
-
>> feasible rhymes that you can vision and feel
|
46
|
-
end
|
47
|
-
unquoted = <<-end.dedent
|
48
|
-
’cause my style’s like a chemical spill
|
49
|
-
feasible rhymes that you can vision and feel
|
40
|
+
it 'does not alter text contents' do
|
41
|
+
wrap = Wrap['> Ice > Ice > Baby']
|
42
|
+
QuoteStripper.new.call(wrap).must_equal wrap
|
50
43
|
end
|
51
|
-
layer = fake :layer, call: Wrap[unquoted, width: 69]
|
52
|
-
QuoteStripper.new(layer).call Wrap[quoted, width: 72]
|
53
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 69]]
|
54
|
-
end
|
55
44
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
45
|
+
it 'strips multilevel quotes' do
|
46
|
+
quoted = <<-end.dedent
|
47
|
+
>> ’cause my style’s like a chemical spill
|
48
|
+
>> feasible rhymes that you can vision and feel
|
49
|
+
end
|
50
|
+
unquoted = <<-end.dedent
|
51
|
+
’cause my style’s like a chemical spill
|
52
|
+
feasible rhymes that you can vision and feel
|
53
|
+
end
|
54
|
+
layer = fake(:layer, call: Wrap[unquoted, width: 69])
|
55
|
+
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
56
|
+
layer.must_have_received :call, [Wrap[unquoted, width: 69]]
|
64
57
|
end
|
65
|
-
layer = fake :layer, call: Wrap[unquoted, width: 68]
|
66
|
-
QuoteStripper.new(layer).call Wrap[quoted, width: 72]
|
67
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 68]]
|
68
|
-
end
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
59
|
+
it 'strips broken quotes properly' do
|
60
|
+
quoted = <<-end.dedent
|
61
|
+
> > >conducted and formed this is a hell of a concept
|
62
|
+
> > >we make it hype and you want to step with this
|
63
|
+
end
|
64
|
+
unquoted = <<-end.dedent
|
65
|
+
conducted and formed this is a hell of a concept
|
66
|
+
we make it hype and you want to step with this
|
67
|
+
end
|
68
|
+
layer = fake(:layer, call: Wrap[unquoted, width: 68])
|
69
|
+
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
70
|
+
layer.must_have_received :call, [Wrap[unquoted, width: 68]]
|
80
71
|
end
|
81
|
-
wrap = Wrap[quoted, width: 72]
|
82
|
-
QuoteStripper.new.call(wrap).must_equal Wrap[fixed, width: 72]
|
83
|
-
end
|
84
72
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
73
|
+
it 'fixes broken quotes when adding them back in' do
|
74
|
+
quoted = <<-end.dedent
|
75
|
+
> > >Shay plays on the fade,
|
76
|
+
> > >slice like a ninja
|
77
|
+
> > >cut like a razor blade
|
78
|
+
end
|
79
|
+
fixed = <<-end.dedent
|
80
|
+
>>> Shay plays on the fade,
|
81
|
+
>>> slice like a ninja
|
82
|
+
>>> cut like a razor blade
|
83
|
+
end
|
84
|
+
wrap = Wrap[quoted, width: 72]
|
85
|
+
QuoteStripper.new.call(wrap).must_equal Wrap[fixed, width: 72]
|
93
86
|
end
|
94
|
-
layer = fake :layer, call: Wrap[unquoted, width: 69]
|
95
|
-
QuoteStripper.new(layer).call Wrap[quoted, width: 72]
|
96
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 69]]
|
97
|
-
end
|
98
87
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
88
|
+
it 'strips // code comments' do
|
89
|
+
quoted = <<-end.dedent
|
90
|
+
// so fast other DJs say ‘damn!’
|
91
|
+
// if my rhyme was a drug I’d sell it by the gram
|
92
|
+
end
|
93
|
+
unquoted = <<-end.dedent
|
94
|
+
so fast other DJs say ‘damn!’
|
95
|
+
if my rhyme was a drug I’d sell it by the gram
|
96
|
+
end
|
97
|
+
layer = fake(:layer, call: Wrap[unquoted, width: 69])
|
98
|
+
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
99
|
+
layer.must_have_received :call, [Wrap[unquoted, width: 69]]
|
107
100
|
end
|
108
|
-
layer = fake :layer, call: Wrap[unquoted, width: 70]
|
109
|
-
QuoteStripper.new(layer).call Wrap[quoted, width: 72]
|
110
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
111
|
-
end
|
112
101
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
102
|
+
it 'strips # code comments' do
|
103
|
+
quoted = <<-end.dedent
|
104
|
+
# keep my composure when it’s time to get loose
|
105
|
+
# magnetized by the mic while I kick my juice
|
106
|
+
end
|
107
|
+
unquoted = <<-end.dedent
|
108
|
+
keep my composure when it’s time to get loose
|
109
|
+
magnetized by the mic while I kick my juice
|
110
|
+
end
|
111
|
+
layer = fake(:layer, call: Wrap[unquoted, width: 70])
|
112
|
+
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
113
|
+
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
117
114
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
|
116
|
+
it 'only considers homogenous characters as comments' do
|
117
|
+
quoted = <<-end.dedent
|
118
|
+
> /if there was a problem,
|
119
|
+
> yo – I’ll solve it!/
|
120
|
+
end
|
121
|
+
unquoted = <<-end.dedent
|
122
|
+
/if there was a problem,
|
123
|
+
yo – I’ll solve it!/
|
124
|
+
end
|
125
|
+
layer = fake(:layer, call: Wrap[unquoted, width: 70])
|
126
|
+
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
127
|
+
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
121
128
|
end
|
122
|
-
layer = fake :layer, call: Wrap[unquoted, width: 70]
|
123
|
-
QuoteStripper.new(layer).call Wrap[quoted, width: 72]
|
124
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
125
129
|
end
|
126
130
|
end
|
127
|
-
end
|
131
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/lovely_rufus/settings'
|
3
|
+
|
4
|
+
module LovelyRufus
|
5
|
+
describe Settings do
|
6
|
+
describe '#width' do
|
7
|
+
it 'defaults to 72' do
|
8
|
+
Settings.new([]).width.must_equal 72
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can be set via --width' do
|
12
|
+
Settings.new(%w(--width=42)).width.must_equal 42
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can be set via -w' do
|
16
|
+
Settings.new(%w(-w 42)).width.must_equal 42
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,48 +1,53 @@
|
|
1
|
+
require 'yaml'
|
1
2
|
require_relative '../spec_helper'
|
3
|
+
require_relative '../../lib/lovely_rufus/text_wrapper'
|
2
4
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module LovelyRufus
|
6
|
+
describe TextWrapper do
|
7
|
+
describe '.wrap' do
|
8
|
+
it 'wraps the passed String to 72 characters by default' do
|
9
|
+
short = 'all right: stop, collaborate and listen'
|
10
|
+
long = short + ' – Ice is back with a brand new invention'
|
11
|
+
wrap = <<-end.dedent
|
12
|
+
all right: stop, collaborate and listen
|
13
|
+
– Ice is back with a brand new invention
|
14
|
+
end
|
15
|
+
TextWrapper.wrap(short).must_equal "#{short}\n"
|
16
|
+
TextWrapper.wrap(long).must_equal wrap
|
11
17
|
end
|
12
|
-
TextWrapper.wrap(short).must_equal "#{short}\n"
|
13
|
-
TextWrapper.wrap(long).must_equal wrap
|
14
|
-
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
it 'wraps the passed String to the given number of characters' do
|
20
|
+
input = 'something grabs a hold of me tightly; ' \
|
21
|
+
'flow like a harpoon – daily and nightly'
|
22
|
+
TextWrapper.wrap(input, width: 40).must_equal <<-end.dedent
|
23
|
+
something grabs a hold of me tightly;
|
24
|
+
flow like a harpoon – daily and nightly
|
25
|
+
end
|
26
|
+
TextWrapper.wrap(input, width: 21).must_equal <<-end.dedent
|
27
|
+
something grabs
|
28
|
+
a hold of me tightly;
|
29
|
+
flow like a harpoon
|
30
|
+
– daily and nightly
|
31
|
+
end
|
28
32
|
end
|
29
|
-
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
it 'rewraps a String from zero' do
|
35
|
+
broken = <<-end.dedent
|
36
|
+
turn off
|
37
|
+
the lights and I’ll glow
|
38
|
+
end
|
39
|
+
wrapped = TextWrapper.wrap(broken)
|
40
|
+
wrapped.must_equal "turn off the lights and I’ll glow\n"
|
35
41
|
end
|
36
|
-
TextWrapper.wrap(broken).must_equal "turn off the lights and I’ll glow\n"
|
37
|
-
end
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
it 'supports all the example use-cases' do
|
44
|
+
path = File.expand_path('text_wrapper_spec.yml', __dir__)
|
45
|
+
YAML.load_file(path).each do |spec|
|
46
|
+
width = spec.fetch('width') { 72 }
|
47
|
+
wrap = "#{spec['output']}\n"
|
48
|
+
TextWrapper.wrap(spec['input'], width: width).must_equal wrap
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
48
|
-
end
|
53
|
+
end
|
@@ -1,27 +1,30 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/lovely_rufus/wrap'
|
2
3
|
|
3
|
-
module LovelyRufus
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module LovelyRufus
|
5
|
+
describe Wrap do
|
6
|
+
describe '.[]' do
|
7
|
+
it 'creates a Wrap with the given text and target width' do
|
8
|
+
Wrap['Ice Ice Baby', width: 7].text.must_equal 'Ice Ice Baby'
|
9
|
+
Wrap['Ice Ice Baby', width: 7].width.must_equal 7
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
it 'defaults to empty text and width of 72' do
|
13
|
+
Wrap[].text.must_equal ''
|
14
|
+
Wrap[].width.must_equal 72
|
15
|
+
end
|
13
16
|
end
|
14
|
-
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
describe '#text' do
|
19
|
+
it 'accesses the text of the Wrap' do
|
20
|
+
Wrap['Ice Ice Baby', width: 7].text.must_equal 'Ice Ice Baby'
|
21
|
+
end
|
19
22
|
end
|
20
|
-
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
describe '#width' do
|
25
|
+
it 'accesses the target width of the Wrap' do
|
26
|
+
Wrap['Ice Ice Baby', width: 7].width.must_equal 7
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
|
-
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require_relative '../lib/lovely_rufus'
|
4
|
+
|
5
|
+
describe LovelyRufus do
|
6
|
+
describe '.wrap' do
|
7
|
+
it 'wraps the passed String to 72 characters by default' do
|
8
|
+
short = 'all right: stop, collaborate and listen'
|
9
|
+
long = short + ' – Ice is back with a brand new invention'
|
10
|
+
wrap = <<-end.dedent
|
11
|
+
all right: stop, collaborate and listen
|
12
|
+
– Ice is back with a brand new invention
|
13
|
+
end
|
14
|
+
LovelyRufus.wrap(short).must_equal "#{short}\n"
|
15
|
+
LovelyRufus.wrap(long).must_equal wrap
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'wraps the passed String to the given number of characters' do
|
19
|
+
input = 'something grabs a hold of me tightly; ' \
|
20
|
+
'flow like a harpoon – daily and nightly'
|
21
|
+
LovelyRufus.wrap(input, width: 40).must_equal <<-end.dedent
|
22
|
+
something grabs a hold of me tightly;
|
23
|
+
flow like a harpoon – daily and nightly
|
24
|
+
end
|
25
|
+
LovelyRufus.wrap(input, width: 21).must_equal <<-end.dedent
|
26
|
+
something grabs
|
27
|
+
a hold of me tightly;
|
28
|
+
flow like a harpoon
|
29
|
+
– daily and nightly
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'rewraps a String from zero' do
|
34
|
+
broken = <<-end.dedent
|
35
|
+
turn off
|
36
|
+
the lights and I’ll glow
|
37
|
+
end
|
38
|
+
wrapped = LovelyRufus.wrap(broken)
|
39
|
+
wrapped.must_equal "turn off the lights and I’ll glow\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'supports all the example use-cases' do
|
43
|
+
path = File.expand_path('lovely_rufus/text_wrapper_spec.yml', __dir__)
|
44
|
+
YAML.load_file(path).each do |spec|
|
45
|
+
width = spec.fetch('width') { 72 }
|
46
|
+
wrap = "#{spec['output']}\n"
|
47
|
+
LovelyRufus.wrap(spec['input'], width: width).must_equal wrap
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|