Skip to content

Commit

Permalink
Merge pull request #6 from arangamani/new_line_fix
Browse files Browse the repository at this point in the history
Add an extra newline if there isn't one
  • Loading branch information
pcreux committed Nov 21, 2013
2 parents 041c425 + bf081bc commit ecc7e78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -3,5 +3,5 @@ require 'bundler/gem_tasks'
task :default => :test

task :test do
system "bundle exec rspec spec"
system "bundle exec rspec spec --color --format documentation"
end
6 changes: 5 additions & 1 deletion lib/pimpmychangelog/pimper.rb
Expand Up @@ -18,7 +18,11 @@ def initialize(user, project, changelog)
def better_changelog
parsed_changelog = Parser.new(changelog)

linkify_changelog(parsed_changelog.content) +
# If the file doesn't have an extra newline at the end the separator gets rendered
# as part of the changelog. So add an extra newline in that case.
extra_newline_if_required = parsed_changelog.content.match(/\n\n\Z/) ? "" : "\n"

linkify_changelog(parsed_changelog.content) + extra_newline_if_required +
links_definitions(parsed_changelog.issues, parsed_changelog.contributors)
end

Expand Down
12 changes: 10 additions & 2 deletions spec/pimper_spec.rb
Expand Up @@ -18,8 +18,16 @@

subject { better_changelog }

context "when the changelog does not contain any reference to issues or users" do
let(:changelog) { 'ChangeLog' }
context "when the changelog does not contain any reference to issues or users and no extra newline" do
let(:changelog) { "ChangeLog\n" }

it "should return the original changelog with an extra newline" do
better_changelog.should == changelog + "\n"
end
end

context "when the changelog already includes an extra newline" do
let(:changelog) { "ChangeLog\n\n" }

it "should return the original changelog" do
better_changelog.should == changelog
Expand Down

0 comments on commit ecc7e78

Please sign in to comment.