Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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
  • 16 commits
  • 13 files changed
  • 2 commit comments
  • 4 contributors
View
41 Gemfile
@@ -1,21 +1,38 @@
source "http://rubygems.org"
+### rspec libs
%w[rspec-core rspec-expectations rspec-mocks].each do |lib|
- gem lib, :path => File.expand_path("../../#{lib}", __FILE__)
+ library_path = File.expand_path("../../#{lib}", __FILE__)
+ if File.exist?(library_path)
+ gem lib, :path => library_path
+ else
+ gem lib
+ end
end
-gem "rake"
+### dev dependencies
+gem "rake", "0.8.7"
gem "cucumber", "0.9.4"
gem "aruba", "0.2.2"
-gem "autotest"
-gem "diff-lcs"
-gem "watchr"
-gem "rcov"
-gem "relish"
+gem "rcov", "0.9.9"
+gem "relish", "0.2.0"
+gem "guard-rspec", "0.1.9"
+gem "growl", "1.0.3"
+gem "ZenTest", "~> 4.4.2"
-case RUBY_VERSION
-when '1.9.2'
- gem 'ruby-debug19'
-when /^1\.8/
- gem 'ruby-debug'
+if RUBY_PLATFORM =~ /darwin/
+ gem "autotest-fsevent", "~> 0.2.4"
+ gem "autotest-growl", "~> 0.2.9"
+end
+
+gem "ruby-debug", :platforms => :ruby_18
+gem "ruby-debug19", "~> 0.11.6", :platforms => :ruby_19
+
+platforms :ruby_18, :ruby_19 do
+ gem "rb-fsevent", "~> 0.3.9"
+ gem "ruby-prof", "~> 0.9.2"
+end
+
+platforms :jruby do
+ gem "jruby-openssl"
end
View
7 History.markdown
@@ -1,5 +1,12 @@
## rspec-expectations release history (incomplete)
+### 2.3.0 / 2010-12-12
+
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0)
+
+* Enhancements
+ * diff strings when include matcher fails (Mike Sassak)
+
### 2.2.0 / 2010-11-28
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.1.0...v2.2.0)
View
4 README.md
@@ -5,10 +5,10 @@ RSpec::Matchers, a library of standard matchers.
## Documentation
-The [Cucumber features](http://relishapp.com/rspec/rspec-expectations/v/2-1)
+The [Cucumber features](http://relishapp.com/rspec/rspec-expectations)
are the most comprehensive and up-to-date docs for end-users.
-The [RDoc](http://rubydoc.info/gems/rspec-expectations/2.1/frames) provides
+The [RDoc](http://rubydoc.info/gems/rspec-expectations/2.3.0/frames) provides
additional information for contributors and/or extenders.
All of the documentation is open source and a work in progress. If you find it
View
5 features/matchers/include.feature
@@ -131,6 +131,5 @@ Feature: include matcher
| expected {:a=>7, :b=>5} to include {:a=>5, :b=>7} |
| expected {:a=>7, :b=>5} to include :a and :d |
| expected {:a=>7, :b=>5} not to include :a and :d |
- | expected {:a=>7, :b=>5} to include {:a=>7, :d=>3} |
- | expected {:a=>7, :b=>5} not to include {:a=>7, :d=>3} |
-
+ And the output should match /expected \{:a=>7, :b=>5\} to include \{(?::a=>7, :d=>3)|(?::d=>3, :a=>7)\}/
+ And the output should match /expected \{:a=>7, :b=>5\} not to include \{(?::a=>7, :d=>3)|(?::d=>3, :a=>7)\}/
View
2  lib/rspec/expectations/version.rb
@@ -1,7 +1,7 @@
module RSpec # :nodoc:
module Expectations # :nodoc:
module Version # :nodoc:
- STRING = '2.2.0'
+ STRING = '2.3.0'
end
end
end
View
3  lib/rspec/matchers/include.rb
@@ -18,6 +18,9 @@ module Matchers
# "spread".should_not include("red")
def include(*expected)
Matcher.new :include, *expected do |*_expected|
+
+ diffable
+
match_for_should do |actual|
perform_match(:all?, :all?, actual, _expected)
end
View
586 spec/rspec/matchers/have_spec.rb
@@ -27,201 +27,201 @@ def create_collection_owner_with(n)
owner
end
-describe "should have(n).items" do
+ describe "should have(n).items" do
- it "passes if target has a collection of items with n members" do
- owner = create_collection_owner_with(3)
- owner.should have(3).items_in_collection_with_length_method
- owner.should have(3).items_in_collection_with_size_method
- end
-
- it "converts :no to 0" do
- owner = create_collection_owner_with(0)
- owner.should have(:no).items_in_collection_with_length_method
- owner.should have(:no).items_in_collection_with_size_method
- end
+ it "passes if target has a collection of items with n members" do
+ owner = create_collection_owner_with(3)
+ owner.should have(3).items_in_collection_with_length_method
+ owner.should have(3).items_in_collection_with_size_method
+ end
- it "fails if target has a collection of items with < n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should have(4).items_in_collection_with_length_method
- }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should have(4).items_in_collection_with_size_method
- }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
- end
-
- it "fails if target has a collection of items with > n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should have(2).items_in_collection_with_length_method
- }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should have(2).items_in_collection_with_size_method
- }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
- end
-end
+ it "converts :no to 0" do
+ owner = create_collection_owner_with(0)
+ owner.should have(:no).items_in_collection_with_length_method
+ owner.should have(:no).items_in_collection_with_size_method
+ end
-describe 'should have(1).item when ActiveSupport::Inflector is defined' do
-
- it 'pluralizes the collection name' do
- owner = create_collection_owner_with(1)
- owner.should have(1).item
+ it "fails if target has a collection of items with < n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should have(4).items_in_collection_with_length_method
+ }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should have(4).items_in_collection_with_size_method
+ }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
+ end
+
+ it "fails if target has a collection of items with > n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should have(2).items_in_collection_with_length_method
+ }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should have(2).items_in_collection_with_size_method
+ }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
+ end
end
- context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
-
- it "does not pluralize the collection name" do
- (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
+ describe 'should have(1).item when ActiveSupport::Inflector is defined' do
+
+ it 'pluralizes the collection name' do
owner = create_collection_owner_with(1)
- expect { owner.should have(1).item }.to raise_error(NoMethodError)
+ owner.should have(1).item
end
- end
-
- after(:each) do
- unless @active_support_was_defined
- Object.__send__ :remove_const, :ActiveSupport
+ context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
+
+ it "does not pluralize the collection name" do
+ (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
+ owner = create_collection_owner_with(1)
+ expect { owner.should have(1).item }.to raise_error(NoMethodError)
+ end
+
+ end
+
+ after(:each) do
+ unless @active_support_was_defined
+ Object.__send__ :remove_const, :ActiveSupport
+ end
end
end
-end
-describe 'should have(1).item when Inflector is defined' do
-
- before(:each) do
- if defined?(Inflector)
- @inflector_was_defined = true
- else
- @inflector_was_defined = false
- class ::Inflector
- def self.pluralize(string)
- string.to_s + 's'
+ describe 'should have(1).item when Inflector is defined' do
+
+ before(:each) do
+ if defined?(Inflector)
+ @inflector_was_defined = true
+ else
+ @inflector_was_defined = false
+ class ::Inflector
+ def self.pluralize(string)
+ string.to_s + 's'
+ end
end
end
end
- end
-
- it 'pluralizes the collection name' do
- owner = create_collection_owner_with(1)
- owner.should have(1).item
- end
-
- after(:each) do
- unless @inflector_was_defined
- Object.__send__ :remove_const, :Inflector
+
+ it 'pluralizes the collection name' do
+ owner = create_collection_owner_with(1)
+ owner.should have(1).item
end
- end
-end
-describe "should have(n).items where result responds to items but returns something other than a collection" do
- it "provides a meaningful error" do
- owner = Class.new do
- def items
- Object.new
+ after(:each) do
+ unless @inflector_was_defined
+ Object.__send__ :remove_const, :Inflector
end
- end.new
- lambda do
- owner.should have(3).items
- end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
+ end
end
-end
-describe "should_not have(n).items" do
-
- it "passes if target has a collection of items with < n members" do
- owner = create_collection_owner_with(3)
- owner.should_not have(4).items_in_collection_with_length_method
- owner.should_not have(4).items_in_collection_with_size_method
- end
-
- it "passes if target has a collection of items with > n members" do
- owner = create_collection_owner_with(3)
- owner.should_not have(2).items_in_collection_with_length_method
- owner.should_not have(2).items_in_collection_with_size_method
+ describe "should have(n).items where result responds to items but returns something other than a collection" do
+ it "provides a meaningful error" do
+ owner = Class.new do
+ def items
+ Object.new
+ end
+ end.new
+ lambda do
+ owner.should have(3).items
+ end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
+ end
end
- it "fails if target has a collection of items with n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should_not have(3).items_in_collection_with_length_method
- }.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should_not have(3).items_in_collection_with_size_method
- }.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
- end
-end
+ describe "should_not have(n).items" do
-describe "should have_exactly(n).items" do
+ it "passes if target has a collection of items with < n members" do
+ owner = create_collection_owner_with(3)
+ owner.should_not have(4).items_in_collection_with_length_method
+ owner.should_not have(4).items_in_collection_with_size_method
+ end
+
+ it "passes if target has a collection of items with > n members" do
+ owner = create_collection_owner_with(3)
+ owner.should_not have(2).items_in_collection_with_length_method
+ owner.should_not have(2).items_in_collection_with_size_method
+ end
- it "passes if target has a collection of items with n members" do
- owner = create_collection_owner_with(3)
- owner.should have_exactly(3).items_in_collection_with_length_method
- owner.should have_exactly(3).items_in_collection_with_size_method
+ it "fails if target has a collection of items with n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should_not have(3).items_in_collection_with_length_method
+ }.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should_not have(3).items_in_collection_with_size_method
+ }.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
+ end
end
- it "converts :no to 0" do
- owner = create_collection_owner_with(0)
- owner.should have_exactly(:no).items_in_collection_with_length_method
- owner.should have_exactly(:no).items_in_collection_with_size_method
- end
+ describe "should have_exactly(n).items" do
- it "fails if target has a collection of items with < n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should have_exactly(4).items_in_collection_with_length_method
- }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should have_exactly(4).items_in_collection_with_size_method
- }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
- end
-
- it "fails if target has a collection of items with > n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should have_exactly(2).items_in_collection_with_length_method
- }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should have_exactly(2).items_in_collection_with_size_method
- }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
- end
-end
+ it "passes if target has a collection of items with n members" do
+ owner = create_collection_owner_with(3)
+ owner.should have_exactly(3).items_in_collection_with_length_method
+ owner.should have_exactly(3).items_in_collection_with_size_method
+ end
-describe "should have_at_least(n).items" do
+ it "converts :no to 0" do
+ owner = create_collection_owner_with(0)
+ owner.should have_exactly(:no).items_in_collection_with_length_method
+ owner.should have_exactly(:no).items_in_collection_with_size_method
+ end
- it "passes if target has a collection of items with n members" do
- owner = create_collection_owner_with(3)
- owner.should have_at_least(3).items_in_collection_with_length_method
- owner.should have_at_least(3).items_in_collection_with_size_method
- end
-
- it "passes if target has a collection of items with > n members" do
- owner = create_collection_owner_with(3)
- owner.should have_at_least(2).items_in_collection_with_length_method
- owner.should have_at_least(2).items_in_collection_with_size_method
+ it "fails if target has a collection of items with < n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should have_exactly(4).items_in_collection_with_length_method
+ }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should have_exactly(4).items_in_collection_with_size_method
+ }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
+ end
+
+ it "fails if target has a collection of items with > n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should have_exactly(2).items_in_collection_with_length_method
+ }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should have_exactly(2).items_in_collection_with_size_method
+ }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
+ end
end
- it "fails if target has a collection of items with < n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should have_at_least(4).items_in_collection_with_length_method
- }.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should have_at_least(4).items_in_collection_with_size_method
- }.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
- end
-
- it "provides educational negative failure messages" do
- #given
- owner = create_collection_owner_with(3)
- length_matcher = have_at_least(3).items_in_collection_with_length_method
- size_matcher = have_at_least(3).items_in_collection_with_size_method
+ describe "should have_at_least(n).items" do
+
+ it "passes if target has a collection of items with n members" do
+ owner = create_collection_owner_with(3)
+ owner.should have_at_least(3).items_in_collection_with_length_method
+ owner.should have_at_least(3).items_in_collection_with_size_method
+ end
- #when
- length_matcher.matches?(owner)
- size_matcher.matches?(owner)
+ it "passes if target has a collection of items with > n members" do
+ owner = create_collection_owner_with(3)
+ owner.should have_at_least(2).items_in_collection_with_length_method
+ owner.should have_at_least(2).items_in_collection_with_size_method
+ end
+
+ it "fails if target has a collection of items with < n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should have_at_least(4).items_in_collection_with_length_method
+ }.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should have_at_least(4).items_in_collection_with_size_method
+ }.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
+ end
- #then
- length_matcher.failure_message_for_should_not.should == <<-EOF
+ it "provides educational negative failure messages" do
+ #given
+ owner = create_collection_owner_with(3)
+ length_matcher = have_at_least(3).items_in_collection_with_length_method
+ size_matcher = have_at_least(3).items_in_collection_with_size_method
+
+ #when
+ length_matcher.matches?(owner)
+ size_matcher.matches?(owner)
+
+ #then
+ length_matcher.failure_message_for_should_not.should == <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_least(3).items_in_collection_with_length_method
@@ -229,183 +229,173 @@ def items
should have_at_most(2).items_in_collection_with_length_method
EOF
- size_matcher.failure_message_for_should_not.should == <<-EOF
+ size_matcher.failure_message_for_should_not.should == <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_least(3).items_in_collection_with_size_method
We recommend that you use this instead:
should have_at_most(2).items_in_collection_with_size_method
EOF
- end
-end
-
-describe "should have_at_most(n).items" do
- it "passes if target has a collection of items with n members" do
- owner = create_collection_owner_with(3)
- owner.should have_at_most(3).items_in_collection_with_length_method
- owner.should have_at_most(3).items_in_collection_with_size_method
+ end
end
- it "fails if target has a collection of items with > n members" do
- owner = create_collection_owner_with(3)
- lambda {
- owner.should have_at_most(2).items_in_collection_with_length_method
- }.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
- lambda {
- owner.should have_at_most(2).items_in_collection_with_size_method
- }.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
- end
-
- it "passes if target has a collection of items with < n members" do
- owner = create_collection_owner_with(3)
- owner.should have_at_most(4).items_in_collection_with_length_method
- owner.should have_at_most(4).items_in_collection_with_size_method
- end
+ describe "should have_at_most(n).items" do
+ it "passes if target has a collection of items with n members" do
+ owner = create_collection_owner_with(3)
+ owner.should have_at_most(3).items_in_collection_with_length_method
+ owner.should have_at_most(3).items_in_collection_with_size_method
+ end
- it "provides educational negative failure messages" do
- #given
- owner = create_collection_owner_with(3)
- length_matcher = have_at_most(3).items_in_collection_with_length_method
- size_matcher = have_at_most(3).items_in_collection_with_size_method
-
- #when
- length_matcher.matches?(owner)
- size_matcher.matches?(owner)
+ it "fails if target has a collection of items with > n members" do
+ owner = create_collection_owner_with(3)
+ lambda {
+ owner.should have_at_most(2).items_in_collection_with_length_method
+ }.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
+ lambda {
+ owner.should have_at_most(2).items_in_collection_with_size_method
+ }.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
+ end
- #then
- length_matcher.failure_message_for_should_not.should == <<-EOF
+ it "passes if target has a collection of items with < n members" do
+ owner = create_collection_owner_with(3)
+ owner.should have_at_most(4).items_in_collection_with_length_method
+ owner.should have_at_most(4).items_in_collection_with_size_method
+ end
+
+ it "provides educational negative failure messages" do
+ #given
+ owner = create_collection_owner_with(3)
+ length_matcher = have_at_most(3).items_in_collection_with_length_method
+ size_matcher = have_at_most(3).items_in_collection_with_size_method
+
+ #when
+ length_matcher.matches?(owner)
+ size_matcher.matches?(owner)
+
+ #then
+ length_matcher.failure_message_for_should_not.should == <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_most(3).items_in_collection_with_length_method
We recommend that you use this instead:
should have_at_least(4).items_in_collection_with_length_method
EOF
-
- size_matcher.failure_message_for_should_not.should == <<-EOF
+
+ size_matcher.failure_message_for_should_not.should == <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_most(3).items_in_collection_with_size_method
We recommend that you use this instead:
should have_at_least(4).items_in_collection_with_size_method
EOF
+ end
end
-end
-describe "have(n).items(args, block)" do
- it "passes args to target" do
- target = mock("target")
- target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
- target.should have(3).items("arg1","arg2")
- end
+ describe "have(n).items(args, block)" do
+ it "passes args to target" do
+ target = mock("target")
+ target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
+ target.should have(3).items("arg1","arg2")
+ end
- it "passes block to target" do
- target = mock("target")
- block = lambda { 5 }
- target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
- target.should have(3).items("arg1","arg2", block)
+ it "passes block to target" do
+ target = mock("target")
+ block = lambda { 5 }
+ target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
+ target.should have(3).items("arg1","arg2", block)
+ end
end
-end
-describe "have(n).items where target IS a collection" do
- it "references the number of items IN the collection" do
- [1,2,3].should have(3).items
- end
+ describe "have(n).items where target IS a collection" do
+ it "references the number of items IN the collection" do
+ [1,2,3].should have(3).items
+ end
- it "fails when the number of items IN the collection is not as expected" do
- lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
+ it "fails when the number of items IN the collection is not as expected" do
+ lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
+ end
end
-end
-describe "have(n).characters where target IS a String" do
- it "passes if the length is correct" do
- "this string".should have(11).characters
- end
+ describe "have(n).characters where target IS a String" do
+ it "passes if the length is correct" do
+ "this string".should have(11).characters
+ end
- it "fails if the length is incorrect" do
- lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
+ it "fails if the length is incorrect" do
+ lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
+ end
end
-end
-describe "have(n).things on an object which is not a collection nor contains one" do
- it "fails" do
- lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
+ describe "have(n).things on an object which is not a collection nor contains one" do
+ it "fails" do
+ lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
+ end
end
-end
-describe RSpec::Matchers::Have, "for a collection owner that implements #send" do
- before(:each) do
- @collection = Object.new
- def @collection.floozles; [1,2] end
- def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
- end
-
- it "works in the straightforward case" do
- lambda {
- @collection.should have(2).floozles
- }.should_not raise_error
- end
+ describe RSpec::Matchers::Have, "for a collection owner that implements #send" do
+ before(:each) do
+ @collection = Object.new
+ def @collection.floozles; [1,2] end
+ def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
+ end
+
+ it "works in the straightforward case" do
+ lambda {
+ @collection.should have(2).floozles
+ }.should_not raise_error
+ end
- it "works when doing automatic pluralization" do
- lambda {
- @collection.should have_at_least(1).floozle
- }.should_not raise_error
- end
+ it "works when doing automatic pluralization" do
+ lambda {
+ @collection.should have_at_least(1).floozle
+ }.should_not raise_error
+ end
- it "blows up when the owner doesn't respond to that method" do
- lambda {
- @collection.should have(99).problems
- }.should raise_error(NoMethodError, /problems/)
+ it "blows up when the owner doesn't respond to that method" do
+ lambda {
+ @collection.should have(99).problems
+ }.should raise_error(NoMethodError, /problems/)
+ end
end
-end
-module RSpec
- module Matchers
- describe Have do
- it "has method_missing as private" do
- with_ruby 1.8 do
- described_class.private_instance_methods.should include("method_missing")
- end
- with_ruby 1.9 do
- described_class.private_instance_methods.should include(:method_missing)
- end
- end
+ describe RSpec::Matchers::Have do
+ it "has method_missing as private" do
+ described_class.private_instance_methods.should include_method(:method_missing)
+ end
- it "does not respond_to? method_missing (because it's private)" do
- formatter = described_class.new({ }, StringIO.new)
- formatter.should_not respond_to(:method_missing)
- end
+ it "does not respond_to? method_missing (because it's private)" do
+ formatter = described_class.new({ }, StringIO.new)
+ formatter.should_not respond_to(:method_missing)
+ end
- describe "respond_to?" do
- before :each do
- @have = Have.new(:foo)
- @a_method_which_have_defines = Have.instance_methods.first
- @a_method_which_object_defines = Object.instance_methods.first
- end
-
- it "is true for a method which Have defines" do
- @have.should respond_to(@a_method_which_have_defines)
- end
-
- it "is true for a method that it's superclass (Object) defines" do
- @have.should respond_to(@a_method_which_object_defines)
- end
-
- it "is false for a method which neither Object nor nor Have defines" do
- @have.should_not respond_to(:foo_bar_baz)
- end
-
- it "is false if the owner doesn't respond to the method" do
- have = Have.new(99)
- have.should_not respond_to(:problems)
- end
-
- it "is true if the owner responds to the method" do
- have = Have.new(:a_symbol)
- have.should respond_to(:to_sym)
- end
+ describe "respond_to?" do
+ before :each do
+ @have = described_class.new(:foo)
+ @a_method_which_have_defines = described_class.instance_methods.first
+ @a_method_which_object_defines = Object.instance_methods.first
+ end
+
+ it "is true for a method which Have defines" do
+ @have.should respond_to(@a_method_which_have_defines)
+ end
+
+ it "is true for a method that it's superclass (Object) defines" do
+ @have.should respond_to(@a_method_which_object_defines)
+ end
+
+ it "is false for a method which neither Object nor nor Have defines" do
+ @have.should_not respond_to(:foo_bar_baz)
+ end
+
+ it "is false if the owner doesn't respond to the method" do
+ have = described_class.new(99)
+ have.should_not respond_to(:problems)
+ end
+
+ it "is true if the owner responds to the method" do
+ have = described_class.new(:a_symbol)
+ have.should respond_to(:to_sym)
end
end
end
end
-
-end
View
50 spec/rspec/matchers/include_spec.rb
@@ -33,7 +33,7 @@
it "fails if target does not include expected" do
lambda {
{:key => 'value'}.should include(:other)
- }.should fail_with(%Q|expected {:key=>"value"} to include :other|)
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
end
end
end
@@ -71,7 +71,7 @@
it 'fails if target is missing any item as a key' do
lambda {
{:key => 'value'}.should include(:key, :other)
- }.should fail_with(%Q|expected {:key=>"value"} to include :key and :other|)
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
end
end
end
@@ -109,7 +109,7 @@
it "fails if target includes expected key" do
lambda {
{:key => 'value'}.should_not include(:key)
- }.should fail_with(%Q|expected {:key=>"value"} not to include :key|)
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
end
end
@@ -142,13 +142,13 @@
it "fails if the target includes all of the expected keys" do
expect {
{ :a => 1, :b => 2 }.should_not include(:a, :b)
- }.to fail_with(%q|expected {:a=>1, :b=>2} not to include :a and :b|)
+ }.to fail_matching(%Q|expected {:a=>1, :b=>2} 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_with(%q|expected {:a=>1, :b=>2} not to include :d and :b|)
+ }.to fail_matching(%Q|expected {:a=>1, :b=>2} not to include :d and :b|)
end
end
@@ -184,13 +184,13 @@
it "fails if target has a different value for key" do
lambda {
{:key => 'different'}.should include(:key => 'value')
- }.should fail_with(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
+ }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
end
it "fails if target has a different key" do
lambda {
{:other => 'value'}.should include(:key => 'value')
- }.should fail_with(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
+ }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
end
end
@@ -198,7 +198,7 @@
it "fails if the target does not contain the given hash" do
lambda {
['a', 'b'].should include(:key => 'value')
- }.should fail_with(%q|expected ["a", "b"] to 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
@@ -212,13 +212,13 @@
it "fails if target includes the key/value pair" do
lambda {
{:key => 'value'}.should_not include(:key => 'value')
- }.should fail_with(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
+ }.should fail_matching(%Q|expected {:key=>"value"} not to 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_with(%Q|expected {:key=>"value", :other=>"different"} not to include {:key=>"value"}|)
+ }.should fail_matching(%Q|expected {:key=>"value", :other=>"different"} not to include {:key=>"value"}|)
end
it "passes if target has a different value for key" do
@@ -238,7 +238,7 @@
it "fails if the target contains the given hash" do
lambda {
['a', { :key => 'value' } ].should_not include(:key => 'value')
- }.should fail_with(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
+ }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
end
end
end
@@ -256,25 +256,31 @@
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_with(%Q|expected {:a=>1, :b=>2} to include {:a=>2, :b=>2}|)
+ }.should fail_matching(%Q|expected {:a=>1, :b=>2} to include {:a=>2, :b=>2}|)
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_with(%Q|expected {:a=>1, :b=>1} to include {:a=>2, :b=>2}|)
+ }.should fail_matching(%Q|expected {:a=>1, :b=>1} to include {:a=>2, :b=>2}|)
end
it "fails if target lacks one of the keys" do
lambda {
{:a => 1, :b => 1}.should include(:a => 1, :c => 1)
- }.should fail_with(%Q|expected {:a=>1, :b=>1} to include {:a=>1, :c=>1}|)
+ }.should fail_matching(%Q|expected {:a=>1, :b=>1} to include {:a=>1, :c=>1}|)
end
it "fails if target lacks both of the keys" do
- lambda {
+ begin
{:a => 1, :b => 1}.should include(:c => 1, :d => 1)
- }.should fail_with(%Q|expected {:a=>1, :b=>1} to include {:c=>1, :d=>1}|)
+ rescue Exception => e
+ ensure
+ e.message.should match(/expected \{:a=>1, :b=>1\} to include/)
+ e.message.match(/include (.*)$/) do |m|
+ eval(m[1]).should eq({:c=>1,:d=>1})
+ end
+ end
end
end
@@ -282,7 +288,7 @@
it "fails if the target does not contain the given hash" do
lambda {
['a', 'b'].should include(:a => 1, :b => 1)
- }.should fail_with(%q|expected ["a", "b"] to include {:a=>1, :b=>1}|)
+ }.should fail_matching(%Q|expected ["a", "b"] to include {:a=>1, :b=>1}|)
end
it "passes if the target contains the given hash" do
@@ -296,20 +302,20 @@
it "fails if target includes the key/value pairs" do
lambda {
{:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
- }.should fail_with(%Q|expected {:a=>1, :b=>2} not to include {:a=>1, :b=>2}|)
+ }.should fail_matching(%Q|expected {:a=>1, :b=>2} not to include {:a=>1, :b=>2}|)
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_with(%Q|expected #{hash.inspect} not to include {:a=>1, :b=>2}|)
+ }.should fail_matching(%Q|expected #{hash.inspect} not to include {:a=>1, :b=>2}|)
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_with(%Q|expected {:a=>1, :b=>2} not to include {:a=>2, :b=>2}|)
+ }.should fail_matching(%Q|expected {:a=>1, :b=>2} not to include {:a=>2, :b=>2}|)
end
it "passes if target has a different value for both of the keys" do
@@ -319,7 +325,7 @@
it "fails if target lacks one of the keys" do
lambda {
{:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
- }.should fail_with(%Q|expected {:a=>1, :b=>1} not to include {:a=>1, :c=>1}|)
+ }.should fail_matching(%Q|expected {:a=>1, :b=>1} not to include {:a=>1, :c=>1}|)
end
it "passes if target lacks both of the keys" do
@@ -335,7 +341,7 @@
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_with(%Q|expected ["a", {:a=>1, :b=>2}] not to include {:a=>1, :b=>2}|)
+ }.should fail_matching(%Q|expected ["a", {:a=>1, :b=>2}] not to include {:a=>1, :b=>2}|)
end
end
end
View
2  spec/rspec/matchers/operator_matcher_spec.rb
@@ -21,7 +21,7 @@
end
-describe "unsupported operators", :ruby => '1.9' do
+describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
it "raises an appropriate error for should != expected" do
expect {
"apple".should != "pear"
View
44 spec/spec_helper.rb
@@ -15,52 +15,10 @@ def add_to_load_path(path, prepend=false)
require 'rspec/core'
require 'rspec/mocks'
-Dir['./spec/support/**/*'].each do |f|
- require f
-end
-
-def with_ruby(version)
- yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
-end
-
-module RSpec
- module Ruby
- class << self
- def version
- RUBY_VERSION
- end
- end
- end
-end
-
-module RSpec
- module Matchers
- def fail
- raise_error(RSpec::Expectations::ExpectationNotMetError)
- end
-
- def fail_with(message)
- raise_error(RSpec::Expectations::ExpectationNotMetError, message)
- end
- end
-end
+Dir['./spec/support/**/*'].each {|f| require f}
RSpec::configure do |config|
- config.mock_with(:rspec)
- config.include RSpec::Mocks::Methods
config.color_enabled = true
config.filter_run :focused => true
-
- config.filter_run_excluding :ruby => lambda {|version|
- case version.to_s
- when "!jruby"
- RUBY_ENGINE != "jruby"
- when /^> (.*)/
- !(RUBY_VERSION.to_s > $1)
- else
- !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
- end
- }
-
config.run_all_when_everything_filtered = true
end
View
2  spec/support/classes.rb
@@ -1,4 +1,4 @@
-# This file contains various classes used by the specs.
+# various classes used by the specs
module RSpec
module Expectations
module Helper
View
22 spec/support/matchers.rb
@@ -0,0 +1,22 @@
+RSpec::Matchers.define :include_method do |expected|
+ match do |actual|
+ actual.map { |m| m.to_s }.include?(expected.to_s)
+ end
+end
+
+module RSpec
+ module Matchers
+ def fail
+ raise_error(RSpec::Expectations::ExpectationNotMetError)
+ end
+
+ def fail_with(message)
+ raise_error(RSpec::Expectations::ExpectationNotMetError, message)
+ end
+
+ def fail_matching(message)
+ raise_error(RSpec::Expectations::ExpectationNotMetError, /#{Regexp.escape(message)}/)
+ end
+ end
+end
+
View
10 spec/support/ruby_version.rb
@@ -0,0 +1,10 @@
+module RSpec
+ module Ruby
+ class << self
+ def version
+ RUBY_VERSION
+ end
+ end
+ end
+end
+

Showing you all comments on commits in this comparison.

@myronmarston

NIce to see the new :unless metadata being used :). But shouldn't this be :if instead? These specs only work on Ruby 1.9.

@dchelimsky
Owner

Right you are. Fixed in: 1f81b11

Something went wrong with that request. Please try again.