Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

always diff

  • Loading branch information...
commit 5182548b3619d41d302d045d380474cf7f3321d5 1 parent d5a369b
@dchelimsky dchelimsky authored
View
1  lib/rspec/expectations.rb
@@ -5,6 +5,7 @@
require 'rspec/expectations/handler'
require 'rspec/expectations/version'
require 'rspec/expectations/backward_compatibility'
+require 'rspec/expectations/differ'
module RSpec
View
4 lib/rspec/expectations/backward_compatibility.rb
@@ -6,6 +6,10 @@ def const_missing(name)
name == :Rspec ? RSpec : super(name)
end
end
+
+ def differ=(ignore)
+ RSpec.deprecate("RSpec::Expectations.differ=(differ)", "nothing at all (diffing is now automatic and no longer configurable)")
+ end
end
end
View
58 lib/rspec/expectations/differ.rb
@@ -0,0 +1,58 @@
+require 'diff/lcs'
+require 'diff/lcs/hunk'
+require 'pp'
+
+module RSpec
+ module Expectations
+ class Differ
+ def initialize(ignore=nil)
+ end
+
+ # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
+ def diff_as_string(data_new, data_old)
+ data_old = data_old.split(/\n/).map! { |e| e.chomp }
+ data_new = data_new.split(/\n/).map! { |e| e.chomp }
+ output = ""
+ diffs = Diff::LCS.diff(data_old, data_new)
+ return output if diffs.empty?
+ oldhunk = hunk = nil
+ file_length_difference = 0
+ diffs.each do |piece|
+ begin
+ hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
+ file_length_difference)
+ file_length_difference = hunk.file_length_difference
+ next unless oldhunk
+ # Hunks may overlap, which is why we need to be careful when our
+ # diff includes lines of context. Otherwise, we might print
+ # redundant lines.
+ if (context_lines > 0) and hunk.overlaps?(oldhunk)
+ hunk.unshift(oldhunk)
+ else
+ output << oldhunk.diff(format)
+ end
+ ensure
+ oldhunk = hunk
+ output << "\n"
+ end
+ end
+ #Handle the last remaining hunk
+ output << oldhunk.diff(format) << "\n"
+ end
+
+ def diff_as_object(target,expected)
+ diff_as_string(PP.pp(target,""), PP.pp(expected,""))
+ end
+
+ protected
+ def format
+ :unified
+ end
+
+ def context_lines
+ 3
+ end
+ end
+
+ end
+end
View
60 lib/rspec/expectations/differs/default.rb
@@ -1,60 +0,0 @@
-require 'diff/lcs'
-require 'diff/lcs/hunk'
-require 'pp'
-
-module RSpec
- module Expectations
- module Differs
- class Default
- def initialize(ignore=nil)
- end
-
- # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
- def diff_as_string(data_new, data_old)
- data_old = data_old.split(/\n/).map! { |e| e.chomp }
- data_new = data_new.split(/\n/).map! { |e| e.chomp }
- output = ""
- diffs = Diff::LCS.diff(data_old, data_new)
- return output if diffs.empty?
- oldhunk = hunk = nil
- file_length_difference = 0
- diffs.each do |piece|
- begin
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
- file_length_difference)
- file_length_difference = hunk.file_length_difference
- next unless oldhunk
- # Hunks may overlap, which is why we need to be careful when our
- # diff includes lines of context. Otherwise, we might print
- # redundant lines.
- if (context_lines > 0) and hunk.overlaps?(oldhunk)
- hunk.unshift(oldhunk)
- else
- output << oldhunk.diff(format)
- end
- ensure
- oldhunk = hunk
- output << "\n"
- end
- end
- #Handle the last remaining hunk
- output << oldhunk.diff(format) << "\n"
- end
-
- def diff_as_object(target,expected)
- diff_as_string(PP.pp(target,""), PP.pp(expected,""))
- end
-
- protected
- def format
- :unified
- end
-
- def context_lines
- 3
- end
- end
-
- end
- end
-end
View
7 lib/rspec/expectations/differs/load-diff-lcs.rb
@@ -1,7 +0,0 @@
-begin
- require 'diff/lcs'
-rescue LoadError
- raise "You must gem install diff-lcs to use diffing"
-end
-
-require 'diff/lcs/hunk'
View
2  lib/rspec/expectations/fail_with.rb
@@ -2,7 +2,7 @@ module RSpec
module Expectations
class << self
def differ
- @differ ||= Differs::Default.new
+ @differ ||= Differ.new
end
# raises a RSpec::Expectations::ExpectationNotMetError with message
View
9 rspec-expectations.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["David Chelimsky", "Chad Humphries"]
- s.date = %q{2010-05-17}
+ s.date = %q{2010-05-19}
s.description = %q{rspec expectations (should[_not] and matchers)}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.extra_rdoc_files = [
@@ -36,8 +36,7 @@ Gem::Specification.new do |s|
"features/support/env.rb",
"lib/rspec/expectations.rb",
"lib/rspec/expectations/backward_compatibility.rb",
- "lib/rspec/expectations/differs/default.rb",
- "lib/rspec/expectations/differs/load-diff-lcs.rb",
+ "lib/rspec/expectations/differ.rb",
"lib/rspec/expectations/errors.rb",
"lib/rspec/expectations/extensions.rb",
"lib/rspec/expectations/extensions/kernel.rb",
@@ -74,7 +73,7 @@ Gem::Specification.new do |s|
"lib/rspec/matchers/satisfy.rb",
"lib/rspec/matchers/throw_symbol.rb",
"rspec-expectations.gemspec",
- "spec/rspec/expectations/differs/default_spec.rb",
+ "spec/rspec/expectations/differ_spec.rb",
"spec/rspec/expectations/extensions/kernel_spec.rb",
"spec/rspec/expectations/fail_with_spec.rb",
"spec/rspec/expectations/handler_spec.rb",
@@ -124,7 +123,7 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.6}
s.summary = %q{rspec-expectations-2.0.0.beta.8}
s.test_files = [
- "spec/rspec/expectations/differs/default_spec.rb",
+ "spec/rspec/expectations/differ_spec.rb",
"spec/rspec/expectations/extensions/kernel_spec.rb",
"spec/rspec/expectations/fail_with_spec.rb",
"spec/rspec/expectations/handler_spec.rb",
View
2  spec/rspec/expectations/differs/default_spec.rb → spec/rspec/expectations/differ_spec.rb
@@ -23,7 +23,7 @@ def inspect
describe "Diff" do
before(:each) do
@options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
- @differ = RSpec::Expectations::Differs::Default.new(@options)
+ @differ = RSpec::Expectations::Differ.new(@options)
end
it "should output unified diff of two strings" do
View
1  spec/spec_helper.rb
@@ -13,7 +13,6 @@ def add_to_load_path(path, prepend=false)
require 'rspec/core'
require 'rspec/mocks'
-require 'rspec/expectations/differs/default'
Dir['./spec/support/**/*'].each do |f|
require f
Please sign in to comment.
Something went wrong with that request. Please try again.