Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-expectations
...
head fork: rspec/rspec-expectations
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 17, 2010
@dchelimsky dchelimsky just diff d5a369b
Commits on May 19, 2010
@dchelimsky dchelimsky always diff 5182548
View
1  Rakefile
@@ -13,6 +13,7 @@ begin
gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
gem.homepage = "http://github.com/rspec/expectations"
gem.authors = ["David Chelimsky", "Chad Humphries"]
+ gem.add_dependency('diff-lcs', ">= 1.1.2")
gem.add_development_dependency('cucumber', ">= 0.6.2")
gem.add_development_dependency('aruba', ">= 0.1.1")
gem.add_development_dependency('rspec-core', ">= #{RSpec::Expectations::Version::STRING}")
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
62 lib/rspec/expectations/differs/default.rb
@@ -1,62 +0,0 @@
-require File.join(File.dirname(__FILE__), "/load-diff-lcs")
-require 'pp'
-
-module RSpec
- module Expectations
- module Differs
- unless defined?(Default)
- class Default
- def initialize(options)
- @options = options
- 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
- @options.diff_format
- end
-
- def context_lines
- @options.context_lines
- end
- 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
4 lib/rspec/expectations/fail_with.rb
@@ -1,7 +1,9 @@
module RSpec
module Expectations
class << self
- attr_accessor :differ
+ def differ
+ @differ ||= Differ.new
+ end
# raises a RSpec::Expectations::ExpectationNotMetError with message
#
View
12 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-16}
+ 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",
@@ -162,17 +161,20 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<diff-lcs>, [">= 1.1.2"])
s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
s.add_development_dependency(%q<aruba>, [">= 0.1.1"])
s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.beta.8"])
s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.8"])
else
+ s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
s.add_dependency(%q<cucumber>, [">= 0.6.2"])
s.add_dependency(%q<aruba>, [">= 0.1.1"])
s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.8"])
s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.8"])
end
else
+ s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
s.add_dependency(%q<cucumber>, [">= 0.6.2"])
s.add_dependency(%q<aruba>, [">= 0.1.1"])
s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.8"])
View
34 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
@@ -94,35 +94,3 @@ def inspect
end
end
-
-
-describe "Diff in context format" do
- before(:each) do
- @options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
- @options.diff_format = :context
- @differ = RSpec::Expectations::Differs::Default.new(@options)
- end
-
- it "should output unified diff message of two objects" do
- expected = RSpec::Fixtures::Animal.new "bob", "giraffe"
- actual = RSpec::Fixtures::Animal.new "bob", "tortoise"
-
- expected_diff = <<'EOD'
-
-***************
-*** 1,5 ****
- <Animal
- name=bob,
-! species=tortoise
- >
---- 1,5 ----
- <Animal
- name=bob,
-! species=giraffe
- >
-EOD
-
- diff = @differ.diff_as_object(expected,actual)
- diff.should == expected_diff
- end
-end
View
46 spec/rspec/expectations/fail_with_spec.rb
@@ -1,33 +1,9 @@
require 'spec_helper'
-describe RSpec::Expectations, "#fail_with with no diff" do
- before(:each) do
- @old_differ = RSpec::Expectations.differ
- RSpec::Expectations.differ = nil
- end
-
- it "should handle just a message" do
- lambda {
- RSpec::Expectations.fail_with "the message"
- }.should fail_with("the message")
- end
-
- after(:each) do
- RSpec::Expectations.differ = @old_differ
- end
-end
-
-describe RSpec::Expectations, "#fail_with with Array" do
- before(:each) do
- RSpec::Core.stub!(:warn)
- end
-end
-
describe RSpec::Expectations, "#fail_with with diff" do
before(:each) do
- @old_differ = RSpec::Expectations.differ
@differ = mock("differ")
- RSpec::Expectations.differ = @differ
+ RSpec::Expectations.stub(:differ) { @differ }
end
it "should not call differ if no expected/actual" do
@@ -57,25 +33,5 @@
RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
}.should fail_with("the message")
end
-
- after(:each) do
- RSpec::Expectations.differ = @old_differ
- end
end
-describe RSpec::Expectations, "#fail_with with a nil message" do
- before(:each) do
- @old_differ = RSpec::Expectations.differ
- RSpec::Expectations.differ = nil
- end
-
- it "should handle just a message" do
- lambda {
- RSpec::Expectations.fail_with nil
- }.should raise_error(ArgumentError, /Failure message is nil\. Does your matcher define the appropriate failure_message_for_\* method to return a string\?/)
- end
-
- after(:each) do
- RSpec::Expectations.differ = @old_differ
- end
-end
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

No commit comments for this range

Something went wrong with that request. Please try again.