gradesfirst 0.2.0 → 0.2.1

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.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = "gradesfirst"
4
- s.version = "0.2.0"
4
+ s.version = "0.2.1"
5
5
  s.summary = "GradesFirst command line utility for developers."
6
6
  s.description = "This utility will help manage the various tasks developers need to do on their workstation such as database updates."
7
7
  s.license = "MIT"
@@ -27,11 +27,24 @@ module GradesFirst
27
27
  message = [
28
28
  "[\##{@story['id']}]",
29
29
  "",
30
- @story['name'],
30
+ constrain_line_length(@story['name'], 72),
31
31
  @story['url']
32
32
  ]
33
33
  message.join("\n") + "\n"
34
34
  end
35
35
  end
36
+
37
+ private
38
+
39
+ def constrain_line_length(string, length)
40
+ line_break_characters = '(?:[ .!?,\-();:\[\]]|$)'
41
+ lines = /.{,#{length.to_i}}#{line_break_characters}/
42
+
43
+ string.
44
+ scan(lines).
45
+ map { |line| line.strip }.
46
+ select { |line| line.length > 0 }.
47
+ join("\n")
48
+ end
36
49
  end
37
50
  end
@@ -22,3 +22,41 @@ describe GradesFirst::CommitMessageCommand do
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ describe 'GradesFirst::CommitMessageCommand#constrain_line_length' do
27
+ def test_string
28
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce vitae.'
29
+ end
30
+
31
+ def test_string_ending_with_a_letter
32
+ 'Lorem ipsum dolor sit amet'
33
+ end
34
+
35
+ def test_string_with_line_feeds_at_30
36
+ "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.\nFusce vitae."
37
+ end
38
+
39
+ it 'should add new lines at natural breaks when length is exceeded' do
40
+ command = GradesFirst::CommitMessageCommand.new
41
+ assert_equal(
42
+ test_string_with_line_feeds_at_30,
43
+ command.send(:constrain_line_length, test_string, 30)
44
+ )
45
+ end
46
+
47
+ it 'should do nothing when length is not exceeded' do
48
+ command = GradesFirst::CommitMessageCommand.new
49
+ assert_equal(
50
+ test_string,
51
+ command.send(:constrain_line_length, test_string, 80)
52
+ )
53
+ end
54
+
55
+ it 'should not wrap when ending with a letter' do
56
+ command = GradesFirst::CommitMessageCommand.new
57
+ assert_equal(
58
+ test_string_ending_with_a_letter,
59
+ command.send(:constrain_line_length, test_string_ending_with_a_letter, 80)
60
+ )
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gradesfirst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-16 00:00:00.000000000 Z
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor