Skip to content

Instantly share code, notes, and snippets.

@atheiman
Created August 8, 2017 16:16
Show Gist options
  • Save atheiman/1a5c08e156c099807e207f2cc093d674 to your computer and use it in GitHub Desktop.
Save atheiman/1a5c08e156c099807e207f2cc093d674 to your computer and use it in GitHub Desktop.
require 'rspec'
def remove_whitespace(string)
lines = string.lines
# remove leading and trailing blank lines
lines.shift while lines.first.strip.empty?
lines.pop while lines.last.strip.empty?
# remove trailing whitespace from lines
lines.map(&:rstrip).join("\n")
end
describe do
let(:str) do
'
blue
green
'
end
it do
expect(remove_whitespace(str)).to eq(' blue
green')
end
end
@atheiman
Copy link
Author

I used this to compare config files in a way that most config parsers would (ignore whitespace that doesnt effect anything)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment