Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/differ/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ def diff(old)
Differ.diff(self, old, $; || "\n")
end
alias :- :diff

def diff_by_char(old)
Differ.diff(self, old, '')
end

def diff_by_word(old)
Differ.diff(self, old, /\b/)
end

def diff_by_line(old)
Differ.diff(self, old, "\n")
end
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/differ/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,25 @@
'TO' - 'FROM'
end
end

describe '#diff_by_char' do
it 'should call Differ#diff' do
Differ.should_receive(:diff).with('Othellos', 'hello', '').once
'Othellos'.diff_by_char('hello')
end
end

describe '#diff_by_word' do
it 'should call Differ#diff' do
Differ.should_receive(:diff).with('Othellos', 'hello', /\b/).once
'Othellos'.diff_by_word('hello')
end
end

describe '#diff_by_line' do
it 'should call Differ#diff' do
Differ.should_receive(:diff).with('Othellos', 'hello', "\n").once
'Othellos'.diff_by_line('hello')
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'differ'

Spec::Runner.configure do |config|
RSpec.configure do |config|

end

Expand Down