Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: rspec/rspec-expectations
...
head fork: rspec/rspec-expectations
  • 9 commits
  • 7 files changed
  • 1 commit comment
  • 4 contributors
Commits on Feb 15, 2011
Philippe Creux pcreux Better diff output for Hash b5f8d5a
Commits on Dec 28, 2011
Chad Humphries spicycode Merge pull request #60 from pcreux/master
Better diff output for Hash
2447ef6
Commits on Dec 29, 2011
David Chelimsky dchelimsky Changelog for last merge 6db8a2a
David Chelimsky dchelimsky make include matcher diffable 119e018
Commits on Jan 04, 2012
Olek Janiszewski exviva Fix warning in matchers/dsl.rb
lib/rspec/matchers/dsl.rb:10: warning: `*' interpreted as argument prefix
9b8aeb9
David Chelimsky dchelimsky Merge pull request #102 from exviva/fix_warning_splat_interpreted_as_…
…argument_prefix

Fix warning in matchers/dsl.rb
43b0918
David Chelimsky dchelimsky Diff single line and multiline strings differently 1273d4d
David Chelimsky dchelimsky Changelog for #102 [ci skip] b525e69
Commits on Jan 05, 2012
David Chelimsky dchelimsky bump to 2.8.0 04e55a8
9 Changelog.md
View
@@ -1,3 +1,12 @@
+### 2.8.0 / 2012-01-04
+
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0.rc2...v2.8.0)
+
+Enhancements
+
+* Better diff output for Hash (Philippe Creux)
+* Eliminate Ruby warnings (Olek Janiszewski)
+
### 2.8.0.rc2 / 2011-12-19
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0.rc1...v2.8.0.rc2)
28 lib/rspec/expectations/differ.rb
View
@@ -15,15 +15,15 @@ def diff_as_string(data_new, data_old)
output = ""
diffs = Diff::LCS.diff(data_old, data_new)
return output if diffs.empty?
- oldhunk = hunk = nil
+ 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
+ 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.
@@ -36,14 +36,14 @@ def diff_as_string(data_new, data_old)
oldhunk = hunk
output << "\n"
end
- end
+ end
#Handle the last remaining hunk
output << oldhunk.diff(format) << "\n"
- end
+ end
def diff_as_object(actual,expected)
- actual = String === actual ? actual : PP.pp(actual,"")
- expected = String === expected ? expected : PP.pp(expected,"")
+ actual = object_to_string(actual)
+ expected = object_to_string(expected)
diff_as_string(actual, expected)
end
@@ -56,7 +56,21 @@ def format
def context_lines
3
end
+
+ def object_to_string(object)
+ case object
+ when Hash
+ object.keys.sort_by { |k| k.to_s }.map do |k|
+ %(#{PP.singleline_pp(k, "")} => #{PP.singleline_pp(object[k], "")})
+ end.join(",\n")
+ when String
+ object =~ /\n/ ? object : object.inspect
+ else
+ PP.pp(object,"")
+ end
+ end
end
end
end
+
2  lib/rspec/expectations/version.rb
View
@@ -2,7 +2,7 @@ module RSpec
module Expectations
# @private
module Version
- STRING = '2.8.0.rc2'
+ STRING = '2.8.0'
end
end
end
2  lib/rspec/matchers/dsl.rb
View
@@ -7,7 +7,7 @@ def define(name, &declarations)
matcher = RSpec::Matchers::Matcher.new(name, &declarations)
define_method name do |*expected|
$matcher_execution_context = self
- matcher.for_expected *expected
+ matcher.for_expected(*expected)
end
end
4 lib/rspec/matchers/include.rb
View
@@ -20,6 +20,10 @@ def description
"include#{expected_to_sentence}"
end
+ def diffable?
+ true
+ end
+
private
def perform_match(predicate, hash_predicate, actuals, expecteds)
52 spec/rspec/expectations/differ_spec.rb
View
@@ -56,7 +56,7 @@ def inspect
expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
- expected_diff = <<'EOD'
+ expected_diff = <<EOD
@@ -5,7 +5,7 @@
@@ -70,7 +70,6 @@ def inspect
+ "quite wide"]
EOD
-
diff = @differ.diff_as_object(expected,actual)
diff.should == expected_diff
end
@@ -93,4 +92,53 @@ def inspect
diff.should == expected_diff
end
+ it "outputs unified diff message of two hashes" do
+ expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
+ actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
+
+ expected_diff = <<'EOD'
+
+@@ -1,4 +1,5 @@
+-:delta => "charlotte",
++:baz => "quux",
++:delta => "charlie",
+ :foo => "bar",
+ :metasyntactic => "variable",
+ :width => "quite wide"
+EOD
+
+ diff = @differ.diff_as_object(expected,actual)
+ diff.should == expected_diff
+ end
+
+ it "outputs unified diff of single line strings" do
+ expected = "this is one string"
+ actual = "this is another string"
+
+ expected_diff = <<EOD
+
+@@ -1,2 +1,2 @@
+-"this is another string"
++"this is one string"
+EOD
+
+ diff = @differ.diff_as_object(expected,actual)
+ diff.should == expected_diff
+ end
+
+ it "outputs unified diff of multi line strings" do
+ expected = "this is:\n one string"
+ actual = "this is:\n another string"
+
+ expected_diff = <<EOD
+
+@@ -1,3 +1,3 @@
+ this is:
+- another string
++ one string
+EOD
+
+ diff = @differ.diff_as_object(expected,actual)
+ diff.should == expected_diff
+ end
end
570 spec/rspec/matchers/include_spec.rb
View
@@ -1,345 +1,351 @@
require 'spec_helper'
-describe "should include(expected)" do
- context "for a string target" do
- it "passes if target includes expected" do
- "abc".should include("a")
- end
-
- it "fails if target does not include expected" do
- lambda {
- "abc".should include("d")
- }.should fail_with("expected \"abc\" to include \"d\"")
- end
- end
-
- context "for an array target" do
- it "passes if target includes expected" do
- [1,2,3].should include(3)
- end
-
- it "fails if target does not include expected" do
- lambda {
- [1,2,3].should include(4)
- }.should fail_with("expected [1, 2, 3] to include 4")
- end
+describe "#include matcher" do
+ it "is diffable" do
+ include("a").should be_diffable
end
- context "for a hash target" do
- it 'passes if target has the expected as a key' do
- {:key => 'value'}.should include(:key)
- end
+ describe "should include(with_one_arg)" do
+ context "for a string target" do
+ it "passes if target includes expected" do
+ "abc".should include("a")
+ end
- it "fails if target does not include expected" do
- lambda {
- {:key => 'value'}.should include(:other)
- }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
+ it "fails if target does not include expected" do
+ lambda {
+ "abc".should include("d")
+ }.should fail_matching("expected \"abc\" to include \"d\"")
+ end
end
- end
-end
-describe "should include(with, multiple, args)" do
- it "has a description" do
- matcher = include("a")
- matcher.description.should eq("include \"a\"")
- end
- context "for a string target" do
- it "passes if target includes all items" do
- "a string".should include("str", "a")
- end
+ context "for an array target" do
+ it "passes if target includes expected" do
+ [1,2,3].should include(3)
+ end
- it "fails if target does not include any one of the items" do
- lambda {
- "a string".should include("str", "a", "foo")
- }.should fail_with(%Q{expected "a string" to include "str", "a", and "foo"})
+ it "fails if target does not include expected" do
+ lambda {
+ [1,2,3].should include(4)
+ }.should fail_matching("expected [1, 2, 3] to include 4")
+ end
end
- end
- context "for an array target" do
- it "passes if target includes all items" do
- [1,2,3].should include(1,2,3)
- end
+ context "for a hash target" do
+ it 'passes if target has the expected as a key' do
+ {:key => 'value'}.should include(:key)
+ end
- it "fails if target does not include any one of the items" do
- lambda {
- [1,2,3].should include(1,2,4)
- }.should fail_with("expected [1, 2, 3] to include 1, 2, and 4")
+ it "fails if target does not include expected" do
+ lambda {
+ {:key => 'value'}.should include(:other)
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
+ end
end
end
- context "for a hash target" do
- it 'passes if target includes all items as keys' do
- {:key => 'value', :other => 'value'}.should include(:key, :other)
+ describe "should include(with, multiple, args)" do
+ it "has a description" do
+ matcher = include("a")
+ matcher.description.should eq("include \"a\"")
end
+ context "for a string target" do
+ it "passes if target includes all items" do
+ "a string".should include("str", "a")
+ end
- it 'fails if target is missing any item as a key' do
- lambda {
- {:key => 'value'}.should include(:key, :other)
- }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
+ it "fails if target does not include any one of the items" do
+ lambda {
+ "a string".should include("str", "a", "foo")
+ }.should fail_matching(%Q{expected "a string" to include "str", "a", and "foo"})
+ end
end
- end
-end
-describe "should_not include(expected)" do
- context "for a string target" do
- it "passes if target does not include expected" do
- "abc".should_not include("d")
- end
-
- it "fails if target includes expected" do
- lambda {
- "abc".should_not include("c")
- }.should fail_with("expected \"abc\" not to include \"c\"")
- end
- end
-
- context "for an array target" do
- it "passes if target does not include expected" do
- [1,2,3].should_not include(4)
- end
-
- it "fails if target includes expected" do
- lambda {
- [1,2,3].should_not include(3)
- }.should fail_with("expected [1, 2, 3] not to include 3")
- end
- end
-
- context "for a hash target" do
- it 'passes if target does not have the expected as a key' do
- {:other => 'value'}.should_not include(:key)
- end
-
- it "fails if target includes expected key" do
- lambda {
- {:key => 'value'}.should_not include(:key)
- }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
- end
- end
-
-end
-
-describe "should_not include(with, multiple, args)" do
- context "for a string target" do
- it "passes if the target does not include any of the expected" do
- "abc".should_not include("d", "e", "f")
- end
-
- 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"})
- end
-
- it "fails if the target includes some (but not all) of the expected" do
- expect {
- "abc".should_not include("d", "a")
- }.to fail_with(%q{expected "abc" not to include "d" and "a"})
- end
- end
+ context "for an array target" do
+ it "passes if target includes all items" do
+ [1,2,3].should include(1,2,3)
+ end
- context "for a hash target" do
- it "passes if it does not include any of the expected keys" do
- { :a => 1, :b => 2 }.should_not include(:c, :d)
+ it "fails if target does not include any one of the items" do
+ lambda {
+ [1,2,3].should include(1,2,4)
+ }.should fail_matching("expected [1, 2, 3] to include 1, 2, and 4")
+ end
end
- it "fails if the target includes all of the expected keys" do
- expect {
- { :a => 1, :b => 2 }.should_not include(:a, :b)
- }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :a and :b|)
- end
+ context "for a hash target" do
+ it 'passes if target includes all items as keys' do
+ {:key => 'value', :other => 'value'}.should include(:key, :other)
+ end
- it "fails if the target includes some (but not all) of the expected keys" do
- expect {
- { :a => 1, :b => 2 }.should_not include(:d, :b)
- }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :d and :b|)
+ it 'fails if target is missing any item as a key' do
+ lambda {
+ {:key => 'value'}.should include(:key, :other)
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
+ end
end
end
- context "for an array target" do
- it "passes if the target does not include any of the expected" do
- [1, 2, 3].should_not include(4, 5, 6)
- end
+ describe "should_not include(expected)" do
+ context "for a string target" do
+ it "passes if target does not include expected" do
+ "abc".should_not include("d")
+ end
- it "fails if the target includes all of the expected" do
- expect {
- [1, 2, 3].should_not include(3, 1)
- }.to fail_with(%q{expected [1, 2, 3] not to include 3 and 1})
+ it "fails if target includes expected" do
+ lambda {
+ "abc".should_not include("c")
+ }.should fail_with("expected \"abc\" not to include \"c\"")
+ end
end
- it "fails if the target includes some (but not all) of the expected" do
- expect {
- [1, 2, 3].should_not include(4, 1)
- }.to fail_with(%q{expected [1, 2, 3] not to include 4 and 1})
- end
- end
-end
+ context "for an array target" do
+ it "passes if target does not include expected" do
+ [1,2,3].should_not include(4)
+ end
-describe "should include(:key => value)" do
- context 'for a hash target' do
- it "passes if target includes the key/value pair" do
- {:key => 'value'}.should include(:key => 'value')
+ it "fails if target includes expected" do
+ lambda {
+ [1,2,3].should_not include(3)
+ }.should fail_with("expected [1, 2, 3] not to include 3")
+ end
end
- it "passes if target includes the key/value pair among others" do
- {:key => 'value', :other => 'different'}.should include(:key => 'value')
- end
+ context "for a hash target" do
+ it 'passes if target does not have the expected as a key' do
+ {:other => 'value'}.should_not include(:key)
+ end
- it "fails if target has a different value for key" do
- lambda {
- {:key => 'different'}.should include(:key => 'value')
- }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
+ it "fails if target includes expected key" do
+ lambda {
+ {:key => 'value'}.should_not include(:key)
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
+ end
end
- it "fails if target has a different key" do
- lambda {
- {:other => 'value'}.should include(:key => 'value')
- }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
- end
end
- context 'for a non-hash target' do
- it "fails if the target does not contain the given hash" do
- lambda {
- ['a', 'b'].should include(:key => 'value')
- }.should fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
- end
-
- it "passes if the target contains the given hash" do
- ['a', { :key => 'value' } ].should include(:key => 'value')
+ describe "should_not include(with, multiple, args)" do
+ context "for a string target" do
+ it "passes if the target does not include any of the expected" do
+ "abc".should_not include("d", "e", "f")
+ end
+
+ 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"})
+ end
+
+ it "fails if the target includes some (but not all) of the expected" do
+ expect {
+ "abc".should_not include("d", "a")
+ }.to fail_with(%q{expected "abc" not to include "d" and "a"})
+ end
+ end
+
+ context "for a hash target" do
+ it "passes if it does not include any of the expected keys" do
+ { :a => 1, :b => 2 }.should_not include(:c, :d)
+ end
+
+ it "fails if the target includes all of the expected keys" do
+ expect {
+ { :a => 1, :b => 2 }.should_not include(:a, :b)
+ }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :a and :b|)
+ end
+
+ it "fails if the target includes some (but not all) of the expected keys" do
+ expect {
+ { :a => 1, :b => 2 }.should_not include(:d, :b)
+ }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :d and :b|)
+ end
+ end
+
+ context "for an array target" do
+ it "passes if the target does not include any of the expected" do
+ [1, 2, 3].should_not include(4, 5, 6)
+ end
+
+ it "fails if the target includes all of the expected" do
+ expect {
+ [1, 2, 3].should_not include(3, 1)
+ }.to fail_with(%q{expected [1, 2, 3] not to include 3 and 1})
+ end
+
+ it "fails if the target includes some (but not all) of the expected" do
+ expect {
+ [1, 2, 3].should_not include(4, 1)
+ }.to fail_with(%q{expected [1, 2, 3] not to include 4 and 1})
+ end
end
end
-end
-describe "should_not include(:key => value)" do
- context 'for a hash target' do
- it "fails if target includes the key/value pair" do
- lambda {
- {:key => 'value'}.should_not include(:key => 'value')
- }.should fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
- end
+ describe "should include(:key => value)" do
+ context 'for a hash target' do
+ it "passes if target includes the key/value pair" do
+ {:key => 'value'}.should include(:key => 'value')
+ end
- it "fails if target includes the key/value pair among others" do
- lambda {
- {:key => 'value', :other => 'different'}.should_not include(:key => 'value')
- }.should fail_matching(%Q|expected #{{:key=>"value", :other=>"different"}.inspect} not to include {:key=>"value"}|)
- end
+ it "passes if target includes the key/value pair among others" do
+ {:key => 'value', :other => 'different'}.should include(:key => 'value')
+ end
- it "passes if target has a different value for key" do
- {:key => 'different'}.should_not include(:key => 'value')
- end
+ it "fails if target has a different value for key" do
+ lambda {
+ {:key => 'different'}.should include(:key => 'value')
+ }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
+ end
- it "passes if target has a different key" do
- {:other => 'value'}.should_not include(:key => 'value')
+ it "fails if target has a different key" do
+ lambda {
+ {:other => 'value'}.should include(:key => 'value')
+ }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
+ end
end
- end
- context "for a non-hash target" do
- it "passes if the target does not contain the given hash" do
- ['a', 'b'].should_not include(:key => 'value')
- end
+ context 'for a non-hash target' do
+ it "fails if the target does not contain the given hash" do
+ lambda {
+ ['a', 'b'].should include(:key => 'value')
+ }.should fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
+ end
- it "fails if the target contains the given hash" do
- lambda {
- ['a', { :key => 'value' } ].should_not include(:key => 'value')
- }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
+ it "passes if the target contains the given hash" do
+ ['a', { :key => 'value' } ].should include(:key => 'value')
+ end
end
end
-end
-describe "should include(:key1 => value1, :key2 => value2)" do
- context 'for a hash target' do
- it "passes if target includes the key/value pairs" do
- {:a => 1, :b => 2}.should include(:b => 2, :a => 1)
- end
+ describe "should_not include(:key => value)" do
+ context 'for a hash target' do
+ it "fails if target includes the key/value pair" do
+ lambda {
+ {:key => 'value'}.should_not include(:key => 'value')
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
+ end
- it "passes if target includes the key/value pairs among others" do
- {:a => 1, :c => 3, :b => 2}.should include(:b => 2, :a => 1)
- end
+ it "fails if target includes the key/value pair among others" do
+ lambda {
+ {:key => 'value', :other => 'different'}.should_not include(:key => 'value')
+ }.should fail_matching(%Q|expected #{{:key=>"value", :other=>"different"}.inspect} not to include {:key=>"value"}|)
+ end
- it "fails if target has a different value for one of the keys" do
- lambda {
- {:a => 1, :b => 2}.should include(:a => 2, :b => 2)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
- end
+ it "passes if target has a different value for key" do
+ {:key => 'different'}.should_not include(:key => 'value')
+ end
- it "fails if target has a different value for both of the keys" do
- lambda {
- {:a => 1, :b => 1}.should include(:a => 2, :b => 2)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
+ it "passes if target has a different key" do
+ {:other => 'value'}.should_not include(:key => 'value')
+ end
end
- it "fails if target lacks one of the keys" do
- lambda {
- {:a => 1, :b => 1}.should include(:a => 1, :c => 1)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>1, :c=>1}.inspect}|)
- end
+ context "for a non-hash target" do
+ it "passes if the target does not contain the given hash" do
+ ['a', 'b'].should_not include(:key => 'value')
+ end
- it "fails if target lacks both of the keys" do
- lambda {
- {:a => 1, :b => 1}.should include(:c => 1, :d => 1)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:c=>1, :d=>1}.inspect}|)
+ it "fails if the target contains the given hash" do
+ lambda {
+ ['a', { :key => 'value' } ].should_not include(:key => 'value')
+ }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
+ end
end
end
- context 'for a non-hash target' do
- it "fails if the target does not contain the given hash" do
- lambda {
- ['a', 'b'].should include(:a => 1, :b => 1)
- }.should fail_matching(%Q|expected ["a", "b"] to include #{{:a=>1, :b=>1}.inspect}|)
- end
-
- it "passes if the target contains the given hash" do
- ['a', { :a => 1, :b => 2 } ].should include(:a => 1, :b => 2)
+ describe "should include(:key1 => value1, :key2 => value2)" do
+ context 'for a hash target' do
+ it "passes if target includes the key/value pairs" do
+ {:a => 1, :b => 2}.should include(:b => 2, :a => 1)
+ end
+
+ it "passes if target includes the key/value pairs among others" do
+ {:a => 1, :c => 3, :b => 2}.should include(:b => 2, :a => 1)
+ end
+
+ it "fails if target has a different value for one of the keys" do
+ lambda {
+ {:a => 1, :b => 2}.should include(:a => 2, :b => 2)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
+ end
+
+ it "fails if target has a different value for both of the keys" do
+ lambda {
+ {:a => 1, :b => 1}.should include(:a => 2, :b => 2)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
+ end
+
+ it "fails if target lacks one of the keys" do
+ lambda {
+ {:a => 1, :b => 1}.should include(:a => 1, :c => 1)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>1, :c=>1}.inspect}|)
+ end
+
+ it "fails if target lacks both of the keys" do
+ lambda {
+ {:a => 1, :b => 1}.should include(:c => 1, :d => 1)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:c=>1, :d=>1}.inspect}|)
+ end
+ end
+
+ context 'for a non-hash target' do
+ it "fails if the target does not contain the given hash" do
+ lambda {
+ ['a', 'b'].should include(:a => 1, :b => 1)
+ }.should fail_matching(%Q|expected ["a", "b"] to include #{{:a=>1, :b=>1}.inspect}|)
+ end
+
+ it "passes if the target contains the given hash" do
+ ['a', { :a => 1, :b => 2 } ].should include(:a => 1, :b => 2)
+ end
end
end
-end
-
-describe "should_not include(:key1 => value1, :key2 => value2)" do
- context 'for a hash target' do
- it "fails if target includes the key/value pairs" do
- lambda {
- {:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
- end
-
- it "fails if target includes the key/value pairs among others" do
- hash = {:a => 1, :b => 2, :c => 3}
- lambda {
- hash.should_not include(:a => 1, :b => 2)
- }.should fail_matching(%Q|expected #{hash.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
- end
-
- it "fails if target has a different value for one of the keys" do
- lambda {
- {:a => 1, :b => 2}.should_not include(:a => 2, :b => 2)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>2, :b=>2}.inspect}|)
- end
-
- it "passes if target has a different value for both of the keys" do
- {:a => 1, :b => 1}.should_not include(:a => 2, :b => 2)
- end
-
- it "fails if target lacks one of the keys" do
- lambda {
- {:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} not to include #{{:a=>1, :c=>1}.inspect}|)
- end
-
- it "passes if target lacks both of the keys" do
- {:a => 1, :b => 1}.should_not include(:c => 1, :d => 1)
- end
- end
-
- context 'for a non-hash target' do
- it "passes if the target does not contain the given hash" do
- ['a', 'b'].should_not include(:a => 1, :b => 1)
- end
- it "fails if the target contains the given hash" do
- lambda {
- ['a', { :a => 1, :b => 2 } ].should_not include(:a => 1, :b => 2)
- }.should fail_matching(%Q|expected #{["a", {:a=>1, :b=>2}].inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
+ describe "should_not include(:key1 => value1, :key2 => value2)" do
+ context 'for a hash target' do
+ it "fails if target includes the key/value pairs" do
+ lambda {
+ {:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
+ end
+
+ it "fails if target includes the key/value pairs among others" do
+ hash = {:a => 1, :b => 2, :c => 3}
+ lambda {
+ hash.should_not include(:a => 1, :b => 2)
+ }.should fail_matching(%Q|expected #{hash.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
+ end
+
+ it "fails if target has a different value for one of the keys" do
+ lambda {
+ {:a => 1, :b => 2}.should_not include(:a => 2, :b => 2)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>2, :b=>2}.inspect}|)
+ end
+
+ it "passes if target has a different value for both of the keys" do
+ {:a => 1, :b => 1}.should_not include(:a => 2, :b => 2)
+ end
+
+ it "fails if target lacks one of the keys" do
+ lambda {
+ {:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} not to include #{{:a=>1, :c=>1}.inspect}|)
+ end
+
+ it "passes if target lacks both of the keys" do
+ {:a => 1, :b => 1}.should_not include(:c => 1, :d => 1)
+ end
+ end
+
+ context 'for a non-hash target' do
+ it "passes if the target does not contain the given hash" do
+ ['a', 'b'].should_not include(:a => 1, :b => 1)
+ end
+
+ it "fails if the target contains the given hash" do
+ lambda {
+ ['a', { :a => 1, :b => 2 } ].should_not include(:a => 1, :b => 2)
+ }.should fail_matching(%Q|expected #{["a", {:a=>1, :b=>2}].inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
+ end
end
end
end

Showing you all comments on commits in this comparison.

Olek Janiszewski

Perfect timing, I was just about to report this issue!

Something went wrong with that request. Please try again.