lovely_rufus 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -7
  3. data/.ruby-version +1 -1
  4. data/Gemfile.lock +41 -26
  5. data/README.md +2 -2
  6. data/Rakefile +5 -6
  7. data/bin/lovely-rufus +1 -1
  8. data/config/reek.yml +7 -7
  9. data/lib/lovely_rufus.rb +9 -6
  10. data/lib/lovely_rufus/cli_wrapper.rb +1 -2
  11. data/lib/lovely_rufus/layers/basic_wrapper.rb +14 -0
  12. data/lib/lovely_rufus/layers/code_comment_stripper.rb +13 -0
  13. data/lib/lovely_rufus/layers/email_quote_stripper.rb +15 -0
  14. data/lib/lovely_rufus/layers/hangout_wrapper.rb +57 -0
  15. data/lib/lovely_rufus/layers/layer.rb +15 -0
  16. data/lib/lovely_rufus/layers/one_letter_gluer.rb +14 -0
  17. data/lib/lovely_rufus/layers/quote_stripper.rb +29 -0
  18. data/lib/lovely_rufus/text_wrapper.rb +11 -7
  19. data/lovely_rufus.gemspec +6 -4
  20. data/{spec/lovely_rufus/cli_wrapper_spec.rb → test/lovely_rufus/cli_wrapper_test.rb} +5 -5
  21. data/test/lovely_rufus/layers/basic_wrapper_test.rb +55 -0
  22. data/test/lovely_rufus/layers/code_comment_stripper_test.rb +90 -0
  23. data/test/lovely_rufus/layers/email_quote_stripper_test.rb +101 -0
  24. data/test/lovely_rufus/layers/hangout_wrapper_test.rb +40 -0
  25. data/test/lovely_rufus/layers/one_letter_gluer_test.rb +33 -0
  26. data/{spec/lovely_rufus/settings_spec.rb → test/lovely_rufus/settings_test.rb} +1 -1
  27. data/{spec/lovely_rufus/text_wrapper_spec.rb → test/lovely_rufus/text_wrapper_test.rb} +2 -2
  28. data/{spec/lovely_rufus/text_wrapper_spec.yml → test/lovely_rufus/text_wrapper_test.yml} +0 -0
  29. data/{spec/lovely_rufus/wrap_spec.rb → test/lovely_rufus/wrap_test.rb} +3 -3
  30. data/{spec/lovely_rufus_spec.rb → test/lovely_rufus_test.rb} +1 -1
  31. data/test/test_helper.rb +37 -0
  32. metadata +51 -33
  33. data/lib/lovely_rufus/basic_wrapper.rb +0 -12
  34. data/lib/lovely_rufus/hangout_wrapper.rb +0 -56
  35. data/lib/lovely_rufus/layer.rb +0 -14
  36. data/lib/lovely_rufus/one_letter_gluer.rb +0 -12
  37. data/lib/lovely_rufus/quote_stripper.rb +0 -32
  38. data/spec/lovely_rufus/basic_wrapper_spec.rb +0 -53
  39. data/spec/lovely_rufus/hangout_wrapper_spec.rb +0 -38
  40. data/spec/lovely_rufus/one_letter_gluer_spec.rb +0 -31
  41. data/spec/lovely_rufus/quote_stripper_spec.rb +0 -131
  42. data/spec/spec_helper.rb +0 -14
@@ -7,17 +7,19 @@ Gem::Specification.new do |gem|
7
7
  gem.license = 'AGPL-3.0'
8
8
  gem.name = 'lovely_rufus'
9
9
  gem.summary = 'lovely_rufus: text wrapper'
10
- gem.version = '0.2.1'
10
+ gem.version = '0.3.0'
11
11
 
12
12
  gem.files = `git ls-files -z`.split("\0")
13
13
  gem.executables = gem.files.grep(/^bin\//).map { |path| File.basename(path) }
14
- gem.test_files = gem.files.grep(/^spec\/.*\.rb$/)
14
+ gem.test_files = gem.files.grep(/^test\/.*\.rb$/)
15
+
16
+ gem.add_dependency 'private_attr', '~> 1.0'
15
17
 
16
18
  gem.add_development_dependency 'bogus', '~> 0.1.4'
17
19
  gem.add_development_dependency 'minitest', '~> 5.0'
18
20
  gem.add_development_dependency 'minitest-focus', '~> 1.1'
19
21
  gem.add_development_dependency 'rake', '~> 10.1'
20
- gem.add_development_dependency 'reek', '~> 1.3'
22
+ gem.add_development_dependency 'reek', '~> 2.0'
21
23
  gem.add_development_dependency 'rerun', '~> 0.10.0'
22
- gem.add_development_dependency 'rubocop', '~> 0.27.0'
24
+ gem.add_development_dependency 'rubocop', '~> 0.29.0'
23
25
  end
@@ -1,23 +1,23 @@
1
1
  require 'stringio'
2
- require_relative '../spec_helper'
2
+ require_relative '../test_helper'
3
3
  require_relative '../../lib/lovely_rufus/cli_wrapper'
4
4
 
5
5
  module LovelyRufus
6
6
  describe CLIWrapper do
7
7
  describe '#run' do
8
- let(:text) { "all right: stop, collaborate and listen\n" }
9
- let(:text_wrapper) { fake(:text_wrapper, as: :class) }
8
+ let(:stream) { StringIO.new(text) }
9
+ let(:text) { "all right: stop, collaborate and listen\n" }
10
+ let(:text_wrapper) { fake(:text_wrapper, as: :class) }
10
11
 
11
12
  it 'reads the passed stream to TextWrapper and prints the results' do
12
13
  stub(text_wrapper).wrap(text, width: 72) { text }
13
14
  lambda do
14
- CLIWrapper.new(text_wrapper: text_wrapper).run StringIO.new(text)
15
+ CLIWrapper.new(text_wrapper: text_wrapper).run stream
15
16
  end.must_output text
16
17
  end
17
18
 
18
19
  it 'accepts the desired width and passes it to TextWrapper' do
19
20
  capture_io do
20
- stream = StringIO.new(text)
21
21
  CLIWrapper.new(%w(--width=22), text_wrapper: text_wrapper).run stream
22
22
  end
23
23
  text_wrapper.must_have_received :wrap, [text, { width: 22 }]
@@ -0,0 +1,55 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../../lib/lovely_rufus/layers/basic_wrapper'
3
+ require_relative '../../../lib/lovely_rufus/wrap'
4
+
5
+ module LovelyRufus
6
+ module Layers
7
+ describe BasicWrapper do
8
+ describe '#call' do
9
+ it 'wraps text to the given width' do
10
+ text = 'I go crazy when I hear a cymbal and a hi-hat ' \
11
+ 'with a souped-up tempo'
12
+ wrap = <<-end.dedent
13
+ I go crazy when I hear
14
+ a cymbal and a hi-hat
15
+ with a souped-up tempo
16
+ end
17
+ bw = BasicWrapper.new
18
+ bw.call(Wrap[text, width: 22]).must_equal Wrap[wrap, width: 22]
19
+ end
20
+
21
+ it 'extends past the given width when necessary' do
22
+ text = 'I’m killing your brain like a poisonous mushroom'
23
+ wrap = <<-end.dedent
24
+ I’m
25
+ killing
26
+ your
27
+ brain
28
+ like
29
+ a
30
+ poisonous
31
+ mushroom
32
+ end
33
+ bw = BasicWrapper.new
34
+ bw.call(Wrap[text, width: 5]).must_equal Wrap[wrap, width: 5]
35
+ end
36
+
37
+ it 'rewraps a String from zero' do
38
+ text = <<-end.dedent
39
+ turn off
40
+ the lights and I’ll glow
41
+ end
42
+ wrap = "turn off the lights and I’ll glow\n"
43
+ BasicWrapper.new.call(Wrap[text]).must_equal Wrap[wrap]
44
+ end
45
+
46
+ it 'passes the fixed text to the next layer and returns its outcome' do
47
+ final = fake(:wrap)
48
+ layer = fake(:layer)
49
+ mock(layer).call(Wrap["I\nO\nU\n", width: 2]) { final }
50
+ BasicWrapper.new(layer).call(Wrap['I O U', width: 2]).must_equal final
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,90 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../../lib/lovely_rufus/layers/code_comment_stripper'
3
+ require_relative '../../../lib/lovely_rufus/wrap'
4
+
5
+ module LovelyRufus
6
+ module Layers
7
+ describe CodeCommentStripper do
8
+ describe '#call' do
9
+ it 'strips comments and adjusts width before calling the next layer' do
10
+ commented = <<-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
+ uncommented = <<-end.dedent
15
+ to the extreme I rock a mic like a vandal
16
+ light up a stage and wax a chump like a candle
17
+ end
18
+ CodeCommentStripper.must_pass_to_next Wrap[commented, width: 72],
19
+ Wrap[uncommented, width: 70]
20
+ end
21
+
22
+ it 'adds comments back in (and adjusts width) before returning' do
23
+ text = <<-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
+ commented = Wrap[text, width: 72]
28
+ CodeCommentStripper.new.call(commented).must_equal commented
29
+ end
30
+
31
+ it 'does not touch non-commented texts' do
32
+ text = <<-end.dedent
33
+ my town, that created all the bass sound
34
+ enough to shake and kick holes in the ground
35
+ end
36
+ uncommented = Wrap[text, width: 72]
37
+ CodeCommentStripper.new.call(uncommented).must_equal uncommented
38
+ end
39
+
40
+ it 'does not alter text contents' do
41
+ wrap = Wrap['# Ice # Ice # Baby']
42
+ CodeCommentStripper.new.call(wrap).must_equal wrap
43
+ end
44
+
45
+ it 'strips // code comments' do
46
+ commented = <<-end.dedent
47
+ // so fast other DJs say ‘damn!’
48
+ // if my rhyme was a drug I’d sell it by the gram
49
+ end
50
+ uncommented = <<-end.dedent
51
+ so fast other DJs say ‘damn!’
52
+ if my rhyme was a drug I’d sell it by the gram
53
+ end
54
+ CodeCommentStripper.must_pass_to_next Wrap[commented, width: 72],
55
+ Wrap[uncommented, width: 69]
56
+ end
57
+
58
+ it 'only considers homogenous characters as comments' do
59
+ commented = <<-end.dedent
60
+ # /if there was a problem,
61
+ # yo – I’ll solve it!/
62
+ end
63
+ uncommented = <<-end.dedent
64
+ /if there was a problem,
65
+ yo – I’ll solve it!/
66
+ end
67
+ CodeCommentStripper.must_pass_to_next Wrap[commented, width: 72],
68
+ Wrap[uncommented, width: 70]
69
+ end
70
+
71
+ it 'strips initial space indentation' do
72
+ indented = Wrap[' // check out the hook', width: 72]
73
+ passed = Wrap['check out the hook', width: 67]
74
+ CodeCommentStripper.must_pass_to_next indented, passed
75
+ end
76
+
77
+ it 'strips initial tab indentation' do
78
+ indented = Wrap["\t# while my DJ revolves it", width: 72]
79
+ stripped = Wrap['while my DJ revolves it', width: 69]
80
+ CodeCommentStripper.must_pass_to_next indented, stripped
81
+ end
82
+
83
+ it 'pays proper homage to K&R' do
84
+ not_commented = Wrap['#define ASSERT(msg, cond) // TODO']
85
+ CodeCommentStripper.must_pass_to_next not_commented, not_commented
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,101 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../../lib/lovely_rufus/layers/email_quote_stripper'
3
+ require_relative '../../../lib/lovely_rufus/wrap'
4
+
5
+ module LovelyRufus
6
+ module Layers
7
+ describe EmailQuoteStripper do
8
+ describe '#call' do
9
+ it 'strips quotes and adjusts width before calling the next layer' do
10
+ quoted = <<-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
+ unquoted = <<-end.dedent
15
+ to the extreme I rock a mic like a vandal
16
+ light up a stage and wax a chump like a candle
17
+ end
18
+ EmailQuoteStripper.must_pass_to_next Wrap[quoted, width: 72],
19
+ Wrap[unquoted, width: 70]
20
+ end
21
+
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
+ EmailQuoteStripper.new.call(wrap).must_equal wrap
29
+ end
30
+
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
+ EmailQuoteStripper.new.call(wrap).must_equal wrap
38
+ end
39
+
40
+ it 'does not alter text contents' do
41
+ wrap = Wrap['> Ice > Ice > Baby']
42
+ EmailQuoteStripper.new.call(wrap).must_equal wrap
43
+ end
44
+
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
+ EmailQuoteStripper.must_pass_to_next Wrap[quoted, width: 72],
55
+ Wrap[unquoted, width: 69]
56
+ end
57
+
58
+ it 'strips broken quotes properly' do
59
+ quoted = <<-end.dedent
60
+ > > >conducted and formed this is a hell of a concept
61
+ > > >we make it hype and you want to step with this
62
+ end
63
+ unquoted = <<-end.dedent
64
+ conducted and formed this is a hell of a concept
65
+ we make it hype and you want to step with this
66
+ end
67
+ EmailQuoteStripper.must_pass_to_next Wrap[quoted, width: 72],
68
+ Wrap[unquoted, width: 68]
69
+ end
70
+
71
+ it 'fixes broken quotes when adding them back in' do
72
+ quoted = <<-end.dedent
73
+ > > >Shay plays on the fade,
74
+ > > >slice like a ninja
75
+ > > >cut like a razor blade
76
+ end
77
+ fixed = <<-end.dedent
78
+ >>> Shay plays on the fade,
79
+ >>> slice like a ninja
80
+ >>> cut like a razor blade
81
+ end
82
+ wrap = Wrap[quoted, width: 72]
83
+ EmailQuoteStripper.new.call(wrap).must_equal Wrap[fixed, width: 72]
84
+ end
85
+
86
+ it 'only considers homogenous characters as comments' do
87
+ quoted = <<-end.dedent
88
+ > /if there was a problem,
89
+ > yo – I’ll solve it!/
90
+ end
91
+ unquoted = <<-end.dedent
92
+ /if there was a problem,
93
+ yo – I’ll solve it!/
94
+ end
95
+ EmailQuoteStripper.must_pass_to_next Wrap[quoted, width: 72],
96
+ Wrap[unquoted, width: 70]
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../../lib/lovely_rufus/layers/hangout_wrapper'
3
+ require_relative '../../../lib/lovely_rufus/wrap'
4
+
5
+ module LovelyRufus
6
+ module Layers
7
+ describe HangoutWrapper do
8
+ describe '#call' do
9
+ it 'removes hangouts from the text' do
10
+ text = <<-end.dedent
11
+ I go crazy when I hear a cymbal and
12
+ a hi-hat with a souped-up tempo
13
+ end
14
+ wrap = <<-end.dedent
15
+ I go crazy when I hear a cymbal
16
+ and a hi-hat with a souped-up tempo
17
+ end
18
+ hw = HangoutWrapper.new
19
+ hw.call(Wrap[text, width: 35]).must_equal Wrap[wrap, width: 35]
20
+ end
21
+
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(any(Wrap)) { final }
26
+ wrapped = HangoutWrapper.new(layer).call(Wrap["I O\nU", width: 4])
27
+ wrapped.must_equal final
28
+ end
29
+
30
+ it 'doesn’t let the last line to hang out' do
31
+ text = <<-end.dedent
32
+ Just found out the Finnish term for grammar Nazi is pilkunnussija.
33
+ Direct translation: comma fucker. You’re welcome.
34
+ end
35
+ HangoutWrapper.new.call(Wrap[text, width: 76]).text.must_equal text
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../../lib/lovely_rufus/layers/one_letter_gluer'
3
+ require_relative '../../../lib/lovely_rufus/wrap'
4
+
5
+ module LovelyRufus
6
+ module Layers
7
+ describe OneLetterGluer do
8
+ describe '#call' do
9
+ it 'replaces spaces after one-letter words with non-break spaces' do
10
+ text = 'I go crazy when I hear a cymbal and a hi-hat'
11
+ glue = 'I go crazy when I hear a cymbal and a hi-hat'
12
+ olg = OneLetterGluer.new
13
+ olg.call(Wrap[text, width: 42]).must_equal Wrap[glue, width: 42]
14
+ end
15
+
16
+ it 'glues subsequent one-letter words' do
17
+ text = 'one-letter words in English: a, I & o'
18
+ glue = 'one-letter words in English: a, I & o'
19
+ olg = OneLetterGluer.new
20
+ olg.call(Wrap[text, width: 42]).must_equal Wrap[glue, width: 42]
21
+ end
22
+
23
+ it 'passes the fixed text to the next layer and returns its outcome' do
24
+ final = fake(:wrap)
25
+ layer = fake(:layer)
26
+ mock(layer).call(Wrap['I O U', width: 69]) { final }
27
+ glued = OneLetterGluer.new(layer).call(Wrap['I O U', width: 69])
28
+ glued.must_equal final
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require_relative '../test_helper'
2
2
  require_relative '../../lib/lovely_rufus/settings'
3
3
 
4
4
  module LovelyRufus
@@ -1,5 +1,5 @@
1
1
  require 'yaml'
2
- require_relative '../spec_helper'
2
+ require_relative '../test_helper'
3
3
  require_relative '../../lib/lovely_rufus/text_wrapper'
4
4
 
5
5
  module LovelyRufus
@@ -41,7 +41,7 @@ module LovelyRufus
41
41
  end
42
42
 
43
43
  it 'supports all the example use-cases' do
44
- path = File.expand_path('text_wrapper_spec.yml', __dir__)
44
+ path = File.expand_path('text_wrapper_test.yml', __dir__)
45
45
  YAML.load_file(path).each do |spec|
46
46
  width = spec.fetch('width') { 72 }
47
47
  wrap = "#{spec['output']}\n"
@@ -1,16 +1,16 @@
1
- require_relative '../spec_helper'
1
+ require_relative '../test_helper'
2
2
  require_relative '../../lib/lovely_rufus/wrap'
3
3
 
4
4
  module LovelyRufus
5
5
  describe Wrap do
6
6
  describe '.[]' do
7
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'
8
+ Wrap['Ice Ice Baby', width: 7].text.must_equal 'Ice Ice Baby'
9
9
  Wrap['Ice Ice Baby', width: 7].width.must_equal 7
10
10
  end
11
11
 
12
12
  it 'defaults to empty text and width of 72' do
13
- Wrap[].text.must_equal ''
13
+ Wrap[].text.must_equal ''
14
14
  Wrap[].width.must_equal 72
15
15
  end
16
16
  end
@@ -1,4 +1,4 @@
1
- require_relative 'spec_helper'
1
+ require_relative 'test_helper'
2
2
  require_relative '../lib/lovely_rufus'
3
3
 
4
4
  describe LovelyRufus do
@@ -0,0 +1,37 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/focus'
4
+ require 'minitest/pride'
5
+ require 'bogus/minitest/spec'
6
+ require 'lovely_rufus'
7
+ require_relative '../lib/lovely_rufus/layers/layer'
8
+ require_relative '../lib/lovely_rufus/wrap'
9
+
10
+ Bogus.configure do |config|
11
+ config.search_modules << LovelyRufus
12
+ config.search_modules << LovelyRufus::Layers
13
+ end
14
+
15
+ class String
16
+ def dedent
17
+ gsub(/^#{scan(/^ +/).min}/, '')
18
+ end
19
+ end
20
+
21
+ module CustomAssertions
22
+ def assert_passes_to_next(subject, called_with, to_be_passed)
23
+ next_layer = fake(:layer, call: LovelyRufus::Wrap.new)
24
+ subject.new(next_layer).call called_with
25
+ assert_received next_layer, :call, [to_be_passed]
26
+ end
27
+ end
28
+
29
+ Minitest::Test.include CustomAssertions
30
+
31
+ module Minitest
32
+ module Expectations
33
+ class << LovelyRufus::Layers::Layer
34
+ infect_an_assertion :assert_passes_to_next, :must_pass_to_next, true
35
+ end
36
+ end
37
+ end