From 2a2afa078a5f8f7adcabc2a9bcbef0590350ce5d Mon Sep 17 00:00:00 2001 From: eddie cianci Date: Sun, 31 Jul 2011 15:11:52 -0400 Subject: [PATCH 1/2] fixed RSpec deprecation warning "DEPRECATION WARNING: you are using deprecated behaviour that will be removed from a future version of RSpec. /Users/defeated/Desktop/differ/spec/spec_helper.rb:7:in `' * Spec::Runner.configure is deprecated. * please use RSpec.configure instead." --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 110e7059df19aec8a442311f3a54a7630e98273a Mon Sep 17 00:00:00 2001 From: eddie cianci Date: Sun, 31 Jul 2011 15:12:19 -0400 Subject: [PATCH 2/2] added diff_by_char / diff_by_word / diff_by_line to String extensions --- lib/differ/string.rb | 12 ++++++++++++ spec/differ/string_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) 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