Uncomment line does not properly uncomment lines #243

Merged
merged 1 commit into from Jan 23, 2013

Projects

None yet

2 participants

Contributor
tomasv commented Aug 5, 2012

If a blank commented line precedes a line to be uncommented,
then it does not get uncommented properly.

Given this standard excerpt from spec_helper.rb that rspec:install of rspec-rails generates:

RSpec.configure do |config|
  # ## Mock Framework
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
end

using

uncomment_lines 'spec/spec_helper.rb', 'mock_with :mocha'

gives us this:

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
end

The problem is with the regex, \s matches newlines as well as spaces, so an empty comment line causes greediness to kick in and mess things up.

Fix and an extra spec for this attached.

@tomasv tomasv Fix bug in uncomment_lines.
If a blank commented line precedes a line to be uncommented,
then it does not get uncommented properly.
445a3b7
@sferik sferik merged commit 445a3b7 into erikhuda:master Jan 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment