Skip to content

Loading…

Add awesome_print if available. #2

Open
wants to merge 1 commit into from

1 participant

@bobtfish

This makes working out what the differences between complex structures is
much easier as they're pretty printed across multiple lines.

@bobtfish bobtfish Add awesome_print if available.
This makes working out what the differences between complex structures is
much easier as they're pretty printed across multiple lines.
d4992e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2013
  1. @bobtfish

    Add awesome_print if available.

    bobtfish committed
    This makes working out what the differences between complex structures is
    much easier as they're pretty printed across multiple lines.
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 2 deletions.
  1. +18 −2 lib/deep/matchers/deep_eql.rb
  2. +1 −0 rspec-deep-matchers.gemspec
  3. +18 −0 spec/lib/rspec/matchers/deep_eql_spec.rb
View
20 lib/deep/matchers/deep_eql.rb
@@ -8,6 +8,13 @@ def deep_eql(expected)
class DeepEql
def initialize(expectation)
+ begin
+ require 'awesome_print'
+ require 'awesome_print/core_ext/kernel'
+ @have_ap = true
+ rescue Exception => e
+ @have_ap = false
+ end
@expectation = expectation
end
@@ -32,14 +39,23 @@ def matches?(target)
result
end
+ def pretty_print(thing)
+ if @have_ap
+ thing.awesome_inspect(:plain => true)
+ else
+ thing.inspect
+ end
+ end
+
def failure_message_for_should
- "expected #{@target.inspect} to be deep_eql with #{@expectation.inspect}"
+ "expected #{pretty_print @target} to be deep_eql with #{pretty_print @expectation}"
end
def failure_message_for_should_not
- "expected #{@target.inspect} not to be in deep_eql with #{@expectation.inspect}"
+ "expected #{pretty_print @target} not to be in deep_eql with #{pretty_print @expectation}"
end
end
end
end
+
View
1 rspec-deep-matchers.gemspec
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('guard-rspec')
s.add_development_dependency('growl')
+ s.add_development_dependency('awesome_print')
end
View
18 spec/lib/rspec/matchers/deep_eql_spec.rb
@@ -134,4 +134,22 @@
end
+ context "pretty printing" do
+ actual = { :foo => "bar", :baz => "quux", :foo2 => "bar", :baz2 => "quux", :foo3 => "bar", :baz3 => "quux",}
+ exp = { :foo => "bar", :baz => "fnar" }
+ de = Deep::Matchers::DeepEql.new(exp)
+ de.matches?(actual).should == false
+ de.failure_message_for_should.should == 'expected {
+ :foo => "bar",
+ :baz => "quux",
+ :foo2 => "bar",
+ :baz2 => "quux",
+ :foo3 => "bar",
+ :baz3 => "quux"
+} to be deep_eql with {
+ :foo => "bar",
+ :baz => "fnar"
+}'
+ end
end
+
Something went wrong with that request. Please try again.