diff --git a/lib/differ/string.rb b/lib/differ/string.rb index f2cf075..9759cea 100644 --- a/lib/differ/string.rb +++ b/lib/differ/string.rb @@ -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 diff --git a/spec/differ/string_spec.rb b/spec/differ/string_spec.rb index ffc8675..8f61d13 100644 --- a/spec/differ/string_spec.rb +++ b/spec/differ/string_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 87ac9b4..e752878 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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