Skip to content

Commit

Permalink
Treat expected args consistently across positive and negative expecta…
Browse files Browse the repository at this point in the history
…tions.

- Fixes #115.
  • Loading branch information
dchelimsky committed Feb 6, 2012
1 parent 17325de commit 044b0a6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/rspec/expectations/fail_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ 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)
all_strings?(*args) && args.any? {|a| a =~ /\n/}
end

def no_numbers?(*args)
args.none? {|a| Numeric === a}
args.flatten.none? {|a| Numeric === a}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/expectations/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/expectations/handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/rspec/matchers/cover_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/matchers/include_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 044b0a6

Please sign in to comment.