diff --git a/README.md b/README.md
new file mode 100644
index 0000000..76c552c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,158 @@
+# Differ
+
+> As streams of text swirled before the young man's eyes, his mind swam with thoughts of many things. They would have to wait, however, as he focussed his full concentration on the shifting patterns ahead of him. A glint of light reflecting off a piece of buried code caught his eye and any hope he had was lost. For the very moment he glanced aside, the landscape became Different.
+> The young man gave a small sigh and trudged onward in solemn resignation, fated to wander the desolate codebanks in perpetuity.
+
+Differ is a flexible, pure-Ruby diff library, suitable for use in both command
+line scripts and web applications. The flexibility comes from the fact that
+diffs can be built at completely arbitrary levels of granularity (some common
+ones are built-in), and can be output in a variety of formats.
+
+## Installation
+
+Add this to your gemfile if you use bundler
+
+```ruby
+gem 'differ'
+```
+
+and bundle to install
+
+```bash
+bundle install
+```
+
+or install it manually
+
+```bash
+sudo gem install differ
+```
+
+## How do I use this thing?
+
+There are a number of ways to use Differ, depending on your situation and needs. Lets examplify:
+
+```ruby
+require 'differ'
+
+@original = "Epic lolcat fail!"
+@current = "Epic wolfman fail!"
+```
+
+There are a number of built-in diff_by_* methods to choose from for standard use:
+
+```ruby
+Differ.diff_by_line(@current, @original)
+# => {"Epic lolcat fail!" >> "Epic wolfman fail!"}
+
+Differ.diff_by_word(@current, @original)
+# => Epic {"lolcat" >> "wolfman"} fail!
+
+Differ.diff_by_char(@current, @original)
+# => Epic {+"wo"}l{-"olcat "}f{+"m"}a{+"n fa"}il!
+```
+
+### Ok, but that doesn't quite cover my case, I have to split by "whatever".
+
+No problem, you can call diff directly and supply your own boundary string:
+
+```ruby
+Differ.diff(@current, @original) # Implicitly by line by default
+# => {"Epic lolcat fail!" >> "Epic wolfman fail!"}
+
+Differ.diff(@current, @original, 'i')
+# => Epi{"c lolcat fa" >> "c wolfman fa"}il
+```
+
+### Yeah, thats nice. But a simple string might not always cut it...
+
+Well, you can supply a regex instead of your string if you have to:
+
+```ruby
+Differ.diff(@original, @current, /[a-z]i/)
+# => E{"c wolfman f" >> "c lolcat f"}l!
+```
+
+Include a capture group if you want to keep the separator:
+
+```ruby
+Differ.diff(@original, @current, /([a-z]i)/)
+# => Epi{"c wolfman f" >> "c lolcat f"}ail!
+```
+
+### Ok, ok, but I don't like having to write "Differ" everywhere.
+
+If you would like something a little more inline you can `require 'differ/string'` to get some added inline string magic:
+
+```ruby
+@current.diff(@original) # Implicitly by line by default
+# => {"Epic lolcat fail!" >> "Epic wolfman fail!"}
+```
+
+Or a lot more inline:
+
+```ruby
+@current - @original # Implicitly by line by default
+# => {"Epic lolcat fail!" >> "Epic wolfman fail!"}
+
+Differ.separator = ' ' # Custom string
+@current - @original
+# => Epic {"lolcat" >> "wolfman"} fail!
+
+Differ.separator = /[a-z]i/ # Custom regex without capture group
+@original - @current
+# => E{"c wolfman f" >> "c lolcat f"}l!
+
+Differ.separator = /([a-z]i)/ # Custom regex with capture group
+@original - @current
+# => Epi{"c wolfman f" >> "c lolcat f"}ail!
+```
+
+So we've pretty much got you covered.
+
+## What about output formatting?
+
+Need a different output format? We've got a few of those too:
+
+```ruby
+Differ.format = :ascii # Default
+Differ.format = :color
+Differ.format = :html
+
+Differ.format = MyCustomFormatModule
+```
+
+The formatter must respond to the call method that takes an instant of the Change class as an argument and returns a string.
+
+### But I don't want to change the system-wide default for only a single diff output!
+
+Yeah, we either:
+
+```ruby
+diff = @current - @original
+diff.format_as(:color)
+```
+
+Or with your own formatter:
+
+```ruby
+diff = @current - @original
+diff.format_as(->(c){c.to_s})
+```
+
+## Copyright
+
+Copyright (c) 2009 Pieter Vande Bruggen.
+
+(The GIFT License, v1)
+
+Permission is hereby granted to use this software and/or its source code for
+whatever purpose you should choose. Seriously, go nuts. Use it for your personal
+RSS feed reader, your wildly profitable social network, or your mission to Mars.
+
+I don't care, it's yours. Change the name on it if you want -- in fact, if you
+start significantly changing what it does, I'd rather you did! Make it your own
+little work of art, complete with a stylish flowing signature in the corner. All
+I really did was give you the canvas. And my blessing.
+
+> Know always right from wrong, and let others see your good works.
diff --git a/README.rdoc b/README.rdoc
deleted file mode 100644
index 02ba355..0000000
--- a/README.rdoc
+++ /dev/null
@@ -1,99 +0,0 @@
-= Differ
-
- As streams of text swirled before the young man's eyes, his mind swam with
- thoughts of many things. They would have to wait, however, as he focussed his
- full concentration on the shifting patterns ahead of him. A glint of light
- reflecting off a piece of buried code caught his eye and any hope he had was
- lost. For the very moment he glanced aside, the landscape became Different.
- The young man gave a small sigh and trudged onward in solemn resignation,
- fated to wander the desolate codebanks in perpetuity.
-
-Differ is a flexible, pure-Ruby diff library, suitable for use in both command
-line scripts and web applications. The flexibility comes from the fact that
-diffs can be built at completely arbitrary levels of granularity (some common
-ones are built-in), and can be output in a variety of formats.
-
-== Installation
-
- sudo gem install differ
-
-== Usage
-
-There are a number of ways to use Differ, depending on your situation and needs.
-
- @original = "Epic lolcat fail!"
- @current = "Epic wolfman fail!"
-
-You can call the Differ module directly.
-
- require 'differ'
-
-There are a number of built-in diff methods to choose from...
-
- @diff = Differ.diff_by_line(@current, @original)
- # => "{"Epic lolcat fail!" >> "Epic wolfman fail!"}"
-
- @diff = Differ.diff_by_word(@current, @original)
- # => "Epic {"lolcat" >> "wolfman"} fail!"
-
- @diff = Differ.diff_by_char(@current, @original)
- # => "Epic {+"wo"}l{-"olcat "}f{+"m"}a{+"n fa"}il!"
-
-... or call #diff directly and supply your own boundary string!
-
- @diff = Differ.diff(@current, @original) # implicitly by line!
- # => "{"Epic lolcat fail!" >> "Epic wolfman fail!"}"
-
- @diff = Differ.diff(@current, @original, 'i')
- # => "Epi{"c lolcat fa" >> "c wolfman fa"}il"
-
-If you would like something a little more inline...
-
- require 'differ/string'
-
- @diff = @current.diff(@original) # implicitly by line!
- # => "{"Epic lolcat fail!" >> "Epic wolfman fail!"}"
-
-... or a lot more inline...
-
- @diff = (@current - @original) # implicitly by line!
- # => "{"Epic lolcat fail!" >> "Epic wolfman fail!"}"
-
- $; = ' '
- @diff = (@current - @original)
- # => "Epic {"lolcat" >> "wolfman"} fail!"
-
-... we've pretty much got you covered.
-
-=== Output Formatting
-
-Need a different output format? We've got a few of those too.
-
- Differ.format = :ascii # <- Default
- Differ.format = :color
- Differ.format = :html
-
- Differ.format = MyCustomFormatModule
-
-Don't want to change the system-wide default for only a single diff output?
-Yeah, me either.
-
- @diff = (@current - @original)
- @diff.format_as(:color)
-
-== Copyright
-
-Copyright (c) 2009 Pieter Vande Bruggen.
-
-(The GIFT License, v1)
-
-Permission is hereby granted to use this software and/or its source code for
-whatever purpose you should choose. Seriously, go nuts. Use it for your personal
-RSS feed reader, your wildly profitable social network, or your mission to Mars.
-
-I don't care, it's yours. Change the name on it if you want -- in fact, if you
-start significantly changing what it does, I'd rather you did! Make it your own
-little work of art, complete with a stylish flowing signature in the corner. All
-I really did was give you the canvas. And my blessing.
-
- Know always right from wrong, and let others see your good works.
diff --git a/Rakefile b/Rakefile
deleted file mode 100644
index da96b5c..0000000
--- a/Rakefile
+++ /dev/null
@@ -1,38 +0,0 @@
-require 'rake'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "differ"
- gem.summary = "A simple gem for generating string diffs"
- gem.email = "pvande@gmail.com"
- gem.homepage = "http://github.com/pvande/differ"
- gem.authors = [ "Pieter van de Bruggen" ]
- end
-rescue LoadError
- puts "Jeweler not available. Install it with: gem install jeweler"
-end
-
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'differ'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
-
-require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
-end
-
-
-task :default => :spec
diff --git a/VERSION.yml b/VERSION.yml
deleted file mode 100644
index 20ba869..0000000
--- a/VERSION.yml
+++ /dev/null
@@ -1,4 +0,0 @@
----
-:patch: 2
-:major: 0
-:minor: 1
diff --git a/differ.gemspec b/differ.gemspec
index d59e0e5..fef0377 100644
--- a/differ.gemspec
+++ b/differ.gemspec
@@ -1,63 +1,21 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
-# -*- encoding: utf-8 -*-
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'differ/version'
-Gem::Specification.new do |s|
- s.name = %q{differ}
- s.version = "0.1.2"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Pieter van de Bruggen"]
- s.date = %q{2011-02-17}
- s.email = %q{pvande@gmail.com}
- s.extra_rdoc_files = [
- "README.rdoc"
- ]
- s.files = [
- "README.rdoc",
- "Rakefile",
- "VERSION.yml",
- "differ.gemspec",
- "lib/differ.rb",
- "lib/differ/change.rb",
- "lib/differ/diff.rb",
- "lib/differ/format/ascii.rb",
- "lib/differ/format/color.rb",
- "lib/differ/format/html.rb",
- "lib/differ/string.rb",
- "spec/differ/change_spec.rb",
- "spec/differ/diff_spec.rb",
- "spec/differ/format/ascii_spec.rb",
- "spec/differ/format/color_spec.rb",
- "spec/differ/format/html_spec.rb",
- "spec/differ/string_spec.rb",
- "spec/differ_spec.rb",
- "spec/spec_helper.rb"
- ]
- s.homepage = %q{http://github.com/pvande/differ}
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{A simple gem for generating string diffs}
- s.test_files = [
- "spec/differ/change_spec.rb",
- "spec/differ/diff_spec.rb",
- "spec/differ/format/ascii_spec.rb",
- "spec/differ/format/color_spec.rb",
- "spec/differ/format/html_spec.rb",
- "spec/differ/string_spec.rb",
- "spec/differ_spec.rb",
- "spec/spec_helper.rb"
- ]
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
-end
+Gem::Specification.new do |spec|
+ spec.name = "differ"
+ spec.version = Differ::VERSION
+ spec.authors = ["Pieter van de Bruggen", "Jonas Schubert Erlandsson"]
+ spec.date = %q{2011-02-17}
+ spec.email = ["pvande@gmail.com", "jonas.schubert.erlandsson@my-codeworks.com"]
+ spec.description = "A simple gem for generating string diffs"
+ spec.summary = "A simple gem for generating string diffs"
+ spec.homepage = "http://github.com/pvande/differ"
+ spec.license = "MIT"
+ spec.files = `git ls-files`.split($/)
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+ spec.require_paths = ["lib"]
+end
\ No newline at end of file
diff --git a/lib/differ.rb b/lib/differ.rb
index 63a4078..20eadb9 100644
--- a/lib/differ.rb
+++ b/lib/differ.rb
@@ -7,20 +7,29 @@
module Differ
class << self
- def diff(target, source, separator = "\n")
- old_sep, $; = $;, separator
+ def separator=(separator)
+ @@separator = separator
+ end
+
+ def separator
+ @@separator
+ end
+
+ def diff(target, source, new_sep = "\n")
+ old_sep = self.separator
+ self.separator = new_sep
- target = target.split(separator)
- source = source.split(separator)
+ target = target.split(new_sep)
+ source = source.split(new_sep)
- $; = '' if separator.is_a? Regexp
+ self.separator = '' if new_sep.is_a? Regexp
@diff = Diff.new
advance(target, source) until source.empty? || target.empty?
@diff.insert(*target) || @diff.delete(*source)
return @diff
ensure
- $; = old_sep
+ self.separator = old_sep
end
def diff_by_char(to, from)
@@ -44,13 +53,16 @@ def format
end
def format_for(f)
- case f
- when Module then f
- when :ascii then Format::Ascii
- when :color then Format::Color
- when :html then Format::HTML
- when nil then nil
- else raise "Unknown format type #{f.inspect}"
+ if f.respond_to? :call
+ f
+ else
+ case f
+ when :ascii then Format::Ascii
+ when :color then Format::Color
+ when :html then Format::HTML
+ when nil then nil
+ else raise "Unknown format type #{f.inspect}"
+ end
end
end
diff --git a/lib/differ/change.rb b/lib/differ/change.rb
index e143452..5ea251b 100644
--- a/lib/differ/change.rb
+++ b/lib/differ/change.rb
@@ -19,7 +19,7 @@ def change?
end
def to_s
- Differ.format.format(self)
+ Differ.format.call(self)
end
alias :inspect :to_s
diff --git a/lib/differ/diff.rb b/lib/differ/diff.rb
index 76d3012..1ce5b88 100644
--- a/lib/differ/diff.rb
+++ b/lib/differ/diff.rb
@@ -76,7 +76,7 @@ def format_as(f)
@raw.inject('') do |sum, part|
part = case part
when String then part
- when Change then f.format(part)
+ when Change then f.call(part)
end
sum << part
end
@@ -89,7 +89,7 @@ def raw_array
private
def sep
- "#{$;}"
+ "#{Differ.separator}"
end
end
end
diff --git a/lib/differ/format/ascii.rb b/lib/differ/format/ascii.rb
index 815af6a..6985d3d 100644
--- a/lib/differ/format/ascii.rb
+++ b/lib/differ/format/ascii.rb
@@ -2,7 +2,7 @@ module Differ
module Format
module Ascii
class << self
- def format(change)
+ def call(change)
(change.change? && as_change(change)) ||
(change.delete? && as_delete(change)) ||
(change.insert? && as_insert(change)) ||
diff --git a/lib/differ/format/color.rb b/lib/differ/format/color.rb
index 8ac399a..41bf81e 100644
--- a/lib/differ/format/color.rb
+++ b/lib/differ/format/color.rb
@@ -2,7 +2,7 @@ module Differ
module Format
module Color
class << self
- def format(change)
+ def call(change)
(change.change? && as_change(change)) ||
(change.delete? && as_delete(change)) ||
(change.insert? && as_insert(change)) ||
diff --git a/lib/differ/format/html.rb b/lib/differ/format/html.rb
index 770c4cd..8f92250 100644
--- a/lib/differ/format/html.rb
+++ b/lib/differ/format/html.rb
@@ -2,7 +2,7 @@ module Differ
module Format
module HTML
class << self
- def format(change)
+ def call(change)
(change.change? && as_change(change)) ||
(change.delete? && as_delete(change)) ||
(change.insert? && as_insert(change)) ||
diff --git a/lib/differ/string.rb b/lib/differ/string.rb
index f2cf075..1cba4f1 100644
--- a/lib/differ/string.rb
+++ b/lib/differ/string.rb
@@ -1,7 +1,7 @@
module Differ
module StringDiffer
def diff(old)
- Differ.diff(self, old, $; || "\n")
+ Differ.diff(self, old, Differ.separator || "\n")
end
alias :- :diff
end
diff --git a/lib/differ/version.rb b/lib/differ/version.rb
new file mode 100644
index 0000000..a607755
--- /dev/null
+++ b/lib/differ/version.rb
@@ -0,0 +1,3 @@
+module Differ
+ VERSION = "0.1.3"
+end
diff --git a/spec/differ/change_spec.rb b/spec/differ/change_spec.rb
index ca2f057..14b81d7 100644
--- a/spec/differ/change_spec.rb
+++ b/spec/differ/change_spec.rb
@@ -2,7 +2,7 @@
describe Differ::Change do
before(:each) do
- @format = Module.new { def self.format(c); end }
+ @format = Module.new { def self.call(c); end }
Differ.format = @format
end
@@ -20,7 +20,7 @@
end
it 'should stringify to ""' do
- @format.should_receive(:format).once.and_return('')
+ @format.should_receive(:call).once.and_return('')
@change.to_s.should == ''
end
end
@@ -76,7 +76,7 @@
end
it "should stringify via the current format's #format method" do
- @format.should_receive(:format).once
+ @format.should_receive(:call).once
Differ::Change.new.to_s
end
end
\ No newline at end of file
diff --git a/spec/differ/diff_spec.rb b/spec/differ/diff_spec.rb
index be77486..14df9ad 100644
--- a/spec/differ/diff_spec.rb
+++ b/spec/differ/diff_spec.rb
@@ -2,7 +2,7 @@
describe Differ::Diff do
before(:each) do
- $; = nil
+ Differ.separator = nil
@diff = Differ::Diff.new
end
@@ -15,14 +15,14 @@
diff('a', 'b', 'c').to_s.should == 'abc'
end
- it 'should concatenate without regard for the $;' do
- $; = '*'
+ it 'should concatenate without regard for the Differ.separator' do
+ Differ.separator = '*'
diff('a', 'b', 'c').to_s.should == 'abc'
end
it 'should delegate insertion changes to Differ#format' do
i = +'b'
- @format.should_receive(:format).once.with(i).and_return('!')
+ @format.should_receive(:call).once.with(i).and_return('!')
diff('a', i, 'c').to_s.should == 'a!c'
end
end
@@ -30,12 +30,12 @@
describe '#format_as' do
before(:each) do
@change = +'b'
- Differ.format = Module.new { def self.format(c); raise :error; end }
- @format = Module.new { def self.format(c); end }
+ Differ.format = Module.new { def self.call(c); raise :error; end }
+ @format = Module.new { def self.call(c); end }
end
it 'should delegate change formatting to the given format' do
- @format.should_receive(:format).once.with(@change).and_return('!')
+ @format.should_receive(:call).once.with(@change).and_return('!')
diff('a', @change, 'c').format_as(@format).should == 'a!c'
end
@@ -56,8 +56,8 @@
@diff.should == diff('abcd')
end
- it 'should join its arguments with $;' do
- $; = '*'
+ it 'should join its arguments with Differ.separator' do
+ Differ.separator = '*'
@diff.same(*'a*b*c*d'.split)
@diff.should == diff('a*b*c*d')
end
@@ -72,8 +72,8 @@
@diff.should == diff('ab')
end
- it 'should join to the last result with $;' do
- $; = '*'
+ it 'should join to the last result with Differ.separator' do
+ Differ.separator = '*'
@diff.same('b')
@diff.should == diff('a*b')
end
@@ -89,15 +89,15 @@
@diff.should == diff(('z' >> 'd'), 'a')
end
- it 'should prepend $; to the result' do
- $; = '*'
+ it 'should prepend Differ.separator to the result' do
+ Differ.separator = '*'
@diff.same('a')
@diff.should == diff(('z' >> 'd'), '*a')
end
- it "should do nothing to a leading $; on the insert" do
+ it "should do nothing to a leading Differ.separator on the insert" do
@diff = diff('a', ('*-' >> '*+'))
- $; = '*'
+ Differ.separator = '*'
@diff.same('c')
@diff.should == diff('a', ('*-' >> '*+'), '*c')
end
@@ -113,15 +113,15 @@
@diff.should == diff(-'z', 'a')
end
- it 'should append $; to the previous result' do
- $; = '*'
+ it 'should append Differ.separator to the previous result' do
+ Differ.separator = '*'
@diff.same('a')
@diff.should == diff(-'z*', 'a')
end
- it "should relocate a leading $; on the delete to the previous item" do
+ it "should relocate a leading Differ.separator on the delete to the previous item" do
@diff = diff('a', -'*b')
- $; = '*'
+ Differ.separator = '*'
@diff.same('c')
@diff.should == diff('a*', -'b*', 'c')
end
@@ -137,15 +137,15 @@
@diff.should == diff(+'z', 'a')
end
- it 'should append $; to the previous result' do
- $; = '*'
+ it 'should append Differ.separator to the previous result' do
+ Differ.separator = '*'
@diff.same('a')
@diff.should == diff(+'z*', 'a')
end
- it "should relocate a leading $; on the insert to the previous item" do
+ it "should relocate a leading Differ.separator on the insert to the previous item" do
@diff = diff('a', +'*b')
- $; = '*'
+ Differ.separator = '*'
@diff.same('c')
@diff.should == diff('a*', +'b*', 'c')
end
@@ -163,8 +163,8 @@
@diff.should == diff(-'abcd')
end
- it 'should join its arguments with $;' do
- $; = '*'
+ it 'should join its arguments with Differ.separator' do
+ Differ.separator = '*'
@diff.delete(*'a*b*c*d'.split)
@diff.should == diff(-'a*b*c*d')
end
@@ -180,8 +180,8 @@
@diff.should == diff(-'ab')
end
- it 'should join to the last result with $;' do
- $; = '*'
+ it 'should join to the last result with Differ.separator' do
+ Differ.separator = '*'
@diff.delete('b')
@diff.should == diff(-'a*b')
end
@@ -197,9 +197,9 @@
@diff.should == diff('b' >> 'a')
end
- it "should relocate a leading $; on the insert to the previous item" do
+ it "should relocate a leading Differ.separator on the insert to the previous item" do
@diff = diff('a', +'*b')
- $; = '*'
+ Differ.separator = '*'
@diff.delete('z')
@diff.should == diff('a*', ('z' >> 'b'))
end
@@ -216,8 +216,8 @@
@diff.should == diff('a', -'b')
end
- it 'should prepend $; to the result' do
- $; = '*'
+ it 'should prepend Differ.separator to the result' do
+ Differ.separator = '*'
@diff.delete('b')
@diff.should == diff('a', -'*b')
end
@@ -235,8 +235,8 @@
@diff.should == diff(+'abcd')
end
- it 'should join its arguments with $;' do
- $; = '*'
+ it 'should join its arguments with Differ.separator' do
+ Differ.separator = '*'
@diff.insert(*'a*b*c*d'.split)
@diff.should == diff(+'a*b*c*d')
end
@@ -252,9 +252,9 @@
@diff.should == diff('b' >> 'a')
end
- it "should relocate a leading $; on the delete to the previous item" do
+ it "should relocate a leading Differ.separator on the delete to the previous item" do
@diff = diff('a', -'*b')
- $; = '*'
+ Differ.separator = '*'
@diff.insert('z')
@diff.should == diff('a*', ('b' >> 'z'))
end
@@ -270,8 +270,8 @@
@diff.should == diff(+'ab')
end
- it 'should join to the last result with $;' do
- $; = '*'
+ it 'should join to the last result with Differ.separator' do
+ Differ.separator = '*'
@diff.insert('b')
@diff.should == diff(+'a*b')
end
@@ -288,8 +288,8 @@
@diff.should == diff('a', +'b')
end
- it 'should prepend $; to the result' do
- $; = '*'
+ it 'should prepend Differ.separator to the result' do
+ Differ.separator = '*'
@diff.insert('b')
@diff.should == diff('a', +'*b')
end
diff --git a/spec/differ/format/ascii_spec.rb b/spec/differ/format/ascii_spec.rb
index 93a9dd6..e34b2bf 100644
--- a/spec/differ/format/ascii_spec.rb
+++ b/spec/differ/format/ascii_spec.rb
@@ -3,16 +3,16 @@
describe Differ::Format::Ascii do
it 'should format inserts well' do
@expected = '{+"SAMPLE"}'
- Differ::Format::Ascii.format(+'SAMPLE').should == @expected
+ Differ::Format::Ascii.call(+'SAMPLE').should == @expected
end
it 'should format deletes well' do
@expected = '{-"SAMPLE"}'
- Differ::Format::Ascii.format(-'SAMPLE').should == @expected
+ Differ::Format::Ascii.call(-'SAMPLE').should == @expected
end
it 'should format changes well' do
@expected = '{"THEN" >> "NOW"}'
- Differ::Format::Ascii.format('THEN' >> 'NOW').should == @expected
+ Differ::Format::Ascii.call('THEN' >> 'NOW').should == @expected
end
end
\ No newline at end of file
diff --git a/spec/differ/format/color_spec.rb b/spec/differ/format/color_spec.rb
index 4cf6223..56abd0a 100644
--- a/spec/differ/format/color_spec.rb
+++ b/spec/differ/format/color_spec.rb
@@ -3,16 +3,16 @@
describe Differ::Format::Color do
it 'should format inserts well' do
@expected = "\033[32mSAMPLE\033[0m"
- Differ::Format::Color.format(+'SAMPLE').should == @expected
+ Differ::Format::Color.call(+'SAMPLE').should == @expected
end
it 'should format deletes well' do
@expected = "\033[31mSAMPLE\033[0m"
- Differ::Format::Color.format(-'SAMPLE').should == @expected
+ Differ::Format::Color.call(-'SAMPLE').should == @expected
end
it 'should format changes well' do
@expected = "\033[31mTHEN\033[0m\033[32mNOW\033[0m"
- Differ::Format::Color.format('THEN' >> 'NOW').should == @expected
+ Differ::Format::Color.call('THEN' >> 'NOW').should == @expected
end
end
\ No newline at end of file
diff --git a/spec/differ/format/html_spec.rb b/spec/differ/format/html_spec.rb
index c3da457..fe33eec 100644
--- a/spec/differ/format/html_spec.rb
+++ b/spec/differ/format/html_spec.rb
@@ -3,16 +3,16 @@
describe Differ::Format::HTML do
it 'should format inserts well' do
@expected = 'SAMPLE'
- Differ::Format::HTML.format(+'SAMPLE').should == @expected
+ Differ::Format::HTML.call(+'SAMPLE').should == @expected
end
it 'should format deletes well' do
@expected = 'SAMPLE'
- Differ::Format::HTML.format(-'SAMPLE').should == @expected
+ Differ::Format::HTML.call(-'SAMPLE').should == @expected
end
it 'should format changes well' do
@expected = 'THENNOW'
- Differ::Format::HTML.format('THEN' >> 'NOW').should == @expected
+ Differ::Format::HTML.call('THEN' >> 'NOW').should == @expected
end
end
\ No newline at end of file
diff --git a/spec/differ/string_spec.rb b/spec/differ/string_spec.rb
index ffc8675..e4aa9a1 100644
--- a/spec/differ/string_spec.rb
+++ b/spec/differ/string_spec.rb
@@ -7,7 +7,7 @@
end
before(:each) do
- $; = nil
+ Differ.separator = nil
end
describe '#diff' do
@@ -16,9 +16,9 @@
'TO'.diff('FROM')
end
- it 'should call Differ#diff with $;' do
- $; = 'x'
- Differ.should_receive(:diff).with('TO', 'FROM', $;).once
+ it 'should call Differ#diff with Differ.separator' do
+ Differ.separator = 'x'
+ Differ.should_receive(:diff).with('TO', 'FROM', Differ.separator).once
'TO'.diff('FROM')
end
end
@@ -29,9 +29,9 @@
'TO' - 'FROM'
end
- it 'should call Differ#diff with $;' do
- $; = 'x'
- Differ.should_receive(:diff).with('TO', 'FROM', $;).once
+ it 'should call Differ#diff with Differ.separator' do
+ Differ.separator = 'x'
+ Differ.should_receive(:diff).with('TO', 'FROM', Differ.separator).once
'TO' - 'FROM'
end
end
diff --git a/spec/differ_spec.rb b/spec/differ_spec.rb
index cd9087f..32a52e9 100644
--- a/spec/differ_spec.rb
+++ b/spec/differ_spec.rb
@@ -30,8 +30,8 @@
describe '#format_for' do
before(:each) { Differ.format = nil }
- it 'should store any module passed to it' do
- formatter = Module.new
+ it 'should store any callable passed to it' do
+ formatter = ->(c){ c.to_s }
Differ.format_for(formatter).should == formatter
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 87ac9b4..676ccab 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -4,10 +4,6 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'differ'
-Spec::Runner.configure do |config|
-
-end
-
def diff(*parts)
x = Differ::Diff.new
x.instance_variable_set(:@raw, parts)