Created
August 8, 2017 16:16
-
-
Save atheiman/1a5c08e156c099807e207f2cc093d674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this to compare config files in a way that most config parsers would (ignore whitespace that doesnt effect anything)