From 044b0a6ff1ae4c06aaa0aefc73b5b19aba0ef7cb Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Mon, 6 Feb 2012 07:30:32 -0600 Subject: [PATCH] Treat expected args consistently across positive and negative expectations. - Fixes #115. --- lib/rspec/expectations/fail_with.rb | 6 +++--- lib/rspec/expectations/handler.rb | 2 +- spec/rspec/expectations/handler_spec.rb | 2 +- spec/rspec/matchers/cover_spec.rb | 10 +++++----- spec/rspec/matchers/include_spec.rb | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/rspec/expectations/fail_with.rb b/lib/rspec/expectations/fail_with.rb index 4742022fa..edca8224b 100644 --- a/lib/rspec/expectations/fail_with.rb +++ b/lib/rspec/expectations/fail_with.rb @@ -35,11 +35,11 @@ def fail_with(message, expected=nil, actual=nil) private def no_procs?(*args) - args.none? {|a| Proc === a} + args.flatten.none? {|a| Proc === a} end def all_strings?(*args) - args.all? {|a| String === a} + args.flatten.all? {|a| String === a} end def any_multiline_strings?(*args) @@ -47,7 +47,7 @@ def any_multiline_strings?(*args) end def no_numbers?(*args) - args.none? {|a| Numeric === a} + args.flatten.none? {|a| Numeric === a} end end end diff --git a/lib/rspec/expectations/handler.rb b/lib/rspec/expectations/handler.rb index f82e2e5fc..a1f209288 100644 --- a/lib/rspec/expectations/handler.rb +++ b/lib/rspec/expectations/handler.rb @@ -37,7 +37,7 @@ def self.handle_matcher(actual, matcher, message=nil, &block) matcher.negative_failure_message if matcher.respond_to?(:diffable?) && matcher.diffable? - ::RSpec::Expectations.fail_with message, matcher.expected.first, matcher.actual + ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual else ::RSpec::Expectations.fail_with message end diff --git a/spec/rspec/expectations/handler_spec.rb b/spec/rspec/expectations/handler_spec.rb index 6cb3d90d1..7d14d0abb 100644 --- a/spec/rspec/expectations/handler_spec.rb +++ b/spec/rspec/expectations/handler_spec.rb @@ -159,7 +159,7 @@ module Expectations :diffable? => true, :failure_message_for_should_not => "message", :matches? => true, - :expected => [1], + :expected => 1, :actual => 2 ) actual = Object.new diff --git a/spec/rspec/matchers/cover_spec.rb b/spec/rspec/matchers/cover_spec.rb index cb557b2bc..d01389954 100644 --- a/spec/rspec/matchers/cover_spec.rb +++ b/spec/rspec/matchers/cover_spec.rb @@ -46,19 +46,19 @@ describe "should_not cover(with, multiple, args)" do context "for a range target" do it "passes if the target does not cover any of the expected" do - (1..10).should_not include(11, 12, 13) + (1..10).should_not cover(11, 12, 13) end it "fails if the target covers all of the expected" do expect { - (1..10).should_not include(4, 6) - }.to fail_with("expected 1..10 not to include 4 and 6") + (1..10).should_not cover(4, 6) + }.to fail_with("expected 1..10 not to cover 4 and 6") end it "fails if the target covers some (but not all) of the expected" do expect { - (1..10).should_not include(5, 11) - }.to fail_with("expected 1..10 not to include 5 and 11") + (1..10).should_not cover(5, 11) + }.to fail_with("expected 1..10 not to cover 5 and 11") end end end diff --git a/spec/rspec/matchers/include_spec.rb b/spec/rspec/matchers/include_spec.rb index 05ccf10b2..6f85821ab 100644 --- a/spec/rspec/matchers/include_spec.rb +++ b/spec/rspec/matchers/include_spec.rb @@ -133,7 +133,7 @@ it "fails if the target includes all of the expected" do expect { "abc".should_not include("c", "a") - }.to fail_with(%q{expected "abc" not to include "c" and "a"}) + }.to fail_with('expected "abc" not to include "c" and "a"') end it "fails if the target includes some (but not all) of the expected" do