diff -Nru ruby-rspec-expectations-2.13.0/Changelog.md ruby-rspec-expectations-2.14.2/Changelog.md --- ruby-rspec-expectations-2.13.0/Changelog.md 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/Changelog.md 2013-08-15 17:28:02.000000000 +0000 @@ -1,3 +1,74 @@ +### 2.14.2 / 2013-08-14 +[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2) + +Bug fixes + +* Fix `be_` matcher to not support operator chaining like the + `be` matcher does (e.g. `be == 5`). This led to some odd behaviors + since `be_ == anything` returned a `BeComparedTo` matcher + and was thus always truthy. This was a consequence of the implementation + (e.g. subclassing the basic `Be` matcher) and was not intended behavior. + (Myron Marston). +* Fix `change` matcher to compare using `==` in addition to `===`. This + is important for an expression like: + `expect {}.to change { a.class }.from(ClassA).to(ClassB)` because + `SomeClass === SomeClass` returns false. (Myron Marston) + +### 2.14.1 / 2013-08-08 +[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0...2.14.1) + +Bug fixes + +* Ensure diff output uses the same encoding as the encoding of + the string being diff'd to prevent `Encoding::UndefinedConversionError` + errors (Jon Rowe). + +### 2.14.0 / 2013-07-06 +[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0.rc1...v2.14.0) + +Bug fixes + +* Values that are not matchers use `#inspect`, rather than `#description` for + documentation output (Andy Lindeman, Sam Phippen). +* Make `expect(a).to be_within(x).percent_of(y)` work with negative y + (Katsuhiko Nishimra). +* Make the `be_predicate` matcher work as expected used with `expect{...}.to + change...` (Sam Phippen). + +### 2.14.0.rc1 / 2013-05-27 +[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.13.0...v2.14.0.rc1) + +Enhancements + +* Enhance `yield_control` so that you can specify an exact or relative + number of times: `expect { }.to yield_control.exactly(3).times`, + `expect { }.to yield_control.at_least(2).times`, etc (Bartek + Borkowski). +* Make the differ that is used when an expectation fails better handle arrays + by splitting each element of the array onto its own line. (Sam Phippen) +* Accept duck-typed strings that respond to `:to_str` as expectation messages. + (Toby Ovod-Everett) + +Bug fixes + +* Fix differ to not raise errors when dealing with differently-encoded + strings (Jon Rowe). +* Fix `expect(something).to be_within(x).percent_of(y)` where x and y are both + integers (Sam Phippen). +* Fix `have` matcher to handle the fact that on ruby 2.0, + `Enumerator#size` may return nil (Kenta Murata). +* Fix `expect { raise s }.to raise_error(s)` where s is an error instance + on ruby 2.0 (Sam Phippen). +* Fix `expect(object).to raise_error` passing. This now warns the user and + fails the spec (tomykaira). + +Deprecations + +* Deprecate `expect { }.not_to raise_error(SpecificErrorClass)` or + `expect { }.not_to raise_error("some specific message")`. Using + these was prone to hiding failures as they would allow _any other + error_ to pass. (Sam Phippen and David Chelimsky) + ### 2.13.0 / 2013-02-23 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.1...v2.13.0) diff -Nru ruby-rspec-expectations-2.13.0/README.md ruby-rspec-expectations-2.14.2/README.md --- ruby-rspec-expectations-2.13.0/README.md 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/README.md 2013-08-15 17:28:02.000000000 +0000 @@ -3,7 +3,7 @@ RSpec::Expectations lets you express expected outcomes on an object in an example. - account.balance.should eq(Money.new(37.42, :USD)) + expect(account.balance).to eq(Money.new(37.42, :USD)) ## Install @@ -38,8 +38,7 @@ end ``` -The `describe` and `it` methods come from rspec-core. The `Order`, `LineItem`, -and `Item` classes would be from _your_ code. The last line of the example +The `describe` and `it` methods come from rspec-core. The `Order`, `LineItem`, `Item` and `Money` classes would be from _your_ code. The last line of the example expresses an expected outcome. If `order.total == Money.new(5.55, :USD)`, then the example passes. If not, it fails with a message like: @@ -51,52 +50,50 @@ ### Equivalence ```ruby -actual.should eq(expected) # passes if actual == expected -actual.should == expected # passes if actual == expected -actual.should eql(expected) # passes if actual.eql?(expected) +expect(actual).to eq(expected) # passes if actual == expected +expect(actual).to eql(expected) # passes if actual.eql?(expected) ``` -Note: we recommend the `eq` matcher over `==` to avoid Ruby's "== in a -useless context" warning when the `==` matcher is used anywhere but the -last statement of an example. +Note: The new `expect` syntax no longer supports `==` matcher. ### Identity ```ruby -actual.should be(expected) # passes if actual.equal?(expected) -actual.should equal(expected) # passes if actual.equal?(expected) +expect(actual).to be(expected) # passes if actual.equal?(expected) +expect(actual).to equal(expected) # passes if actual.equal?(expected) ``` ### Comparisons ```ruby -actual.should be > expected -actual.should be >= expected -actual.should be <= expected -actual.should be < expected -actual.should be_within(delta).of(expected) +expect(actual).to be > expected +expect(actual).to be >= expected +expect(actual).to be <= expected +expect(actual).to be < expected +expect(actual).to be_within(delta).of(expected) ``` ### Regular expressions ```ruby -actual.should match(/expression/) -actual.should =~ /expression/ +expect(actual).to match(/expression/) ``` +Note: The new `expect` syntax no longer supports `=~` matcher. + ### Types/classes ```ruby -actual.should be_an_instance_of(expected) -actual.should be_a_kind_of(expected) +expect(actual).to be_an_instance_of(expected) +expect(actual).to be_a_kind_of(expected) ``` ### Truthiness ```ruby -actual.should be_true # passes if actual is truthy (not nil or false) -actual.should be_false # passes if actual is falsy (nil or false) -actual.should be_nil # passes if actual is nil +expect(actual).to be_true # passes if actual is truthy (not nil or false) +expect(actual).to be_false # passes if actual is falsy (nil or false) +expect(actual).to be_nil # passes if actual is nil ``` ### Expecting errors @@ -134,92 +131,51 @@ ### Predicate matchers ```ruby -actual.should be_xxx # passes if actual.xxx? -actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg) +expect(actual).to be_xxx # passes if actual.xxx? +expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg) ``` ### Ranges (Ruby >= 1.9 only) ```ruby -(1..10).should cover(3) +expect(1..10).to cover(3) ``` ### Collection membership ```ruby -actual.should include(expected) -actual.should start_with(expected) -actual.should end_with(expected) +expect(actual).to include(expected) +expect(actual).to start_with(expected) +expect(actual).to end_with(expected) ``` #### Examples ```ruby -[1,2,3].should include(1) -[1,2,3].should include(1, 2) -[1,2,3].should start_with(1) -[1,2,3].should start_with(1,2) -[1,2,3].should end_with(3) -[1,2,3].should end_with(2,3) -{:a => 'b'}.should include(:a => 'b') -"this string".should include("is str") -"this string".should start_with("this") -"this string".should end_with("ring") +expect([1,2,3]).to include(1) +expect([1,2,3]).to include(1, 2) +expect([1,2,3]).to start_with(1) +expect([1,2,3]).to start_with(1,2) +expect([1,2,3]).to end_with(3) +expect([1,2,3]).to end_with(2,3) +expect({:a => 'b'}).to include(:a => 'b') +expect("this string").to include("is str") +expect("this string").to start_with("this") +expect("this string").to end_with("ring") ``` -## `expect` syntax - -In addition to the `should` syntax, rspec-expectations supports -a new `expect` syntax as of version 2.11.0: - -```ruby -expect(actual).to eq expected -expect(actual).to be > 3 -expect([1, 2, 3]).to_not include 4 -``` +## `should` syntax -If you want your project to only use one of these syntaxes, you can -configure it: +In addition to the `expect` syntax, rspec-expectations continues to support the +`should` syntax: ```ruby -RSpec.configure do |config| - config.expect_with :rspec do |c| - c.syntax = :expect - # or - c.syntax = :should - # or - c.syntax = [:should, :expect] - end -end +actual.should eq expected +actual.should be > 3 +[1, 2, 3].should_not include 4 ``` -See -[RSpec::Expectations::Syntax#expect](http://rubydoc.info/gems/rspec-expectations/RSpec/Expectations/Syntax:expect) -for more information. - -### Motivation for `expect` - -We added the `expect` syntax to resolve some edge case issues, most notably -that objects whose definitions wipe out all but a few methods were throwing -`should` and `should_not` away. `expect` solves that by not monkey patching -those methods onto `Kernel` (or any global object). - -See -[http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax) -for a detailed explanation. - -### One-liners - -The one-liner syntax supported by -[rspec-core](http://rubydoc.info/gems/rspec-core) uses `should` even when -`config.syntax = :expect`. It reads better than the alternative, and does not -require a global monkey patch: - -```ruby -describe User do - it { should validate_presence_of :email } -end -``` +See [detailed information on the `should` syntax and its usage.](https://github.com/rspec/rspec-expectations/blob/master/Should.md) ## Also see diff -Nru ruby-rspec-expectations-2.13.0/debian/changelog ruby-rspec-expectations-2.14.2/debian/changelog --- ruby-rspec-expectations-2.13.0/debian/changelog 2013-07-02 05:44:24.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/debian/changelog 2013-08-15 18:36:38.000000000 +0000 @@ -1,3 +1,11 @@ +ruby-rspec-expectations (2.14.2-1) unstable; urgency=low + + * Imported Upstream version 2.14.2 + * force external encoding in specs with Ruby >= 1.9 + * bump rspec-* version in dependencies + + -- Cédric Boutillier Thu, 15 Aug 2013 19:29:04 +0200 + ruby-rspec-expectations (2.13.0-3) unstable; urgency=low * Replace ruby1.8 by ruby in Depends field. diff -Nru ruby-rspec-expectations-2.13.0/debian/control ruby-rspec-expectations-2.14.2/debian/control --- ruby-rspec-expectations-2.13.0/debian/control 2013-07-02 05:44:24.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/debian/control 2013-08-15 18:13:32.000000000 +0000 @@ -3,7 +3,7 @@ Priority: optional Maintainer: Debian Ruby Extras Maintainers Uploaders: Lucas Nussbaum , Cédric Boutillier -Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.3.0~), ruby-rspec-mocks (>= 2.13~), ruby-rspec-core (>= 2.13~), ruby-diff-lcs, rake +Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.3.0~), ruby-rspec-mocks (>= 2.14~), ruby-rspec-core (>= 2.14~), ruby-diff-lcs, rake Standards-Version: 3.9.4 Vcs-Git: git://anonscm.debian.org/pkg-ruby-extras/ruby-rspec-expectations.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-ruby-extras/ruby-rspec-expectations.git diff -Nru ruby-rspec-expectations-2.13.0/debian/patches/fix_encoding.patch ruby-rspec-expectations-2.14.2/debian/patches/fix_encoding.patch --- ruby-rspec-expectations-2.13.0/debian/patches/fix_encoding.patch 1970-01-01 00:00:00.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/debian/patches/fix_encoding.patch 2013-08-15 18:34:33.000000000 +0000 @@ -0,0 +1,18 @@ +Description: force default external encoding to UTF-8 + This is required to make specs relying on Unicode characters to pass + in building environment with C locale. +Origin: vendor +Author: Cédric Boutillier +Forwarded: not-needed +Last-Update: 2013-08-15 + +--- a/spec/rspec/expectations/differ_spec.rb ++++ b/spec/rspec/expectations/differ_spec.rb +@@ -1,4 +1,7 @@ + # encoding: utf-8 ++ ++Encoding.default_external="UTF-8" if defined? Encoding ++ + require 'spec_helper' + require 'ostruct' + diff -Nru ruby-rspec-expectations-2.13.0/debian/patches/series ruby-rspec-expectations-2.14.2/debian/patches/series --- ruby-rspec-expectations-2.13.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/debian/patches/series 2013-08-15 18:32:08.000000000 +0000 @@ -0,0 +1 @@ +fix_encoding.patch diff -Nru ruby-rspec-expectations-2.13.0/features/README.md ruby-rspec-expectations-2.14.2/features/README.md --- ruby-rspec-expectations-2.13.0/features/README.md 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/README.md 2013-08-15 17:28:02.000000000 +0000 @@ -2,7 +2,7 @@ describe Account do it "has a balance of zero when first created" do - Account.new.balance.should eq(Money.new(0)) + expect(Account.new.balance).to eq(Money.new(0)) end end @@ -10,17 +10,16 @@ The basic structure of an rspec expectation is: - actual.should matcher(expected) - actual.should_not matcher(expected) + expect(actual).to matcher(expected) + expect(actual).not_to matcher(expected) -## `should` and `should_not` +Note: You can also use `expect(..).to_not` instead of `expect(..).not_to`. + One is an alias to the other, so you can use whichever reads better to you. -`rspec-expectations` adds `should` and `should_not` to every object in -the system. These methods each accept a matcher as an argument. This allows -each matcher to work in a positive or negative mode: +#### Examples - 5.should eq(5) - 5.should_not eq(4) + expect(5).to eq(5) + expect(5).not_to eq(4) ## What is a matcher? diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/README.md ruby-rspec-expectations-2.14.2/features/built_in_matchers/README.md --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/README.md 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/README.md 2013-08-15 17:28:02.000000000 +0000 @@ -1,55 +1,55 @@ # Built-in Matchers -Here is a list of matchers that ship with rspec-expectations. Each matcher -can be used with `should` or `should_not` e.g. - - result.should eq(3) - list.should_not be_empty +rspec-expectations ships with a number of built-in matchers. +Each matcher can be used with `expect(..).to` or `expect(..).not_to` to define +positive and negative expectations respectively on an object. Most matchers can +also be accessed using the `(...).should` and `(...).should_not` syntax, see +[using should syntax](https://github.com/rspec/rspec-expectations/blob/master/Should.md) +for why we recommend using `expect`. + +e.g. + + expect(result).to eq(3) + expect(list).not_to be_empty + pi.should be > 3 ## Object identity - actual.should be(expected) # passes if actual.equal?(expected) - + expect(actual).to be(expected) # passes if actual.equal?(expected) + ## Object equivalence - actual.should eq(expected) # passes if actual == expected + expect(actual).to eq(expected) # passes if actual == expected ## Optional APIs for identity/equivalence - actual.should == expected # passes if actual == expected - actual.should eql(expected) # passes if actual.eql?(expected) - actual.should equal(expected) # passes if actual.equal?(expected) - - # NOTE: this can't work in Ruby 1.8, so we don't support it at all: - # actual.should != expected - # The reason is that Ruby 1.8 parses it as: - # !(actual.should.==(expected)), - # so by the time RSpec sees it it has no way to know that it's - # been negated. Use either of these instead: - # actual.should_not eq(expected) - # actual.should_not == expected + expect(actual).to eql(expected) # passes if actual.eql?(expected) + expect(actual).to equal(expected) # passes if actual.equal?(expected) + + # NOTE: `expect` does not support `==` matcher. ## Comparisons - actual.should be > expected - actual.should be >= expected - actual.should be <= expected - actual.should be < expected - actual.should =~ /expression/ - actual.should match(/expression/) - actual.should be_within(delta).of(expected) + expect(actual).to be > expected + expect(actual).to be >= expected + expect(actual).to be <= expected + expect(actual).to be < expected + expect(actual).to match(/expression/) + expect(actual).to be_within(delta).of(expected) + + # NOTE: `expect` does not support `=~` matcher. ## Types/classes - actual.should be_instance_of(expected) - actual.should be_kind_of(expected) + expect(actual).to be_instance_of(expected) + expect(actual).to be_kind_of(expected) ## Truthiness and existentialism - actual.should be_true # passes if actual is truthy (not nil or false) - actual.should be_false # passes if actual is falsy (nil or false) - actual.should be_nil # passes if actual is nil - actual.should be # passes if actual is truthy (not nil or false) + expect(actual).to be_true # passes if actual is truthy (not nil or false) + expect(actual).to be_false # passes if actual is falsy (nil or false) + expect(actual).to be_nil # passes if actual is nil + expect(actual).to be # passes if actual is truthy (not nil or false) ## Expecting errors @@ -66,25 +66,25 @@ ## Predicate matchers - actual.should be_xxx # passes if actual.xxx? - actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg) + expect(actual).to be_xxx # passes if actual.xxx? + expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg) ### Examples - [].should be_empty # passes because [].empty? returns true - { :a => 1 }.should have_key(:a) # passes because the hash has the key :a + expect([]).to be_empty + expect(:a => 1).to have_key(:a) ## Collection membership - actual.should include(expected) + expect(actual).to include(expected) ### Examples - [1,2,3].should include(1) - [1,2,3].should include(1, 2) - {:a => 'b'}.should include(:a => 'b') - "this string".should include("is str") + expect([1,2,3]).to include(1) + expect([1,2,3]).to include(1, 2) + expect(:a => 'b').to include(:a => 'b') + expect("this string").to include("is str") ## Ranges (1.9 only) - (1..10).should cover(3) + expect(1..10).to cover(3) diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/be_within.feature ruby-rspec-expectations-2.14.2/features/built_in_matchers/be_within.feature --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/be_within.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/be_within.feature 2013-08-15 17:28:02.000000000 +0000 @@ -4,11 +4,11 @@ Consider this irb session: > radius = 3 - => 3 + => 3 > area_of_circle = radius * radius * Math::PI - => 28.2743338823081 + => 28.2743338823081 > area_of_circle == 28.2743338823081 - => false + => false Instead, you should use the be_within matcher to check that the value is within a delta of your expected value: diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/expect_change.feature ruby-rspec-expectations-2.14.2/features/built_in_matchers/expect_change.feature --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/expect_change.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/expect_change.feature 2013-08-15 17:28:02.000000000 +0000 @@ -11,14 +11,14 @@ @count ||= 0 @count += 1 end - + def count @count ||= 0 end end end """ - + Scenario: expect change Given a file named "spec/example_spec.rb" with: """ruby @@ -45,13 +45,13 @@ require "counter" describe Counter, "#increment" do - it "should not increment the count by 1 (using to_not)" do - expect { Counter.increment }.to_not change{Counter.count} - end - it "should not increment the count by 1 (using not_to)" do expect { Counter.increment }.not_to change{Counter.count} end + + it "should not increment the count by 1 (using to_not)" do + expect { Counter.increment }.to_not change{Counter.count} + end end """ When I run `rspec spec/example_spec.rb` diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/expect_error.feature ruby-rspec-expectations-2.14.2/features/built_in_matchers/expect_error.feature --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/expect_error.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/expect_error.feature 2013-08-15 17:28:02.000000000 +0000 @@ -124,7 +124,7 @@ describe Object, "#public_instance_methods" do it "does not raise" do expect { Object.public_instance_methods }. - to_not raise_error(NameError) + not_to raise_error(NameError) end end """ @@ -136,7 +136,7 @@ """ describe "#to_s" do it "does not raise" do - expect { Object.new.to_s }.to_not raise_error + expect { Object.new.to_s }.not_to raise_error end end """ diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/start_with.feature ruby-rspec-expectations-2.14.2/features/built_in_matchers/start_with.feature --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/start_with.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/start_with.feature 2013-08-15 17:28:02.000000000 +0000 @@ -1,6 +1,6 @@ Feature: start_with matcher - Use the `start_with` matcher to specify that a string or array starts with + Use the `start_with` matcher to specify that a string or array starts with the expected characters or elements. ```ruby diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/throw_symbol.feature ruby-rspec-expectations-2.14.2/features/built_in_matchers/throw_symbol.feature --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/throw_symbol.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/throw_symbol.feature 2013-08-15 17:28:02.000000000 +0000 @@ -26,11 +26,11 @@ describe "throw" do specify { expect { throw :foo }.to throw_symbol } specify { expect { throw :bar, 7 }.to throw_symbol } - specify { expect { 5 + 5 }.to_not throw_symbol } + specify { expect { 5 + 5 }.not_to throw_symbol } # deliberate failures - specify { expect { throw :foo }.to_not throw_symbol } - specify { expect { throw :bar, 7 }.to_not throw_symbol } + specify { expect { throw :foo }.not_to throw_symbol } + specify { expect { throw :bar, 7 }.not_to throw_symbol } specify { expect { 5 + 5 }.to throw_symbol } end """ @@ -47,12 +47,12 @@ describe "throw symbol" do specify { expect { throw :foo }.to throw_symbol(:foo) } specify { expect { throw :foo, 7 }.to throw_symbol(:foo) } - specify { expect { 5 + 5 }.to_not throw_symbol(:foo) } - specify { expect { throw :bar }.to_not throw_symbol(:foo) } + specify { expect { 5 + 5 }.not_to throw_symbol(:foo) } + specify { expect { throw :bar }.not_to throw_symbol(:foo) } # deliberate failures - specify { expect { throw :foo }.to_not throw_symbol(:foo) } - specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo) } + specify { expect { throw :foo }.not_to throw_symbol(:foo) } + specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo) } specify { expect { 5 + 5 }.to throw_symbol(:foo) } specify { expect { throw :bar }.to throw_symbol(:foo) } end @@ -70,12 +70,12 @@ """ruby describe "throw symbol with argument" do specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) } - specify { expect { throw :foo, 8 }.to_not throw_symbol(:foo, 7) } - specify { expect { throw :bar, 7 }.to_not throw_symbol(:foo, 7) } - specify { expect { throw :foo }.to_not throw_symbol(:foo, 7) } + specify { expect { throw :foo, 8 }.not_to throw_symbol(:foo, 7) } + specify { expect { throw :bar, 7 }.not_to throw_symbol(:foo, 7) } + specify { expect { throw :foo }.not_to throw_symbol(:foo, 7) } # deliberate failures - specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo, 7) } + specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo, 7) } specify { expect { throw :foo, 8 }.to throw_symbol(:foo, 7) } specify { expect { throw :bar, 7 }.to throw_symbol(:foo, 7) } specify { expect { throw :foo }.to throw_symbol(:foo, 7) } diff -Nru ruby-rspec-expectations-2.13.0/features/built_in_matchers/yield.feature ruby-rspec-expectations-2.14.2/features/built_in_matchers/yield.feature --- ruby-rspec-expectations-2.13.0/features/built_in_matchers/yield.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/built_in_matchers/yield.feature 2013-08-15 17:28:02.000000000 +0000 @@ -30,6 +30,10 @@ yield *args end + def self.yield_twice_with(*args) + 2.times { yield *args } + end + def self.raw_yield yield end @@ -47,17 +51,28 @@ describe "yield_control matcher" do specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control } specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_control } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.twice } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.exactly(2).times } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.at_least(1) } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.at_most(3).times } # deliberate failures specify { expect { |b| MyClass.yield_once_with(1, &b) }.not_to yield_control } specify { expect { |b| MyClass.dont_yield(&b) }.to yield_control } + specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control.at_least(2).times } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.twice } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_least(2).times } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_least(1) } + specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_most(3).times } end """ When I run `rspec yield_control_spec.rb` Then the output should contain all of these: - | 4 examples, 2 failures | - | expected given block to yield control | - | expected given block not to yield control | + | 13 examples, 7 failures | + | expected given block to yield control | + | expected given block not to yield control | + | expected given block not to yield control at least twice | + | expected given block not to yield control at most 3 times | Scenario: yield_with_args matcher Given a file named "yield_with_args_spec.rb" with: diff -Nru ruby-rspec-expectations-2.13.0/features/custom_matchers/define_diffable_matcher.feature ruby-rspec-expectations-2.14.2/features/custom_matchers/define_diffable_matcher.feature --- ruby-rspec-expectations-2.13.0/features/custom_matchers/define_diffable_matcher.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/custom_matchers/define_diffable_matcher.feature 2013-08-15 17:28:02.000000000 +0000 @@ -12,7 +12,7 @@ match do |actual| actual == expected end - + diffable end diff -Nru ruby-rspec-expectations-2.13.0/features/custom_matchers/define_matcher_outside_rspec.feature ruby-rspec-expectations-2.14.2/features/custom_matchers/define_matcher_outside_rspec.feature --- ruby-rspec-expectations-2.13.0/features/custom_matchers/define_matcher_outside_rspec.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/custom_matchers/define_matcher_outside_rspec.feature 2013-08-15 17:28:02.000000000 +0000 @@ -9,19 +9,19 @@ """ruby require "rspec/expectations" require "test/unit" - + RSpec::Matchers.define :be_a_multiple_of do |expected| match do |actual| actual % expected == 0 end end - + class Test::Unit::TestCase include RSpec::Matchers end - + class TestMultiples < Test::Unit::TestCase - + def test_9_should_be_a_multiple_of_3 9.should be_a_multiple_of(3) end @@ -29,10 +29,10 @@ def test_9_should_be_a_multiple_of_4 9.should be_a_multiple_of(4) end - + end """ When I run `ruby test_multiples.rb` - Then the exit status should not be 0 + Then the exit status should not be 0 And the output should contain "expected 9 to be a multiple of 4" And the output should contain "2 tests, 0 assertions, 0 failures, 1 errors" diff -Nru ruby-rspec-expectations-2.13.0/features/custom_matchers/define_matcher_with_fluent_interface.feature ruby-rspec-expectations-2.14.2/features/custom_matchers/define_matcher_with_fluent_interface.feature --- ruby-rspec-expectations-2.13.0/features/custom_matchers/define_matcher_with_fluent_interface.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/custom_matchers/define_matcher_with_fluent_interface.feature 2013-08-15 17:28:02.000000000 +0000 @@ -1,7 +1,7 @@ Feature: define matcher with fluent interface Use the chain() method to define matchers with a fluent interface. - + Scenario: chained method with argumetn Given a file named "between_spec.rb" with: """ruby diff -Nru ruby-rspec-expectations-2.13.0/features/customized_message.feature ruby-rspec-expectations-2.14.2/features/customized_message.feature --- ruby-rspec-expectations-2.13.0/features/customized_message.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/customized_message.feature 2013-08-15 17:28:02.000000000 +0000 @@ -3,7 +3,7 @@ RSpec tries to provide useful failure messages, but for cases in which you want more specific information, you can define your own message right in the example. This works for any matcher _other than the operator matchers_. - + Scenario: customize failure message Given a file named "example_spec.rb" with: """ruby diff -Nru ruby-rspec-expectations-2.13.0/features/support/env.rb ruby-rspec-expectations-2.14.2/features/support/env.rb --- ruby-rspec-expectations-2.13.0/features/support/env.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/support/env.rb 2013-08-15 17:28:02.000000000 +0000 @@ -1,5 +1,14 @@ require 'aruba/cucumber' +timeouts = { 'java' => 60 } + Before do - @aruba_timeout_seconds = 15 + @aruba_timeout_seconds = timeouts.fetch(RUBY_PLATFORM) { 15 } end + +Aruba.configure do |config| + config.before_cmd do |cmd| + set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived + end +end if RUBY_PLATFORM == 'java' + diff -Nru ruby-rspec-expectations-2.13.0/features/support/rubinius.rb ruby-rspec-expectations-2.14.2/features/support/rubinius.rb --- ruby-rspec-expectations-2.13.0/features/support/rubinius.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/support/rubinius.rb 2013-08-15 17:28:02.000000000 +0000 @@ -0,0 +1,6 @@ +# Required until https://github.com/rubinius/rubinius/issues/2430 is resolved +ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc" + +Around "@unsupported-on-rbx" do |scenario, block| + block.call unless defined?(Rubinius) +end diff -Nru ruby-rspec-expectations-2.13.0/features/syntax_configuration.feature ruby-rspec-expectations-2.14.2/features/syntax_configuration.feature --- ruby-rspec-expectations-2.13.0/features/syntax_configuration.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/syntax_configuration.feature 2013-08-15 17:28:02.000000000 +0000 @@ -47,6 +47,9 @@ config.expect_with :rspec do |c| c.syntax = :should end + config.mock_with :rspec do |c| + c.syntax = :should + end end """ When I run `rspec disable_expect_syntax.rb syntaxes_spec.rb` diff -Nru ruby-rspec-expectations-2.13.0/features/test_frameworks/test_unit.feature ruby-rspec-expectations-2.14.2/features/test_frameworks/test_unit.feature --- ruby-rspec-expectations-2.13.0/features/test_frameworks/test_unit.feature 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/features/test_frameworks/test_unit.feature 2013-08-15 17:28:02.000000000 +0000 @@ -1,11 +1,12 @@ Feature: Test::Unit integration - RSpec-expectations is a stand-alone gem that can be used without - the rest of RSpec. It can easily be used with another test - framework such as Test::Unit if you like RSpec's should/should_not - syntax but prefer the test organization of another framework. + RSpec-expectations is a stand-alone gem that can be used without the rest of + RSpec. If you like the way Test::Unit (or MiniTest) organizes tests, but + prefer RSpec's approach to expressing expectations, you can have both. - Scenario: Basic Test::Unit usage + The one downside is that failures are reported as errors with MiniTest. + + Scenario: use rspec/expectations with Test::Unit Given a file named "rspec_expectations_test.rb" with: """ruby require 'test/unit' @@ -17,30 +18,27 @@ end def be_an_int - RSpec.deprecate(:be_an_int, :be_an_integer) + # This is actually an internal rspec-expectations API, but is used + # here to demonstrate that deprecation warnings from within + # rspec-expectations work correcty without depending on rspec-core + RSpec.deprecate(:be_an_int, :replacement => :be_an_integer) be_an_integer end def test_passing_expectation - x = 1 + 3 - x.should == 4 + expect(1 + 3).to eq 4 end def test_failing_expectation - array = [1, 2] - array.should be_empty - end - - def test_expect_matcher - expect { @a = 5 }.to change { @a }.from(nil).to(5) + expect([1,2]).to be_empty end - def test_custom_matcher_and_deprecation_warning - 1.should be_an_int + def test_custom_matcher_with_deprecation_warning + expect(1).to be_an_int end end """ When I run `ruby rspec_expectations_test.rb` - Then the output should contain "4 tests, 0 assertions, 1 failures, 0 errors" or "4 tests, 0 assertions, 0 failures, 1 errors" + Then the output should contain "3 tests, 0 assertions, 0 failures, 1 errors" or "3 tests, 0 assertions, 1 failures, 0 errors" And the output should contain "expected empty? to return true, got false" And the output should contain "be_an_int is deprecated" diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/deprecation.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/deprecation.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/deprecation.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/deprecation.rb 2013-08-15 17:28:02.000000000 +0000 @@ -1,38 +1,17 @@ module RSpec - unless respond_to?(:deprecate) - class << self - # Used internally by RSpec to display standard deprecation warnings. - # This is also defined in rspec-core, but we can't assume it's loaded - # since rspec-expectations should be usable w/o rspec-core. - def deprecate(method, alternate_method=nil, version=nil) - version_string = version ? "rspec-#{version}" : "a future version of RSpec" - - message = <<-NOTICE - -***************************************************************** -DEPRECATION WARNING: you are using deprecated behaviour that will -be removed from #{version_string}. - -#{caller(0)[2]} - -* #{method} is deprecated. -NOTICE - if alternate_method - message << <<-ADDITIONAL -* please use #{alternate_method} instead. -ADDITIONAL - end - - message << "*****************************************************************" - warn_deprecation(message) - end - - # Used internally by RSpec to display custom deprecation warnings. This - # is also defined in rspec-core, but we can't assume it's loaded since - # rspec-expectations should be usable w/o rspec-core. - def warn_deprecation(message) - warn(message) + module Expectations + module Deprecation + # @private + # + # Used internally to print deprecation warnings + def deprecate(deprecated, options={}) + message = "DEPRECATION: #{deprecated} is deprecated." + message << " Use #{options[:replacement]} instead." if options[:replacement] + message << " Called from #{caller(0)[2]}." + warn message end end end + + extend(Expectations::Deprecation) unless respond_to?(:deprecate) end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/differ.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/differ.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/differ.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/differ.rb 2013-08-15 17:28:02.000000000 +0000 @@ -6,11 +6,11 @@ module Expectations class Differ # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool) - def diff_as_string(data_new, data_old) - data_old = data_old.split(/\n/).map! { |e| e.chomp } - data_new = data_new.split(/\n/).map! { |e| e.chomp } + def diff_as_string(input_data_new, input_data_old) + output = matching_encoding("", input_data_old) + data_old = input_data_old.split(matching_encoding("\n", input_data_old)).map! { |e| e.chomp } + data_new = input_data_new.split(matching_encoding("\n", input_data_new)).map! { |e| e.chomp } diffs = Diff::LCS.diff(data_old, data_new) - output = "" return output if diffs.empty? oldhunk = hunk = nil file_length_difference = 0 @@ -33,16 +33,24 @@ hunk.unshift(oldhunk) end else - output << oldhunk.diff(format) + output << matching_encoding(oldhunk.diff(format).to_s, output) end ensure oldhunk = hunk - output << "\n" + output << matching_encoding("\n", output) end end #Handle the last remaining hunk - output << oldhunk.diff(format) << "\n" + output << matching_encoding(oldhunk.diff(format).to_s,output) + output << matching_encoding("\n",output) color_diff output + rescue Encoding::CompatibilityError + if input_data_new.encoding != input_data_old.encoding + "Could not produce a diff because the encoding of the actual string (#{input_data_old.encoding}) "+ + "differs from the encoding of the expected string (#{input_data_new.encoding})" + else + "Could not produce a diff because of the encoding of the string (#{input_data_old.encoding})" + end end def diff_as_object(actual, expected) @@ -99,8 +107,15 @@ 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], "")}) + object.keys.sort_by { |k| k.to_s }.map do |key| + pp_key = PP.singleline_pp(key, "") + pp_value = PP.singleline_pp(object[key], "") + + # on 1.9.3 PP seems to minimise to US-ASCII, ensure we're matching source encoding + # + # note, PP is used to ensure the ordering of the internal values of key/value e.g. + # <# a: b: c:> not <# c: a: b:> + matching_encoding("#{pp_key} => #{pp_value}", key) end.join(",\n") when String object =~ /\n/ ? object : object.inspect @@ -108,6 +123,16 @@ PP.pp(object,"") end end + + if String.method_defined?(:encoding) + def matching_encoding(string, source) + string.encode(source.encoding) + end + else + def matching_encoding(string, source) + string + end + end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/expectation_target.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/expectation_target.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/expectation_target.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/expectation_target.rb 2013-08-15 17:28:02.000000000 +0000 @@ -7,8 +7,8 @@ # # used with `to` # expect(actual).to eq(3) # - # # with `to_not` - # expect(actual).to_not eq(3) + # # with `not_to` + # expect(actual).not_to eq(3) class ExpectationTarget class << self attr_accessor :deprecated_should_enabled @@ -36,29 +36,28 @@ # Runs the given expectation, passing if `matcher` returns false. # @example - # expect(value).to_not eq(5) # expect(value).not_to eq(5) # @param [Matcher] # matcher # @param [String] message optional message to display when the expectation fails # @return [Boolean] false if the negative expectation succeeds (else raises) # @see RSpec::Matchers - def to_not(matcher=nil, message=nil, &block) - prevent_operator_matchers(:to_not, matcher) + def not_to(matcher=nil, message=nil, &block) + prevent_operator_matchers(:not_to, matcher) RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, message, &block) end - alias not_to to_not + alias to_not not_to def self.enable_deprecated_should return if deprecated_should_enabled? def should(*args) - RSpec.deprecate "`expect { }.should`", "`expect { }.to`", 3 + RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`" @target.should(*args) end def should_not(*args) - RSpec.deprecate "`expect { }.should_not`", "`expect { }.to_not`", 3 + RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`" @target.should_not(*args) end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/extensions/object.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/extensions/object.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/extensions/object.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/extensions/object.rb 2013-08-15 17:28:02.000000000 +0000 @@ -6,17 +6,7 @@ def const_missing(name) case name when :Rspec, :Spec - RSpec.warn_deprecation <<-WARNING -***************************************************************** -DEPRECATION WARNING: you are using a deprecated constant that will -be removed from a future version of RSpec. - -#{caller(0)[2]} - -* #{name} is deprecated. -* RSpec is the new top-level module in RSpec-2 -*************************************************************** -WARNING + RSpec.deprecate(name.to_s, :replacement => "RSpec") RSpec else begin @@ -31,7 +21,7 @@ # @deprecated (no replacement) def differ=(ignore) - RSpec.deprecate("RSpec::Expectations.differ=(differ)", "nothing at all (diffing is now automatic and no longer configurable)") + RSpec.deprecate("RSpec::Expectations.differ=(differ)") end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/fail_with.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/fail_with.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/fail_with.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/fail_with.rb 2013-08-15 17:28:02.000000000 +0000 @@ -52,7 +52,17 @@ def coerce_to_string(string_or_array) return string_or_array unless Array === string_or_array - string_or_array.join(',') + diffably_stringify(string_or_array).join("\n") + end + + def diffably_stringify(array) + array.map do |entry| + if Array === entry + entry.inspect + else + entry.to_s.gsub("\n", "\\n") + end + end end if String.method_defined?(:encoding) diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/handler.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/handler.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/handler.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/handler.rb 2013-08-15 17:28:02.000000000 +0000 @@ -2,13 +2,14 @@ module Expectations class ExpectationHandler - def self.message_must_be_string(msg) - "WARNING: ignoring the provided expectation message argument " + - "(#{msg.inspect}) since it is not a string." - end - def self.check_message(msg) - ::Kernel.warn message_must_be_string(msg) unless msg.nil? || msg.is_a?(String) + unless msg.nil? || msg.respond_to?(:to_str) || msg.respond_to?(:call) + ::Kernel.warn [ + "WARNING: ignoring the provided expectation message argument (", + msg.inspect, + ") since it is not a string or a proc." + ].join + end end end @@ -23,6 +24,8 @@ match = matcher.matches?(actual, &block) return match if match + message = message.call if message.respond_to?(:call) + message ||= matcher.respond_to?(:failure_message_for_should) ? matcher.failure_message_for_should : matcher.failure_message @@ -47,6 +50,8 @@ matcher.matches?(actual, &block) return match unless match + message = message.call if message.respond_to?(:call) + message ||= matcher.respond_to?(:failure_message_for_should_not) ? matcher.failure_message_for_should_not : matcher.negative_failure_message diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/syntax.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/syntax.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/syntax.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/syntax.rb 2013-08-15 17:28:02.000000000 +0000 @@ -32,10 +32,10 @@ # `ExpectationTarget`. # @example # expect(actual).to eq(expected) - # expect(actual).to_not eq(expected) + # expect(actual).not_to eq(expected) # @return [ExpectationTarget] # @see ExpectationTarget#to - # @see ExpectationTarget#to_not + # @see ExpectationTarget#not_to # @api private # Determines where we add `should` and `should_not`. diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations/version.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations/version.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations/version.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations/version.rb 2013-08-15 17:28:02.000000000 +0000 @@ -2,7 +2,8 @@ module Expectations # @private module Version - STRING = '2.13.0' + STRING = '2.14.2' end end end + diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/expectations.rb ruby-rspec-expectations-2.14.2/lib/rspec/expectations.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/expectations.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/expectations.rb 2013-08-15 17:28:02.000000000 +0000 @@ -37,7 +37,7 @@ # `eq.failure_message_for_should_not`. # # rspec-expectations ships with a standard set of useful matchers, and writing - # your own matchers is quite simple. + # your own matchers is quite simple. # # See [RSpec::Matchers](../RSpec/Matchers) for more information about the # built-in matchers that ship with rspec-expectations, and how to write your diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/be_close.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/be_close.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/be_close.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/be_close.rb 2013-08-15 17:28:02.000000000 +0000 @@ -2,7 +2,7 @@ module Matchers # @deprecated use +be_within+ instead. def be_close(expected, delta) - RSpec.deprecate("be_close(#{expected}, #{delta})", "be_within(#{delta}).of(#{expected})") + RSpec.deprecate("be_close(#{expected}, #{delta})", :replacement => "be_within(#{delta}).of(#{expected})") be_within(delta).of(expected) end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/be.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/be.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/be.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/be.rb 2013-08-15 17:28:02.000000000 +0000 @@ -45,7 +45,33 @@ end end + module BeHelpers + private + + def args_to_s + @args.empty? ? "" : parenthesize(inspected_args.join(', ')) + end + + def parenthesize(string) + "(#{string})" + end + + def inspected_args + @args.collect{|a| a.inspect} + end + + def expected_to_sentence + split_words(@expected) + end + + def args_to_sentence + to_sentence(@args) + end + end + class Be < BaseMatcher + include BeHelpers + def initialize(*args, &block) @args = args end @@ -67,28 +93,6 @@ BeComparedTo.new(operand, operator) end end - - private - - def args_to_s - @args.empty? ? "" : parenthesize(inspected_args.join(', ')) - end - - def parenthesize(string) - "(#{string})" - end - - def inspected_args - @args.collect{|a| a.inspect} - end - - def expected_to_sentence - split_words(@expected) - end - - def args_to_sentence - to_sentence(@args) - end end class BeComparedTo < Be @@ -126,7 +130,9 @@ end end - class BePredicate < Be + class BePredicate < BaseMatcher + include BeHelpers + def initialize(*args, &block) @expected = parse_expected(args.shift) @args = args @@ -148,6 +154,8 @@ end end + alias === matches? + def failure_message_for_should "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}" end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/be_within.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/be_within.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/be_within.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/be_within.rb 2013-08-15 17:28:02.000000000 +0000 @@ -23,7 +23,7 @@ def percent_of(expected) @expected = expected - @tolerance = @delta * @expected / 100 + @tolerance = @delta * @expected.abs / 100.0 @unit = '%' self end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/change.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/change.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/change.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/change.rb 2013-08-15 17:28:02.000000000 +0000 @@ -39,7 +39,7 @@ if @eval_before && !expected_matches_actual?(@expected_before, @actual_before) "#{message} should have initially been #{@expected_before.inspect}, but was #{@actual_before.inspect}" elsif @eval_after && !expected_matches_actual?(@expected_after, @actual_after) - "#{message} should have been changed to #{@expected_after.inspect}, but is now #{@actual_after.inspect}" + "#{message} should have been changed to #{failure_message_for_expected_after}, but is now #{@actual_after.inspect}" elsif @expected_delta "#{message} should have been changed by #{@expected_delta.inspect}, but was changed by #{actual_delta.inspect}" elsif @minimum @@ -92,6 +92,14 @@ private + def failure_message_for_expected_after + if RSpec::Matchers.is_a_matcher?(@expected_after) + @expected_after.description + else + @expected_after.inspect + end + end + def message @message || "result" end @@ -125,7 +133,7 @@ end def expected_matches_actual?(expected, actual) - expected === actual + expected === actual || actual == expected end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/have.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/have.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/have.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/have.rb 2013-08-15 17:28:02.000000000 +0000 @@ -2,6 +2,8 @@ module Matchers module BuiltIn class Have + QUERY_METHODS = [:size, :length, :count].freeze + def initialize(expected, relativity=:exactly) @expected = case expected when :no then 0 @@ -22,9 +24,19 @@ def matches?(collection_or_owner) collection = determine_collection(collection_or_owner) - query_method = determine_query_method(collection) - raise not_a_collection unless query_method - @actual = collection.__send__(query_method) + case collection + when enumerator_class + for query_method in QUERY_METHODS + next unless collection.respond_to?(query_method) + @actual = collection.__send__(query_method) + break unless @actual.nil? + end + raise not_a_collection if @actual.nil? + else + query_method = determine_query_method(collection) + raise not_a_collection unless query_method + @actual = collection.__send__(query_method) + end case @relativity when :at_least then @actual >= @expected when :at_most then @actual <= @expected @@ -46,7 +58,7 @@ end def determine_query_method(collection) - [:size, :length, :count].detect {|m| collection.respond_to?(m)} + QUERY_METHODS.detect {|m| collection.respond_to?(m)} end def not_a_collection @@ -102,6 +114,10 @@ def relative_expectation "#{relativities[@relativity]}#{@expected}" end + + def enumerator_class + RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator + end end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/include.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/include.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/include.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/include.rb 2013-08-15 17:28:02.000000000 +0000 @@ -23,7 +23,7 @@ def diffable? # Matchers do not diff well, since diff uses their inspect # output, which includes their instance variables and such. - @expected.none? { |e| is_a_matcher?(e) } + @expected.none? { |e| RSpec::Matchers.is_a_matcher?(e) } end private @@ -53,15 +53,7 @@ end def comparing_with_matcher?(actual, expected) - actual.is_a?(Array) && is_a_matcher?(expected) - end - - def is_a_matcher?(object) - return false if object.respond_to?(:i_respond_to_everything_so_im_not_really_a_matcher) - - [:failure_message_for_should, :failure_message].any? do |msg| - object.respond_to?(msg) - end && object.respond_to?(:matches?) + actual.is_a?(Array) && RSpec::Matchers.is_a_matcher?(expected) end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/raise_error.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/raise_error.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/raise_error.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/raise_error.rb 2013-08-15 17:28:02.000000000 +0000 @@ -14,19 +14,31 @@ end def matches?(given_proc, negative_expectation = false) + if negative_expectation && (expecting_specific_exception? || @expected_message) + what_to_deprecate = if expecting_specific_exception? && @expected_message + "`expect { }.not_to raise_error(SpecificErrorClass, message)`" + elsif expecting_specific_exception? + "`expect { }.not_to raise_error(SpecificErrorClass)`" + elsif @expected_message + "`expect { }.not_to raise_error(message)`" + end + RSpec.deprecate(what_to_deprecate, :replacement => "`expect { }.not_to raise_error()`") + end @raised_expected_error = false @with_expected_message = false @eval_block = false @eval_block_passed = false + unless given_proc.respond_to?(:call) + ::Kernel.warn "`raise_error` was called with non-proc object #{given_proc.inspect}" + return false + end begin given_proc.call - rescue @expected_error => @actual_error - @raised_expected_error = true - @with_expected_message = verify_message rescue Exception => @actual_error - # This clause should be empty, but rcov will not report it as covered - # unless something (anything) is executed within the clause - "http://eigenclass.org/hiki.rb?rcov-0.8.0" + if @actual_error == @expected_error || @expected_error === @actual_error + @raised_expected_error = true + @with_expected_message = verify_message + end end unless negative_expectation @@ -79,7 +91,7 @@ def expected_error case @expected_message when nil - @expected_error + @expected_error.inspect when Regexp "#{@expected_error} with message matching #{@expected_message.inspect}" else @@ -101,6 +113,10 @@ *backtrace ].join("\n # ") end + + def expecting_specific_exception? + @expected_error != Exception + end end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/yield.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/yield.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/built_in/yield.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/built_in/yield.rb 2013-08-15 17:28:02.000000000 +0000 @@ -65,17 +65,92 @@ end class YieldControl < BaseMatcher + def initialize + @expectation_type = nil + @expected_yields_count = nil + end + def matches?(block) probe = YieldProbe.probe(block) - probe.yielded_once?(:yield_control) + + if @expectation_type + probe.num_yields.send(@expectation_type, @expected_yields_count) + else + probe.yielded_once?(:yield_control) + end + end + + def once + exactly(1) + self + end + + def twice + exactly(2) + self + end + + def exactly(number) + set_expected_yields_count(:==, number) + self + end + + def at_most(number) + set_expected_yields_count(:<=, number) + self + end + + def at_least(number) + set_expected_yields_count(:>=, number) + self + end + + def times + self end def failure_message_for_should - "expected given block to yield control" + 'expected given block to yield control'.tap do |failure_message| + failure_message << relativity_failure_message + end end def failure_message_for_should_not - "expected given block not to yield control" + 'expected given block not to yield control'.tap do |failure_message| + failure_message << relativity_failure_message + end + end + + private + + def set_expected_yields_count(relativity, n) + @expectation_type = relativity + @expected_yields_count = case n + when Numeric then n + when :once then 1 + when :twice then 2 + end + end + + def relativity_failure_message + return '' unless @expected_yields_count + " #{human_readable_expecation_type}#{human_readable_count}" + end + + def human_readable_expecation_type + case @expectation_type + when :<= then 'at most ' + when :>= then 'at least ' + else '' + end + end + + def human_readable_count + case @expected_yields_count + when 1 then "once" + when 2 then "twice" + else "#{@expected_yields_count} times" + end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/operator_matcher.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/operator_matcher.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/operator_matcher.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/operator_matcher.rb 2013-08-15 17:28:02.000000000 +0000 @@ -91,7 +91,7 @@ if actual.__send__(operator, expected) true elsif ['==','===', '=~'].include?(operator) - fail_with_message("expected: #{expected.inspect}\n got: #{actual.inspect} (using #{operator})") + fail_with_message("expected: #{expected.inspect}\n got: #{actual.inspect} (using #{operator})") else fail_with_message("expected: #{operator} #{expected.inspect}\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}") end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/pretty.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/pretty.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/pretty.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/pretty.rb 2013-08-15 17:28:02.000000000 +0000 @@ -35,7 +35,7 @@ end def to_word(item) - item.respond_to?(:description) ? item.description : item.inspect + is_matcher_with_description?(item) ? item.description : item.inspect end def name_to_sentence @@ -59,6 +59,12 @@ word.downcase! word end + + private + + def is_matcher_with_description?(object) + RSpec::Matchers.is_a_matcher?(object) && object.respond_to?(:description) + end end end end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers/test_unit_integration.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers/test_unit_integration.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers/test_unit_integration.rb 1970-01-01 00:00:00.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers/test_unit_integration.rb 2013-08-15 17:28:02.000000000 +0000 @@ -0,0 +1,11 @@ +# Include Matchers for other test frameworks. Note that MiniTest _must_ +# come before TU because on ruby 1.9, T::U::TC is a subclass of MT::U::TC +# and a 1.9 bug can lead to infinite recursion from the `super` call in our +# method_missing hook. See this gist for more info: +# https://gist.github.com/845896 +if defined?(MiniTest::Unit::TestCase) + MiniTest::Unit::TestCase.send(:include, RSpec::Matchers) +end +if defined?(Test::Unit::TestCase) + Test::Unit::TestCase.send(:include, RSpec::Matchers) +end diff -Nru ruby-rspec-expectations-2.13.0/lib/rspec/matchers.rb ruby-rspec-expectations-2.14.2/lib/rspec/matchers.rb --- ruby-rspec-expectations-2.13.0/lib/rspec/matchers.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/lib/rspec/matchers.rb 2013-08-15 17:28:02.000000000 +0000 @@ -1,5 +1,19 @@ +require 'rspec/matchers/extensions/instance_eval_with_args' +require 'rspec/matchers/pretty' + +require 'rspec/matchers/built_in' +require 'rspec/matchers/matcher' +require 'rspec/matchers/operator_matcher' +require 'rspec/matchers/be_close' + +require 'rspec/matchers/generated_descriptions' +require 'rspec/matchers/method_missing' +require 'rspec/matchers/compatibility' +require 'rspec/matchers/dsl' +require 'rspec/matchers/test_unit_integration' + module RSpec - # RSpec::Matchers provides a number of useful matchers we use to compose + # RSpec::Matchers provides a number of useful matchers we use to define # expectations. A matcher is any object that responds to the following: # # matches?(actual) @@ -20,28 +34,29 @@ # A Ruby predicate is a method that ends with a "?" and returns true or false. # Common examples are `empty?`, `nil?`, and `instance_of?`. # - # All you need to do is write `should be_` followed by the predicate without - # the question mark, and RSpec will figure it out from there. For example: + # All you need to do is write `expect(..).to be_` followed by the predicate + # without the question mark, and RSpec will figure it out from there. + # For example: # - # [].should be_empty # => [].empty?() | passes - # [].should_not be_empty # => [].empty?() | fails + # expect([]).to be_empty # => [].empty?() | passes + # expect([]).not_to be_empty # => [].empty?() | fails # # In addtion to prefixing the predicate matchers with "be_", you can also use "be_a_" # and "be_an_", making your specs read much more naturally: # - # "a string".should be_an_instance_of(String) =>"a string".instance_of?(String) #passes + # expect("a string").to be_an_instance_of(String) # =>"a string".instance_of?(String) # passes # - # 3.should be_a_kind_of(Fixnum) # => 3.kind_of?(Numeric) | passes - # 3.should be_a_kind_of(Numeric) # => 3.kind_of?(Numeric) | passes - # 3.should be_an_instance_of(Fixnum) # => 3.instance_of?(Fixnum) | passes - # 3.should_not be_instance_of(Numeric) # => 3.instance_of?(Numeric) | fails + # expect(3).to be_a_kind_of(Fixnum) # => 3.kind_of?(Numeric) | passes + # expect(3).to be_a_kind_of(Numeric) # => 3.kind_of?(Numeric) | passes + # expect(3).to be_an_instance_of(Fixnum) # => 3.instance_of?(Fixnum) | passes + # expect(3).not_to be_an_instance_of(Numeric) # => 3.instance_of?(Numeric) | fails # # RSpec will also create custom matchers for predicates like `has_key?`. To # use this feature, just state that the object should have_key(:key) and RSpec will # call has_key?(:key) on the target. For example: # - # {:a => "A"}.should have_key(:a) # => {:a => "A"}.has_key?(:a) | passes - # {:a => "A"}.should have_key(:b) # => {:a => "A"}.has_key?(:b) | fails + # expect(:a => "A").to have_key(:a) + # expect(:a => "A").to have_key(:b) # fails # # You can use this feature to invoke any predicate that begins with "has_", whether it is # part of the Ruby libraries (like `Hash#has_key?`) or a method you wrote on your own class. @@ -58,15 +73,15 @@ # zones on a virtual board. To specify that bob should be in zone 4, you # could say: # - # bob.current_zone.should eql(Zone.new("4")) + # expect(bob.current_zone).to eql(Zone.new("4")) # # But you might find it more expressive to say: # - # bob.should be_in_zone("4") + # expect(bob).to be_in_zone("4") # # and/or # - # bob.should_not be_in_zone("3") + # expect(bob).not_to be_in_zone("3") # # You can create such a matcher like so: # @@ -102,7 +117,7 @@ # passed to the create method (in this case, zone). The # failure message methods (failure_message_for_should and # failure_message_for_should_not) are passed the actual value (the - # receiver of should or should_not). + # receiver of expect(..) or expect(..).not_to). # # ### Custom Matcher from scratch # @@ -159,35 +174,14 @@ # config.include(CustomGameMatchers) # end module Matchers - # Include Matchers for other test frameworks. Note that MiniTest _must_ - # come before TU because on ruby 1.9, T::U::TC is a subclass of MT::U::TC - # and a 1.9 bug can lead to infinite recursion from the `super` call in our - # method_missing hook. See this gist for more info: - # https://gist.github.com/845896 - if defined?(MiniTest::Unit::TestCase) - MiniTest::Unit::TestCase.send(:include, self) - end - if defined?(Test::Unit::TestCase) - Test::Unit::TestCase.send(:include, self) - end - end -end + # @api private + def self.is_a_matcher?(obj) + return true if ::RSpec::Matchers::BuiltIn::BaseMatcher === obj + return false if obj.respond_to?(:i_respond_to_everything_so_im_not_really_a_matcher) + return false unless obj.respond_to?(:matches?) -require 'rspec/matchers/extensions/instance_eval_with_args' -require 'rspec/matchers/pretty' - -require 'rspec/matchers/built_in' -require 'rspec/matchers/matcher' -require 'rspec/matchers/operator_matcher' -require 'rspec/matchers/be_close' - -require 'rspec/matchers/generated_descriptions' -require 'rspec/matchers/method_missing' -require 'rspec/matchers/compatibility' -require 'rspec/matchers/dsl' - -module RSpec - module Matchers + obj.respond_to?(:failure_message_for_should) || obj.respond_to?(:failure_message) + end # Passes if actual is truthy (anything but false or nil) def be_true @@ -205,12 +199,12 @@ end # @example - # actual.should be_true - # actual.should be_false - # actual.should be_nil - # actual.should be_[arbitrary_predicate](*args) - # actual.should_not be_nil - # actual.should_not be_[arbitrary_predicate](*args) + # expect(actual).to be_true + # expect(actual).to be_false + # expect(actual).to be_nil + # expect(actual).to be_[arbitrary_predicate](*args) + # expect(actual).not_to be_nil + # expect(actual).not_to be_[arbitrary_predicate](*args) # # Given true, false, or nil, will pass if actual value is true, false or # nil (respectively). Given no args means the caller should satisfy an if @@ -240,9 +234,9 @@ # # @example # - # 5.should be_instance_of(Fixnum) - # 5.should_not be_instance_of(Numeric) - # 5.should_not be_instance_of(Float) + # expect(5).to be_an_instance_of(Fixnum) + # expect(5).not_to be_an_instance_of(Numeric) + # expect(5).not_to be_an_instance_of(Float) def be_an_instance_of(expected) BuiltIn::BeAnInstanceOf.new(expected) end @@ -253,9 +247,9 @@ # # @example # - # 5.should be_kind_of(Fixnum) - # 5.should be_kind_of(Numeric) - # 5.should_not be_kind_of(Float) + # expect(5).to be_a_kind_of(Fixnum) + # expect(5).to be_a_kind_of(Numeric) + # expect(5).not_to be_a_kind_of(Float) def be_a_kind_of(expected) BuiltIn::BeAKindOf.new(expected) end @@ -266,8 +260,8 @@ # # @example # - # result.should be_within(0.5).of(3.0) - # result.should_not be_within(0.5).of(3.0) + # expect(result).to be_within(0.5).of(3.0) + # expect(result).not_to be_within(0.5).of(3.0) def be_within(delta) BuiltIn::BeWithin.new(delta) end @@ -283,55 +277,59 @@ # # When passing a block, it must use the { ... } format, not # do/end, as { ... } binds to the +change+ method, whereas do/end - # would errantly bind to the +should+ or +should_not+ method. + # would errantly bind to the +expect(..)+ or +expect(..).not_to+ method. # # @example # - # lambda { + # expect { # team.add_player(player) - # }.should change(roster, :count) + # }.to change(roster, :count) # - # lambda { + # expect { # team.add_player(player) - # }.should change(roster, :count).by(1) + # }.to change(roster, :count).by(1) # - # lambda { + # expect { # team.add_player(player) - # }.should change(roster, :count).by_at_least(1) + # }.to change(roster, :count).by_at_least(1) # - # lambda { + # expect { # team.add_player(player) - # }.should change(roster, :count).by_at_most(1) + # }.to change(roster, :count).by_at_most(1) # # string = "string" - # lambda { + # expect { # string.reverse! - # }.should change { string }.from("string").to("gnirts") + # }.to change { string }.from("string").to("gnirts") # - # lambda { + # string = "string" + # expect { + # string + # }.not_to change { string } + # + # expect { # person.happy_birthday - # }.should change(person, :birthday).from(32).to(33) + # }.to change(person, :birthday).from(32).to(33) # - # lambda { + # expect { # employee.develop_great_new_social_networking_app - # }.should change(employee, :title).from("Mail Clerk").to("CEO") + # }.to change(employee, :title).from("Mail Clerk").to("CEO") # - # lambda { + # expect { # doctor.leave_office - # }.should change(doctor, :sign).from(/is in/).to(/is out/) + # }.to change(doctor, :sign).from(/is in/).to(/is out/) # # user = User.new(:type => "admin") - # lambda { + # expect { # user.symbolize_type - # }.should change(user, :type).from(String).to(Symbol) + # }.to change(user, :type).from(String).to(Symbol) # # == Notes # # Evaluates receiver.message or block before and after it - # evaluates the proc object (generated by the lambdas in the examples - # above). + # evaluates the block passed to expect. # - # should_not change only supports the form with no subsequent + # expect( ... ).not_to change only supports the form with no subsequent # calls to by, by_at_least, by_at_most, # to or from. def change(receiver=nil, message=nil, &block) @@ -343,11 +341,11 @@ # and it will only pass if all args are found in Range. # # @example - # (1..10).should cover(5) - # (1..10).should cover(4, 6) - # (1..10).should cover(4, 6, 11) # will fail - # (1..10).should_not cover(11) - # (1..10).should_not cover(5) # will fail + # expect(1..10).to cover(5) + # expect(1..10).to cover(4, 6) + # expect(1..10).to cover(4, 6, 11) # fails + # expect(1..10).not_to cover(11) + # expect(1..10).not_to cover(5) # fails # # ### Warning:: Ruby >= 1.9 only def cover(*values) @@ -361,45 +359,48 @@ # # @example # - # "this string".should end_with "string" - # [0, 1, 2, 3, 4].should end_with 4 - # [0, 2, 3, 4, 4].should end_with 3, 4 + # expect("this string").to end_with "string" + # expect([0, 1, 2, 3, 4]).to end_with 4 + # expect([0, 2, 3, 4, 4]).to end_with 3, 4 def end_with(*expected) BuiltIn::EndWith.new(*expected) end # Passes if actual == expected. # - # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby. + # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more + # information about equality in Ruby. # # @example # - # 5.should eq(5) - # 5.should_not eq(3) + # expect(5).to eq(5) + # expect(5).not_to eq(3) def eq(expected) BuiltIn::Eq.new(expected) end # Passes if +actual.eql?(expected)+ # - # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby. + # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more + # information about equality in Ruby. # # @example # - # 5.should eql(5) - # 5.should_not eql(3) + # expect(5).to eql(5) + # expect(5).not_to eql(3) def eql(expected) BuiltIn::Eql.new(expected) end # Passes if actual.equal?(expected) (object identity). # - # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby. + # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more + # information about equality in Ruby. # # @example # - # 5.should equal(5) # Fixnums are equal - # "5".should_not equal("5") # Strings that look the same are not the same object + # expect(5).to equal(5) # Fixnums are equal + # expect("5").not_to equal("5") # Strings that look the same are not the same object def equal(expected) BuiltIn::Equal.new(expected) end @@ -407,7 +408,7 @@ # Passes if `actual.exist?` or `actual.exists?` # # @example - # File.should exist("path/to/file") + # expect(File).to exist("path/to/file") def exist(*args) BuiltIn::Exist.new(*args) end @@ -430,16 +431,16 @@ # @example # # # Passes if team.players.size == 11 - # team.should have(11).players + # expect(team).to have(11).players # # # Passes if [1,2,3].length == 3 - # [1,2,3].should have(3).items #"items" is pure sugar + # expect([1,2,3]).to have(3).items #"items" is pure sugar # # # Passes if ['a', 'b', 'c'].count == 3 - # [1,2,3].should have(3).items #"items" is pure sugar + # expect([1,2,3]).to have(3).items #"items" is pure sugar # # # Passes if "this string".length == 11 - # "this string".should have(11).characters #"characters" is pure sugar + # expect("this string").to have(11).characters #"characters" is pure sugar def have(n) BuiltIn::Have.new(n) end @@ -448,11 +449,11 @@ # Exactly like have() with >=. # # @example - # "this".should have_at_least(3).letters + # expect("this").to have_at_least(3).letters # # ### Warning: # - # `should_not have_at_least` is not supported + # `expect(..).not_to have_at_least` is not supported def have_at_least(n) BuiltIn::Have.new(n, :at_least) end @@ -460,11 +461,11 @@ # Exactly like have() with <=. # # @example - # should have_at_most(number).items + # expect("this").to have_at_most(4).letters # # ### Warning: # - # `should_not have_at_most` is not supported + # `expect(..).not_to have_at_most` is not supported def have_at_most(n) BuiltIn::Have.new(n, :at_most) end @@ -475,12 +476,12 @@ # # @example # - # [1,2,3].should include(3) - # [1,2,3].should include(2,3) #would pass - # [1,2,3].should include(2,3,4) #would fail - # [1,2,3].should_not include(4) - # "spread".should include("read") - # "spread".should_not include("red") + # expect([1,2,3]).to include(3) + # expect([1,2,3]).to include(2,3) + # expect([1,2,3]).to include(2,3,4) # fails + # expect([1,2,3]).not_to include(4) + # expect("spread").to include("read") + # expect("spread").not_to include("red") def include(*expected) BuiltIn::Include.new(*expected) end @@ -489,10 +490,10 @@ # # @example # - # email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) - # email.should match("@example.com") - # zipcode.should match_regex(/\A\d{5}(-\d{4})?\z/) - # zipcode.should match_regex("90210") + # expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) + # expect(email).to match("@example.com") + # expect(zipcode).to match_regex(/\A\d{5}(-\d{4})?\z/) + # expect(zipcode).to match_regex("90210") # # @note Due to Ruby's method dispatch mechanism, using the `#match` matcher # within a custom matcher defined via the matcher DSL @@ -513,16 +514,16 @@ # # @example # - # lambda { do_something_risky }.should raise_error - # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError) - # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError) { |error| error.data.should == 42 } - # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, "that was too risky") - # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, /oo ri/) - # - # lambda { do_something_risky }.should_not raise_error - # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError) - # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, "that was too risky") - # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, /oo ri/) + # expect { do_something_risky }.to raise_error + # expect { do_something_risky }.to raise_error(PoorRiskDecisionError) + # expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 } + # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky") + # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/) + # + # expect { do_something_risky }.not_to raise_error + # expect { do_something_risky }.not_to raise_error(PoorRiskDecisionError) + # expect { do_something_risky }.not_to raise_error(PoorRiskDecisionError, "that was too risky") + # expect { do_something_risky }.not_to raise_error(PoorRiskDecisionError, /oo ri/) def raise_error(error=Exception, message=nil, &block) BuiltIn::RaiseError.new(error, message, &block) end @@ -534,6 +535,8 @@ # # @example # + # expect("string").to respond_to(:length) + # def respond_to(*names) BuiltIn::RespondTo.new(*names) end @@ -550,9 +553,7 @@ # # @example # - # 5.should satisfy { |n| - # n > 3 - # } + # expect(5).to satisfy { |n| n > 3 } def satisfy(&block) BuiltIn::Satisfy.new(&block) end @@ -564,9 +565,9 @@ # # @example # - # "this string".should start_with "this s" - # [0, 1, 2, 3, 4].should start_with 0 - # [0, 2, 3, 4, 4].should start_with 0, 1 + # expect("this string").to start_with "this s" + # expect([0, 1, 2, 3, 4]).to start_with 0 + # expect([0, 2, 3, 4, 4]).to start_with 0, 1 def start_with(*expected) BuiltIn::StartWith.new(*expected) end @@ -580,13 +581,13 @@ # # @example # - # lambda { do_something_risky }.should throw_symbol - # lambda { do_something_risky }.should throw_symbol(:that_was_risky) - # lambda { do_something_risky }.should throw_symbol(:that_was_risky, culprit) - # - # lambda { do_something_risky }.should_not throw_symbol - # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky) - # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit) + # expect { do_something_risky }.to throw_symbol + # expect { do_something_risky }.to throw_symbol(:that_was_risky) + # expect { do_something_risky }.to throw_symbol(:that_was_risky, 'culprit') + # + # expect { do_something_risky }.not_to throw_symbol + # expect { do_something_risky }.not_to throw_symbol(:that_was_risky) + # expect { do_something_risky }.not_to throw_symbol(:that_was_risky, 'culprit') def throw_symbol(expected_symbol=nil, expected_arg=nil) BuiltIn::ThrowSymbol.new(expected_symbol, expected_arg) end @@ -679,17 +680,14 @@ # # @note This is also available using the `=~` operator with `should`, # but `=~` is not supported with `expect`. - # @note There is no should_not version of array.should =~ other_array + # + # @note This matcher only supports positive expectations. + # expect(..).not_to match_array(other_array) is not supported. # # @example # # expect([1,2,3]).to match_array([1,2,3]) # expect([1,2,3]).to match_array([1,3,2]) - # [1,2,3].should =~ [1,2,3] # => would pass - # [1,2,3].should =~ [2,3,1] # => would pass - # [1,2,3,4].should =~ [1,2,3] # => would fail - # [1,2,2,3].should =~ [1,2,3] # => would fail - # [1,2,3].should =~ [1,2,3,4] # => would fail def match_array(array) BuiltIn::MatchArray.new(array) end diff -Nru ruby-rspec-expectations-2.13.0/metadata.yml ruby-rspec-expectations-2.14.2/metadata.yml --- ruby-rspec-expectations-2.13.0/metadata.yml 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/metadata.yml 2013-08-15 17:28:02.000000000 +0000 @@ -2,7 +2,7 @@ name: rspec-expectations version: !ruby/object:Gem::Version prerelease: - version: 2.13.0 + version: 2.14.2 platform: ruby authors: - Steven Baker @@ -10,7 +10,7 @@ autorequire: bindir: bin cert_chain: [] -date: 2013-02-23 00:00:00.000000000 Z +date: 2013-08-15 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency version_requirements: !ruby/object:Gem::Requirement @@ -71,7 +71,7 @@ requirements: - - ~> - !ruby/object:Gem::Version - version: 0.4.11 + version: '0.5' none: false prerelease: false name: aruba @@ -79,7 +79,7 @@ requirements: - - ~> - !ruby/object:Gem::Version - version: 0.4.11 + version: '0.5' none: false type: :development description: rspec expectations (should[_not] and matchers) @@ -135,6 +135,7 @@ - lib/rspec/matchers/method_missing.rb - lib/rspec/matchers/operator_matcher.rb - lib/rspec/matchers/pretty.rb +- lib/rspec/matchers/test_unit_integration.rb - README.md - License.txt - Changelog.md @@ -172,6 +173,7 @@ - features/implicit_docstrings.feature - features/step_definitions/additional_cli_steps.rb - features/support/env.rb +- features/support/rubinius.rb - features/syntax_configuration.feature - features/test_frameworks/test_unit.feature - spec/rspec/expectations/differ_spec.rb @@ -232,7 +234,7 @@ version: '0' segments: - 0 - hash: 3249637945894736858 + hash: 2244321019137391681 none: false required_rubygems_version: !ruby/object:Gem::Requirement requirements: @@ -241,14 +243,14 @@ version: '0' segments: - 0 - hash: 3249637945894736858 + hash: 2244321019137391681 none: false requirements: [] rubyforge_project: rspec rubygems_version: 1.8.24 signing_key: specification_version: 3 -summary: rspec-expectations-2.13.0 +summary: rspec-expectations-2.14.2 test_files: - features/README.md - features/Upgrade.md @@ -282,6 +284,7 @@ - features/implicit_docstrings.feature - features/step_definitions/additional_cli_steps.rb - features/support/env.rb +- features/support/rubinius.rb - features/syntax_configuration.feature - features/test_frameworks/test_unit.feature - spec/rspec/expectations/differ_spec.rb diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/expectations/differ_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/expectations/differ_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/expectations/differ_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/expectations/differ_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'spec_helper' require 'ostruct' @@ -13,10 +14,11 @@ # color disabled context describe '#diff_as_string' do + subject { differ.diff_as_string(@expected, @actual) } it "outputs unified diff of two strings" do - expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n" - actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n" - expected_diff= <<'EOD' + @expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n" + @actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n" + expect(subject).to eql(<<-'EOD') @@ -1,6 +1,6 @@ @@ -35,8 +37,28 @@ line EOD - diff = differ.diff_as_string(expected, actual) - expect(diff).to eql(expected_diff) + end + if RUBY_VERSION.to_f > 1.9 + it 'copes with encoded strings', :pending => (Diff::LCS::VERSION < '1.2.2') do + @expected="Tu avec carté {count} itém has".encode('UTF-16LE') + @actual="Tu avec carte {count} item has".encode('UTF-16LE') + expect(subject).to eql(<<-EOD.encode('UTF-16LE')) + +@@ -1,2 +1,2 @@ +-Tu avec carte {count} item has ++Tu avec carté {count} itém has +EOD + end + it 'copes with encoded strings', :pending => (Diff::LCS::VERSION >= '1.2.2') do + @expected="Tu avec carté {count} itém has".encode('UTF-16LE') + @actual="Tu avec carte {count} item has".encode('UTF-16LE') + expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)' + end + it 'ouputs a message when encountering differently encoded strings' do + @expected="Tu avec carté {count} itém has".encode('UTF-16LE') + @actual="Tu avec carte {count} item has" + expect(subject).to eql 'Could not produce a diff because the encoding of the actual string (UTF-8) differs from the encoding of the expected string (UTF-16LE)' + end end end @@ -115,6 +137,17 @@ expect(diff).to eq expected_diff end + it 'outputs unified diff messaoge of two hashes with differing encoding' do + expected_diff = %Q{ +@@ -1,2 +1,2 @@ +-"a" => "a" +#{ (RUBY_VERSION.to_f > 1.8) ? %Q{+"ö" => "ö"} : '+"\303\266" => "\303\266"' } +} + + diff = differ.diff_as_object({'ö' => 'ö'}, {'a' => 'a'}) + expect(diff).to eq expected_diff + end + it "outputs unified diff of single line strings" do expected = "this is one string" actual = "this is another string" diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/expectations/expectation_target_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/expectations/expectation_target_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/expectations/expectation_target_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/expectations/expectation_target_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -37,10 +37,13 @@ end it 'passes a valid negative expectation' do - expect(5).to_not eq(4) expect(5).not_to eq(4) end + it 'passes a valid negative expectation with a split infinitive' do + expect(5).to_not eq(4) + end + it 'fails an invalid positive expectation' do expect { expect(5).to eq(4) @@ -50,10 +53,14 @@ it 'fails an invalid negative expectation' do message = /expected 5 not to be a kind of Fixnum/ expect { - expect(5).to_not be_a(Fixnum) + expect(5).not_to be_a(Fixnum) }.to fail_with(message) + end + + it 'fails an invalid negative expectation with a split infinitive' do + message = /expected 5 not to be a kind of Fixnum/ expect { - expect(5).not_to be_a(Fixnum) + expect(5).to_not be_a(Fixnum) }.to fail_with(message) end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/expectations/extensions/kernel_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/expectations/extensions/kernel_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/expectations/extensions/kernel_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/expectations/extensions/kernel_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -3,9 +3,9 @@ describe Object, "#should" do before(:each) do @target = "target" - @matcher = mock("matcher") - @matcher.stub!(:matches?).and_return(true) - @matcher.stub!(:failure_message_for_should) + @matcher = double("matcher") + @matcher.stub(:matches?).and_return(true) + @matcher.stub(:failure_message_for_should) end it "accepts and interacts with a matcher" do @@ -47,12 +47,12 @@ describe Object, "#should_not" do before(:each) do @target = "target" - @matcher = mock("matcher") + @matcher = double("matcher") end it "accepts and interacts with a matcher" do @matcher.should_receive(:matches?).with(@target).and_return(false) - @matcher.stub!(:failure_message_for_should_not) + @matcher.stub(:failure_message_for_should_not) expect(@target).not_to @matcher end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/expectations/fail_with_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/expectations/fail_with_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/expectations/fail_with_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/expectations/fail_with_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -1,6 +1,25 @@ # encoding: utf-8 require 'spec_helper' + +describe RSpec::Expectations, "#fail_with with diff of arrays" do + before { RSpec::Matchers.configuration.stub(:color? => false) } + + it "splits items with newlines" do + expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n" + expect { + RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"]) + }.to fail_with(expected_diff) + end + + it "shows inner arrays on a single line" do + expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+[\"c\\nd\"]\n" + expect { + RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]]) + }.to fail_with(expected_diff) + end +end + describe RSpec::Expectations, "#fail_with with diff" do let(:differ) { double("differ") } diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/expectations/handler_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/expectations/handler_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/expectations/handler_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/expectations/handler_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -49,21 +49,21 @@ describe PositiveExpectationHandler do describe "#handle_matcher" do it "asks the matcher if it matches" do - matcher = mock("matcher") + matcher = double("matcher") actual = Object.new matcher.should_receive(:matches?).with(actual).and_return(true) RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher) end it "returns the match value" do - matcher = mock("matcher") + matcher = double("matcher") actual = Object.new matcher.should_receive(:matches?).with(actual).and_return(:this_value) expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value end it "calls failure_message_for_should if the matcher implements it" do - matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false) + matcher = double("matcher", :failure_message_for_should => "message", :matches? => false) actual = Object.new ::RSpec::Expectations.should_receive(:fail_with).with("message") @@ -72,7 +72,7 @@ end it "calls fail if matcher.diffable?" do - matcher = mock("matcher", + matcher = double("matcher", :diffable? => true, :failure_message_for_should => "message", :matches? => false, @@ -87,7 +87,7 @@ end it "calls failure_message if the matcher does not implement failure_message_for_should" do - matcher = mock("matcher", :failure_message => "message", :matches? => false) + matcher = double("matcher", :failure_message => "message", :matches? => false) actual = Object.new ::RSpec::Expectations.should_receive(:fail_with).with("message") @@ -96,45 +96,56 @@ end - it "appends the :or message in the options hash passed to should" do - matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false) + it "uses the custom failure message when one is provided" do + matcher = double("matcher", :failure_message_for_should => "message", :matches? => false) actual = Object.new ::RSpec::Expectations.should_receive(:fail_with).with("custom") RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom") end + + it "uses the custom failure message when one is provided as a callable object" do + matcher = double("matcher", :failure_message_for_should => "message", :matches? => false) + actual = Object.new + + failure_message = double("failure message", :call => "custom") + + ::RSpec::Expectations.should_receive(:fail_with).with("custom") + + RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message) + end end end describe NegativeExpectationHandler do describe "#handle_matcher" do it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do - matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil) + matcher = double("matcher", :does_not_match? => true, :negative_failure_message => nil) actual = Object.new matcher.should_receive(:does_not_match?).with(actual).and_return(true) RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher) end it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do - matcher = mock("matcher") + matcher = double("matcher") actual = Object.new - matcher.stub!(:negative_failure_message) + matcher.stub(:negative_failure_message) matcher.should_receive(:matches?).with(actual).and_return(false) RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher) end it "returns the match value" do - matcher = mock("matcher") + matcher = double("matcher") actual = Object.new matcher.should_receive(:matches?).with(actual).and_return(false) - matcher.stub!(:negative_failure_message).and_return("ignore") + matcher.stub(:negative_failure_message).and_return("ignore") expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_false end it "calls failure_message_for_should_not if the matcher implements it" do - matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true) + matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true) actual = Object.new ::RSpec::Expectations.should_receive(:fail_with).with("message") @@ -144,7 +155,7 @@ end it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do - matcher = mock("matcher", :negative_failure_message => "message", :matches? => true) + matcher = double("matcher", :negative_failure_message => "message", :matches? => true) actual = Object.new ::RSpec::Expectations.should_receive(:fail_with).with("message") @@ -155,7 +166,7 @@ it "calls fail if matcher.diffable?" do - matcher = mock("matcher", + matcher = double("matcher", :diffable? => true, :failure_message_for_should_not => "message", :matches? => true, @@ -169,8 +180,8 @@ RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher) end - it "appends the :or message in the options hash passed to should" do - matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true) + it "uses the custom failure message when one is provided" do + matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true) actual = Object.new ::RSpec::Expectations.should_receive(:fail_with).with("custom") @@ -178,6 +189,16 @@ RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom") end + it "uses the custom failure message when one is provided as a callable object" do + matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true) + actual = Object.new + + failure_message = double("failure message", :call => "custom") + + ::RSpec::Expectations.should_receive(:fail_with).with("custom") + + RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message) + end end end @@ -189,10 +210,10 @@ expect(5).to arbitrary_matcher(:expected => "wrong").with(5) expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5") expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5") - expect(5).to_not arbitrary_matcher(:expected => 4) - expect(5).to_not arbitrary_matcher(:expected => 5).with(4) - expect { expect(5).to_not arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5") - expect { expect(5).to_not arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5") + expect(5).not_to arbitrary_matcher(:expected => 4) + expect(5).not_to arbitrary_matcher(:expected => 5).with(4) + expect { expect(5).not_to arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5") + expect { expect(5).not_to arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5") end it "handles the submitted block" do diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/expectations/syntax_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/expectations/syntax_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/expectations/syntax_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/expectations/syntax_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -6,9 +6,21 @@ context "when passing a message to an expectation" do let(:warner) { ::Kernel } + let(:string_like_object) do + Struct.new(:to_str, :to_s).new(*(["Ceci n'est pas une Chaine."]*2)) + end + + let(:insufficiently_string_like_object) do + Struct.new(:to_s).new("Ceci n'est pas une Chaine.") + end + + let(:callable_object) do + Struct.new(:call).new("Ceci n'est pas une Chaine.") + end + describe "expect(...).to" do it "prints a warning when the message object isn't a String" do - warner.should_receive(:warn).with /ignoring.*message/ + warner.should_receive(:warn).with(/ignoring.*message/) expect(3).to eq(3), :not_a_string end @@ -16,11 +28,26 @@ warner.should_not_receive(:warn) expect(3).to eq(3), "a string" end + + it "doesn't print a warning when message responds to to_str" do + warner.should_not_receive(:warn) + expect(3).to eq(3), string_like_object + end + + it "prints a warning when the message object handles to_s but not to_str" do + warner.should_receive(:warn).with(/ignoring.*message/) + expect(3).to eq(3), insufficiently_string_like_object + end + + it "doesn't print a warning when message responds to call" do + warner.should_not_receive(:warn) + expect(3).to eq(3), callable_object + end end - describe "expect(...).to_not" do + describe "expect(...).not_to" do it "prints a warning when the message object isn't a String" do - warner.should_receive(:warn).with /ignoring.*message/ + warner.should_receive(:warn).with(/ignoring.*message/) expect(3).not_to eq(4), :not_a_string end @@ -28,6 +55,21 @@ warner.should_not_receive(:warn) expect(3).not_to eq(4), "a string" end + + it "doesn't print a warning when message responds to to_str" do + warner.should_not_receive(:warn) + expect(3).not_to eq(4), string_like_object + end + + it "prints a warning when the message object handles to_s but not to_str" do + warner.should_receive(:warn).with(/ignoring.*message/) + expect(3).not_to eq(4), insufficiently_string_like_object + end + + it "doesn't print a warning when message responds to call" do + warner.should_not_receive(:warn) + expect(3).not_to eq(4), callable_object + end end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/be_close_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/be_close_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/be_close_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/be_close_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -4,17 +4,17 @@ module Matchers describe "expect(actual).to be_close(expected, delta)" do before(:each) do - RSpec.stub(:warn) + allow(RSpec).to receive(:deprecate) end - it "delegates to be_within(delta).of(expected)" do - should_receive(:be_within).with(0.5).and_return( be_within_matcher = stub ) - be_within_matcher.should_receive(:of).with(3.0) + it "is deprecated" do + expect(RSpec).to receive(:deprecate).with(/be_close.*/, :replacement => "be_within(0.5).of(3.0)") be_close(3.0, 0.5) end - it "prints a deprecation warning" do - RSpec.should_receive(:warn).with(/please use be_within.*instead/) + it "delegates to be_within(delta).of(expected)" do + should_receive(:be_within).with(0.5).and_return( be_within_matcher = double ) + be_within_matcher.should_receive(:of).with(3.0) be_close(3.0, 0.5) end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/be_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/be_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/be_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/be_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -2,24 +2,24 @@ describe "expect(...).to be_predicate" do it "passes when actual returns true for :predicate?" do - actual = stub("actual", :happy? => true) + actual = double("actual", :happy? => true) expect(actual).to be_happy end it "passes when actual returns true for :predicates? (present tense)" do - actual = stub("actual", :exists? => true, :exist? => true) + actual = double("actual", :exists? => true, :exist? => true) expect(actual).to be_exist end it "fails when actual returns false for :predicate?" do - actual = stub("actual", :happy? => false) + actual = double("actual", :happy? => false) expect { expect(actual).to be_happy }.to fail_with("expected happy? to return true, got false") end it "fails when actual returns false for :predicate?" do - actual = stub("actual", :happy? => nil) + actual = double("actual", :happy? => nil) expect { expect(actual).to be_happy }.to fail_with("expected happy? to return true, got nil") @@ -32,7 +32,7 @@ end it "fails on error other than NameError" do - actual = stub("actual") + actual = double("actual") actual.should_receive(:foo?).and_raise("aaaah") expect { expect(actual).to be_foo @@ -46,21 +46,27 @@ expect(actual).to be_foo }.to raise_error(/aaaah/) end + + it "does not support operator chaining like a basic `be` matcher does" do + matcher = be_happy + value = double(:happy? => false) + expect(be_happy == value).to be false + end end describe "expect(...).not_to be_predicate" do it "passes when actual returns false for :sym?" do - actual = stub("actual", :happy? => false) + actual = double("actual", :happy? => false) expect(actual).not_to be_happy end it "passes when actual returns nil for :sym?" do - actual = stub("actual", :happy? => nil) + actual = double("actual", :happy? => nil) expect(actual).not_to be_happy end it "fails when actual returns true for :sym?" do - actual = stub("actual", :happy? => true) + actual = double("actual", :happy? => true) expect { expect(actual).not_to be_happy }.to fail_with("expected happy? to return false, got true") @@ -75,13 +81,13 @@ describe "expect(...).to be_predicate(*args)" do it "passes when actual returns true for :predicate?(*args)" do - actual = mock("actual") + actual = double("actual") actual.should_receive(:older_than?).with(3).and_return(true) expect(actual).to be_older_than(3) end it "fails when actual returns false for :predicate?(*args)" do - actual = mock("actual") + actual = double("actual") actual.should_receive(:older_than?).with(3).and_return(false) expect { expect(actual).to be_older_than(3) @@ -97,13 +103,13 @@ describe "expect(...).not_to be_predicate(*args)" do it "passes when actual returns false for :predicate?(*args)" do - actual = mock("actual") + actual = double("actual") actual.should_receive(:older_than?).with(3).and_return(false) expect(actual).not_to be_older_than(3) end it "fails when actual returns true for :predicate?(*args)" do - actual = mock("actual") + actual = double("actual") actual.should_receive(:older_than?).with(3).and_return(true) expect { expect(actual).not_to be_older_than(3) @@ -119,16 +125,16 @@ describe "expect(...).to be_predicate(&block)" do it "passes when actual returns true for :predicate?(&block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:happy?).and_yield delegate.should_receive(:check_happy).and_return(true) expect(actual).to be_happy { delegate.check_happy } end it "fails when actual returns false for :predicate?(&block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:happy?).and_yield delegate.should_receive(:check_happy).and_return(false) expect { @@ -137,7 +143,7 @@ end it "fails when actual does not respond to :predicate?" do - delegate = mock("delegate", :check_happy => true) + delegate = double("delegate", :check_happy => true) expect { expect(Object.new).to be_happy { delegate.check_happy } }.to raise_error(NameError) @@ -146,16 +152,16 @@ describe "expect(...).not_to be_predicate(&block)" do it "passes when actual returns false for :predicate?(&block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:happy?).and_yield delegate.should_receive(:check_happy).and_return(false) expect(actual).not_to be_happy { delegate.check_happy } end it "fails when actual returns true for :predicate?(&block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:happy?).and_yield delegate.should_receive(:check_happy).and_return(true) expect { @@ -164,7 +170,7 @@ end it "fails when actual does not respond to :predicate?" do - delegate = mock("delegate", :check_happy => true) + delegate = double("delegate", :check_happy => true) expect { expect(Object.new).not_to be_happy { delegate.check_happy } }.to raise_error(NameError) @@ -173,16 +179,16 @@ describe "expect(...).to be_predicate(*args, &block)" do it "passes when actual returns true for :predicate?(*args, &block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:older_than?).with(3).and_yield(3) delegate.should_receive(:check_older_than).with(3).and_return(true) expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) } end it "fails when actual returns false for :predicate?(*args, &block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:older_than?).with(3).and_yield(3) delegate.should_receive(:check_older_than).with(3).and_return(false) expect { @@ -191,7 +197,7 @@ end it "fails when actual does not respond to :predicate?" do - delegate = mock("delegate", :check_older_than => true) + delegate = double("delegate", :check_older_than => true) expect { expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) } }.to raise_error(NameError) @@ -200,16 +206,16 @@ describe "expect(...).not_to be_predicate(*args, &block)" do it "passes when actual returns false for :predicate?(*args, &block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:older_than?).with(3).and_yield(3) delegate.should_receive(:check_older_than).with(3).and_return(false) expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) } end it "fails when actual returns true for :predicate?(*args, &block)" do - actual = mock("actual") - delegate = mock("delegate") + actual = double("actual") + delegate = double("delegate") actual.should_receive(:older_than?).with(3).and_yield(3) delegate.should_receive(:check_older_than).with(3).and_return(true) expect { @@ -218,7 +224,7 @@ end it "fails when actual does not respond to :predicate?" do - delegate = mock("delegate", :check_older_than => true) + delegate = double("delegate", :check_older_than => true) expect { expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) } }.to raise_error(NameError) @@ -465,10 +471,10 @@ describe "'expect(...).to be' with operator" do it "includes 'be' in the description" do - expect((be > 6).description).to match /be > 6/ - expect((be >= 6).description).to match /be >= 6/ - expect((be <= 6).description).to match /be <= 6/ - expect((be < 6).description).to match /be < 6/ + expect((be > 6).description).to match(/be > 6/) + expect((be >= 6).description).to match(/be >= 6/) + expect((be <= 6).description).to match(/be <= 6/) + expect((be < 6).description).to match(/be < 6/) end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/be_within_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/be_within_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/be_within_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/be_within_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -27,6 +27,14 @@ expect(5.5).to be_within(0.5).of(5.0) end + it "passes with integer arguments that are near each other" do + expect(1.0001).to be_within(5).percent_of(1) + end + + it "passes with negative arguments" do + expect(-1.0001).to be_within(5).percent_of(-1) + end + it "fails when actual < (expected - delta)" do expect { expect(4.49).to be_within(0.5).of(5.0) diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/change_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/change_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/change_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/change_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -28,6 +28,20 @@ end end + it "can specify the change of a variable's class" do + val = nil + + expect { + val = 42 + }.to change { val.class }.from(NilClass).to(Fixnum) + + expect { + expect { + val = "string" + }.to change { val.class }.from(Fixnum).to(NilClass) + }.to fail_with(/but is now String/) + end + context "with boolean values" do before(:each) do @instance = SomethingExpected.new @@ -72,6 +86,17 @@ expect {@instance.some_value << 1}.to change(@instance, :some_value) end + it "fails when a predicate on the actual fails" do + expect do + expect {@instance.some_value << 1}.to change { @instance.some_value }.to be_empty + end.to fail_with(/result should have been changed to/) + end + + it "passes when a predicate on the actual passes" do + @instance.some_value = [1] + expect {@instance.some_value.pop}.to change { @instance.some_value }.to be_empty + end + it "fails when actual is not modified by the block" do expect do expect {}.to change(@instance, :some_value) @@ -156,12 +181,12 @@ end it "passes when actual is not modified by the block" do - expect { }.to_not change(@instance, :some_value) + expect { }.not_to change(@instance, :some_value) end it "fails when actual is not modified by the block" do expect do - expect {@instance.some_value = 6}.to_not change(@instance, :some_value) + expect {@instance.some_value = 6}.not_to change(@instance, :some_value) end.to fail_with("some_value should not have changed, but did change from 5 to 6") end end @@ -206,18 +231,18 @@ end it "passes when actual is modified by the block" do - expect {}.to_not change{ @instance.some_value } + expect {}.not_to change{ @instance.some_value } end it "fails when actual is not modified by the block" do expect do - expect {@instance.some_value = 6}.to_not change { @instance.some_value } + expect {@instance.some_value = 6}.not_to change { @instance.some_value } end.to fail_with("result should not have changed, but did change from 5 to 6") end it "warns if passed a block using do/end instead of {}" do expect do - expect {}.to_not change do; end + expect {}.not_to change do; end end.to raise_error(SyntaxError, /block passed to should or should_not/) end end @@ -537,6 +562,6 @@ expect { expect { @instance.some_value = "cat" }.to change(@instance, :some_value) - }.to_not raise_error + }.not_to raise_error end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/configuration_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/configuration_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/configuration_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/configuration_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -22,7 +22,12 @@ end before do - RSpec.configuration.stub(:backtrace_clean_patterns) { [/clean-me/] } + @old_patterns = RSpec.configuration.backtrace_exclusion_patterns + RSpec.configuration.backtrace_exclusion_patterns = [/clean-me/] + end + + after do + RSpec.configuration.backtrace_exclusion_patterns = @old_patterns end it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do @@ -36,7 +41,7 @@ end it "can be set to another backtrace formatter" do - config.backtrace_formatter = stub(:format_backtrace => ['a']) + config.backtrace_formatter = double(:format_backtrace => ['a']) expect(formatted_backtrace).to eq(['a']) end end @@ -60,134 +65,97 @@ end shared_examples_for "configuring the expectation syntax" do - # We want a sandboxed method that ensures that we wind up with - # both syntaxes properly enabled when the example ends. - # - # On platforms that fork, using a sub process is the easiest, - # most robust way to achieve that. - # - # On jRuby we just re-enable both syntaxes at the end of the example; - # however, this is a generally inferior approach because it depends on - # the code-under-test working properly; if it doesn't work properly, - # it could leave things in a "broken" state where tons of other examples fail. - if RUBY_PLATFORM == "java" - def sandboxed - orig_syntax = RSpec::Matchers.configuration.syntax - yield - ensure - configure_syntax(orig_syntax) - end - else - include InSubProcess - alias sandboxed in_sub_process + before do + @orig_syntax = RSpec::Matchers.configuration.syntax end - it 'can limit the syntax to :should' do - sandboxed do - configure_syntax :should - configured_syntax.should eq([:should]) - - 3.should eq(3) - 3.should_not eq(4) - lambda { expect(6).to eq(6) }.should raise_error(NameError) - end + after do + configure_syntax(@orig_syntax) end - it 'is a no-op when configured to :should twice' do - sandboxed do - configure_syntax :should + it 'can limit the syntax to :should' do + configure_syntax :should + configured_syntax.should eq([:should]) - Expectations::Syntax.default_should_host. - stub(:method_added). - and_raise("no methods should be added here") + 3.should eq(3) + 3.should_not eq(4) + lambda { expect(6).to eq(6) }.should raise_error(NameError) + end - configure_syntax :should - end + it 'is a no-op when configured to :should twice' do + configure_syntax :should + Expectations::Syntax.default_should_host.should_not_receive(:method_added) + configure_syntax :should + RSpec::Mocks.verify # because configure_syntax is called again in an after hook end it 'can limit the syntax to :expect' do - sandboxed do - configure_syntax :expect - expect(configured_syntax).to eq([:expect]) - - expect(3).to eq(3) - expect { 3.should eq(3) }.to raise_error(NameError) - expect { 3.should_not eq(3) }.to raise_error(NameError) - end + configure_syntax :expect + expect(configured_syntax).to eq([:expect]) + + expect(3).to eq(3) + expect { 3.should eq(3) }.to raise_error(NameError) + expect { 3.should_not eq(3) }.to raise_error(NameError) end it 'is a no-op when configured to :expect twice' do - sandboxed do - RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here") + RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here") - configure_syntax :expect - configure_syntax :expect - end + configure_syntax :expect + configure_syntax :expect end it 'can re-enable the :should syntax' do - sandboxed do - configure_syntax :expect - configure_syntax [:should, :expect] - configured_syntax.should eq([:should, :expect]) - - 3.should eq(3) - 3.should_not eq(4) - expect(3).to eq(3) - end + configure_syntax :expect + configure_syntax [:should, :expect] + configured_syntax.should eq([:should, :expect]) + + 3.should eq(3) + 3.should_not eq(4) + expect(3).to eq(3) end it 'can re-enable the :expect syntax' do - sandboxed do - configure_syntax :should - configure_syntax [:should, :expect] - configured_syntax.should eq([:should, :expect]) - - 3.should eq(3) - 3.should_not eq(4) - expect(3).to eq(3) - end + configure_syntax :should + configure_syntax [:should, :expect] + configured_syntax.should eq([:should, :expect]) + + 3.should eq(3) + 3.should_not eq(4) + expect(3).to eq(3) end it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do et = Expectations::ExpectationTarget - sandboxed do - configure_syntax :should - et.new(Proc.new {}).should be_an(et) - et.new(Proc.new {}).should_not be_a(Proc) - end + configure_syntax :should + et.new(Proc.new {}).should be_an(et) + et.new(Proc.new {}).should_not be_a(Proc) end it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do - sandboxed do - configure_syntax :expect - expect(expect(3)).not_to respond_to(:should) - expect(expect(3)).not_to respond_to(:should_not) - end + configure_syntax :expect + expect(expect(3)).not_to respond_to(:should) + expect(expect(3)).not_to respond_to(:should_not) end context 'when both :expect and :should are enabled' do - before { RSpec.stub(:warn) } + before { allow(RSpec).to receive(:deprecate) } it 'allows `expect {}.should` to be used' do - sandboxed do - configure_syntax [:should, :expect] - expect { raise "boom" }.should raise_error("boom") - expect { }.should_not raise_error - end + configure_syntax [:should, :expect] + expect { raise "boom" }.should raise_error("boom") + expect { }.should_not raise_error end it 'prints a deprecation notice when `expect {}.should` is used' do - sandboxed do - configure_syntax [:should, :expect] + configure_syntax [:should, :expect] - RSpec.should_receive(:warn).with(/please use `expect \{ \}.to.*instead/) - expect { raise "boom" }.should raise_error("boom") + expect(RSpec).to receive(:deprecate) + expect { raise "boom" }.should raise_error("boom") - RSpec.should_receive(:warn).with(/please use `expect \{ \}.to_not.*instead/) - expect { }.should_not raise_error - end + expect(RSpec).to receive(:deprecate) + expect { }.should_not raise_error end end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/description_generation_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/description_generation_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/description_generation_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/description_generation_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -107,11 +107,25 @@ expect(RSpec::Matchers.generated_description).to eq "should have at most 4 players" end - it "expect(...).to include" do + it "expect(...).to include(x)" do expect([1,2,3]).to include(3) expect(RSpec::Matchers.generated_description).to eq "should include 3" end + it "expect(...).to include(x) when x responds to description but is not a matcher" do + obj = double(:description => "description", :inspect => "inspect") + expect([obj]).to include(obj) + expect(RSpec::Matchers.generated_description).to eq "should include inspect" + end + + it "expect(...).to include(x) when x responds to description and is a matcher" do + matcher = double(:description => "description", + :matches? => true, + :failure_message_for_should => "") + expect([matcher]).to include(matcher) + expect(RSpec::Matchers.generated_description).to eq "should include description" + end + it "expect(array).not_to match_array [1,2,3]" do expect([1,2,3]).to match_array [1,2,3] expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3" @@ -171,6 +185,6 @@ it "provides a helpful message when used in a string-less example block" do expect(5).to matcher - expect(RSpec::Matchers.generated_description).to match /When you call.*description method/m + expect(RSpec::Matchers.generated_description).to match(/When you call.*description method/m) end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/exist_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/exist_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/exist_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/exist_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -8,7 +8,7 @@ end context "when the object does not respond to #exist? or #exists?" do - subject { mock } + subject { double } [:to, :not_to].each do |expect_method| describe "expect(...).#{expect_method} exist" do @@ -25,12 +25,12 @@ context "when the object responds to ##{predicate}" do describe "expect(...).to exist" do it "passes if #{predicate}" do - expect(mock(predicate => true)).to exist + expect(double(predicate => true)).to exist end it "fails if not #{predicate}" do expect { - expect(mock(predicate => false)).to exist + expect(double(predicate => false)).to exist }.to fail_with(/expected .* to exist/) end @@ -51,12 +51,12 @@ describe "expect(...).not_to exist" do it "passes if not #{predicate}" do - expect(mock(predicate => false)).not_to exist + expect(double(predicate => false)).not_to exist end it "fails if #{predicate}" do expect { - expect(mock(predicate => true)).not_to exist + expect(double(predicate => true)).not_to exist }.to fail_with(/expected .* not to exist/) end end @@ -65,7 +65,7 @@ context "when the object responds to #exist? and #exists?" do context "when they both return falsey values" do - subject { mock(:exist? => false, :exists? => nil) } + subject { double(:exist? => false, :exists? => nil) } describe "expect(...).not_to exist" do it "passes" do @@ -83,7 +83,7 @@ end context "when they both return truthy values" do - subject { mock(:exist? => true, :exists? => "something true") } + subject { double(:exist? => true, :exists? => "something true") } describe "expect(...).not_to exist" do it "fails" do @@ -101,7 +101,7 @@ end context "when they return values with different truthiness" do - subject { mock(:exist? => true, :exists? => false) } + subject { double(:exist? => true, :exists? => false) } [:to, :not_to].each do |expect_method| describe "expect(...).#{expect_method} exist" do @@ -116,7 +116,7 @@ end it 'passes any provided arguments to the call to #exist?' do - object = mock + object = double object.should_receive(:exist?).with(:foo, :bar) { true } expect(object).to exist(:foo, :bar) diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/has_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/has_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/has_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/has_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -117,6 +117,6 @@ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end expect { expect(o).to have_key(:a) - }.to_not raise_error + }.not_to raise_error end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/have_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/have_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/have_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/have_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -326,13 +326,13 @@ describe "have(n).items(args, block)" do it "passes args to target" do - target = mock("target") + target = double("target") target.should_receive(:items).with("arg1","arg2").and_return([1,2,3]) expect(target).to have(3).items("arg1","arg2") end it "passes block to target" do - target = mock("target") + target = double("target") block = lambda { 5 } target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3]) expect(target).to have(3).items("arg1","arg2", block) @@ -402,6 +402,16 @@ end end + if RUBY_VERSION >= '2.0' + describe RSpec::Matchers::BuiltIn::Have, "for an Enumerator whose size is nil but count is supplied" do + let(:enumerator) { %w[a b c d].to_enum(:each) } + + it 'works fine' do + expect(enumerator).to have(4).items + end + end + end + describe RSpec::Matchers::BuiltIn::Have do it "has method_missing as private" do expect(described_class.private_instance_methods).to include_method(:method_missing) diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/include_matcher_integration_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/include_matcher_integration_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/include_matcher_integration_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/include_matcher_integration_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -22,8 +22,8 @@ end it "works with be_[some predicate]" do - expect([stub("actual", :happy? => true)]).to include( be_happy ) - expect([stub("actual", :happy? => false)]).not_to include( be_happy ) + expect([double("actual", :happy? => true)]).to include( be_happy ) + expect([double("actual", :happy? => false)]).not_to include( be_happy ) end end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/include_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/include_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/include_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/include_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -137,7 +137,7 @@ end end - describe "expect(...).to_not include(expected)" do + describe "expect(...).not_to include(expected)" do context "for a string target" do it "passes if target does not include expected" do expect("abc").not_to include("d") @@ -188,7 +188,7 @@ end - describe "expect(...).to_not include(with, multiple, args)" do + describe "expect(...).not_to include(with, multiple, args)" do context "for a string target" do it "passes if the target does not include any of the expected" do expect("abc").not_to include("d", "e", "f") @@ -280,7 +280,7 @@ end end - describe "expect(...).to_not include(:key => value)" do + describe "expect(...).not_to include(:key => value)" do context 'for a hash target' do it "fails if target includes the key/value pair" do expect { @@ -364,7 +364,7 @@ end end - describe "expect(...).to_not include(:key1 => value1, :key2 => value2)" do + describe "expect(...).not_to include(:key1 => value1, :key2 => value2)" do context 'for a hash target' do it "fails if target includes the key/value pairs" do expect { diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/match_array_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/match_array_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/match_array_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/match_array_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -156,7 +156,7 @@ end end -describe "expect(...).to_not match_array [:with, :multiple, :args]" do +describe "expect(...).not_to match_array [:with, :multiple, :args]" do it "is not supported" do expect { expect([1,2,3]).not_to match_array [1,2,3] diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/match_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/match_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -32,7 +32,7 @@ end end -describe "expect(...).to_not match(expected)" do +describe "expect(...).not_to match(expected)" do it "passes when target (String) matches does not match (Regexp)" do expect("string").not_to match(/rings/) end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/raise_error_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/raise_error_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/raise_error_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/raise_error_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -10,6 +10,25 @@ expect {raise}.to raise_error end + it "passes if an error instance is expected" do + s = StandardError.new + expect {raise s}.to raise_error(s) + end + + it "fails if a different error instance is thrown from the one that is expected" do + s = StandardError.new("Error 1") + to_raise = StandardError.new("Error 2") + expect do + expect {raise to_raise}.to raise_error(s) + end.to fail_with(Regexp.new("expected #{s.inspect}, got #{to_raise.inspect} with backtrace")) + end + + it "passes if an error class is expected and an instance of that class is thrown" do + s = StandardError.new :bees + + expect { raise s }.to raise_error(StandardError) + end + it "fails if nothing is raised" do expect { expect {}.to raise_error @@ -41,36 +60,53 @@ end end -describe "expect { ... }.to_not raise_error" do - it "passes if nothing is raised" do - expect {}.to_not raise_error - end +describe "expect { ... }.not_to raise_error" do - it "fails if anything is raised" do - expect { - expect { raise RuntimeError, "example message" }.to_not raise_error - }.to fail_with(/expected no Exception, got #/) - end + context "with a specific error class" do + it "is deprecated" do + RSpec.should_receive :deprecate + expect {"bees"}.not_to raise_error(RuntimeError) + end + end + + context "with no specific error class" do + it "is not deprecated" do + run = nil + allow(RSpec).to receive(:deprecate) { run = true } + expect {"bees"}.not_to raise_error + expect(run).to be_nil + end + + it "passes if nothing is raised" do + expect {}.not_to raise_error + end - it 'includes the backtrace of the error that was raised in the error message' do - expect { - expect { raise "boom" }.not_to raise_error - }.to raise_error { |e| - backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}" - expect(e.message).to include("with backtrace", backtrace_line) - } - end + it "fails if anything is raised" do + expect { + expect { raise RuntimeError, "example message" }.not_to raise_error + }.to fail_with(/expected no Exception, got #/) + end - it 'formats the backtrace using the configured backtrace formatter' do - RSpec::Matchers.configuration.backtrace_formatter. - stub(:format_backtrace). - and_return("formatted-backtrace") + it 'includes the backtrace of the error that was raised in the error message' do + expect { + expect { raise "boom" }.not_to raise_error + }.to raise_error { |e| + backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}" + expect(e.message).to include("with backtrace", backtrace_line) + } + end - expect { - expect { raise "boom" }.not_to raise_error - }.to raise_error { |e| - expect(e.message).to include("with backtrace", "formatted-backtrace") - } + it 'formats the backtrace using the configured backtrace formatter' do + RSpec::Matchers.configuration.backtrace_formatter. + stub(:format_backtrace). + and_return("formatted-backtrace") + + expect { + expect { raise "boom" }.not_to raise_error + }.to raise_error { |e| + expect(e.message).to include("with backtrace", "formatted-backtrace") + } + end end end @@ -109,24 +145,33 @@ end end -describe "expect { ... }.to_not raise_error(message)" do +describe "expect { ... }.not_to raise_error(message)" do + before do + allow(RSpec).to receive(:deprecate) + end + + it "is deprecated" do + expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(message\)/, :replacement =>"`expect { }.not_to raise_error()`") + expect {raise 'blarg'}.not_to raise_error('blah') + end + it "passes if RuntimeError error is raised with the different message" do - expect {raise 'blarg'}.to_not raise_error('blah') + expect {raise 'blarg'}.not_to raise_error('blah') end it "passes if any other error is raised with the wrong message" do - expect {raise NameError.new('blarg')}.to_not raise_error('blah') + expect {raise NameError.new('blarg')}.not_to raise_error('blah') end it "fails if RuntimeError is raised with message" do expect do - expect {raise 'blah'}.to_not raise_error('blah') + expect {raise 'blah'}.not_to raise_error('blah') end.to fail_with(/expected no Exception with "blah", got #/) end it "fails if any other error is raised with message" do expect do - expect {raise NameError.new('blah')}.to_not raise_error('blah') + expect {raise NameError.new('blah')}.not_to raise_error('blah') end.to fail_with(/expected no Exception with "blah", got #/) end end @@ -155,18 +200,27 @@ end end -describe "expect { ... }.to_not raise_error(NamedError)" do +describe "expect { ... }.not_to raise_error(NamedError)" do + before do + allow(RSpec).to receive(:deprecate) + end + + it "is deprecated" do + expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass\)/, :replacement => "`expect { }.not_to raise_error()`") + expect { }.not_to raise_error(NameError) + end + it "passes if nothing is raised" do - expect { }.to_not raise_error(NameError) + expect { }.not_to raise_error(NameError) end it "passes if another error is raised" do - expect { raise }.to_not raise_error(NameError) + expect { raise }.not_to raise_error(NameError) end it "fails if named error is raised" do expect { - expect { 1 + 'b' }.to_not raise_error(TypeError) + expect { 1 + 'b' }.not_to raise_error(TypeError) }.to fail_with(/expected no TypeError, got #"`expect { }.not_to raise_error()`") + expect {}.not_to raise_error(RuntimeError, "example message") + end + + it "passes if nothing is raised" do + expect {}.not_to raise_error(RuntimeError, "example message") + end + + it "passes if a different error is raised" do + expect { raise }.not_to raise_error(NameError, "example message") + end + + it "passes if same error is raised with different message" do + expect { raise RuntimeError.new("not the example message") }.not_to raise_error(RuntimeError, "example message") + end + + it "fails if named error is raised with same message" do + expect { + expect { raise "example message" }.not_to raise_error(RuntimeError, "example message") + }.to fail_with(/expected no RuntimeError with \"example message\", got #/) + end +end + +describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp" do + it "passes if named error is raised with matching message" do + expect { raise "example message" }.to raise_error(RuntimeError, /ample mess/) + end + + it "fails if nothing is raised" do + expect { + expect {}.to raise_error(RuntimeError, /ample mess/) + }.to fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/) + end + + it "fails if incorrect error is raised" do + expect { + expect { raise RuntimeError, "example message" }.to raise_error(NameError, /ample mess/) + }.to fail_with(/expected NameError with message matching \/ample mess\/, got #/) + end + + it "fails if correct error is raised with incorrect message" do + expect { + expect { raise RuntimeError.new("not the example message") }.to raise_error(RuntimeError, /less than ample mess/) + }.to fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #/) + end +end + +describe "expect { ... }.not_to raise_error(NamedError, error_message) with Regexp" do + before do + allow(RSpec).to receive(:deprecate) + end + + it "is deprecated" do + expect(RSpec).to receive(:deprecate) + expect {}.not_to raise_error(RuntimeError, /ample mess/) + end + + it "passes if nothing is raised" do + expect {}.not_to raise_error(RuntimeError, /ample mess/) + end + + it "passes if a different error is raised" do + expect { raise }.not_to raise_error(NameError, /ample mess/) + end + + it "passes if same error is raised with non-matching message" do + expect { raise RuntimeError.new("non matching message") }.not_to raise_error(RuntimeError, /ample mess/) + end + + it "fails if named error is raised with matching message" do + expect { + expect { raise "example message" }.not_to raise_error(RuntimeError, /ample mess/) + }.to fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #/) + end +end + describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }" do it "yields exception if named error is raised with same message" do ran = false @@ -268,11 +404,20 @@ end end -describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| ... }" do +describe "expect { ... }.not_to raise_error(NamedError, error_message) { |err| ... }" do + before do + allow(RSpec).to receive(:deprecate) + end + + it "is deprecated" do + expect(RSpec).to receive(:deprecate) + expect {}.not_to raise_error(RuntimeError, "example message") { |err| } + end + it "passes if nothing is raised" do ran = false - expect {}.to_not raise_error(RuntimeError, "example message") { |err| + expect {}.not_to raise_error(RuntimeError, "example message") { |err| ran = true } @@ -282,7 +427,7 @@ it "passes if a different error is raised" do ran = false - expect { raise }.to_not raise_error(NameError, "example message") { |err| + expect { raise }.not_to raise_error(NameError, "example message") { |err| ran = true } @@ -294,7 +439,7 @@ expect { raise RuntimeError.new("not the example message") - }.to_not raise_error(RuntimeError, "example message") { |err| + }.not_to raise_error(RuntimeError, "example message") { |err| ran = true } @@ -307,7 +452,7 @@ expect { expect { raise "example message" - }.to_not raise_error(RuntimeError, "example message") { |err| + }.not_to raise_error(RuntimeError, "example message") { |err| ran = true } }.to fail_with(/expected no RuntimeError with \"example message\", got #/) @@ -330,66 +475,11 @@ end end -describe "expect { ... }.to_not raise_error(NamedError, error_message) with String" do - it "passes if nothing is raised" do - expect {}.to_not raise_error(RuntimeError, "example message") - end - - it "passes if a different error is raised" do - expect { raise }.to_not raise_error(NameError, "example message") - end - - it "passes if same error is raised with different message" do - expect { raise RuntimeError.new("not the example message") }.to_not raise_error(RuntimeError, "example message") - end - - it "fails if named error is raised with same message" do - expect { - expect { raise "example message" }.to_not raise_error(RuntimeError, "example message") - }.to fail_with(/expected no RuntimeError with \"example message\", got #/) - end -end - -describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp" do - it "passes if named error is raised with matching message" do - expect { raise "example message" }.to raise_error(RuntimeError, /ample mess/) - end - - it "fails if nothing is raised" do - expect { - expect {}.to raise_error(RuntimeError, /ample mess/) - }.to fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/) - end - - it "fails if incorrect error is raised" do - expect { - expect { raise RuntimeError, "example message" }.to raise_error(NameError, /ample mess/) - }.to fail_with(/expected NameError with message matching \/ample mess\/, got #/) - end - - it "fails if correct error is raised with incorrect message" do - expect { - expect { raise RuntimeError.new("not the example message") }.to raise_error(RuntimeError, /less than ample mess/) - }.to fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #/) - end -end - -describe "expect { ... }.to_not raise_error(NamedError, error_message) with Regexp" do - it "passes if nothing is raised" do - expect {}.to_not raise_error(RuntimeError, /ample mess/) - end - - it "passes if a different error is raised" do - expect { raise }.to_not raise_error(NameError, /ample mess/) - end - - it "passes if same error is raised with non-matching message" do - expect { raise RuntimeError.new("non matching message") }.to_not raise_error(RuntimeError, /ample mess/) - end - - it "fails if named error is raised with matching message" do +describe "misuse of raise_error, with (), not {}" do + it "fails with warning" do + ::Kernel.should_receive(:warn).with(/`raise_error` was called with non-proc object 1\.7/) expect { - expect { raise "example message" }.to_not raise_error(RuntimeError, /ample mess/) - }.to fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #/) + expect(Math.sqrt(3)).to raise_error + }.to fail_with(/nothing was raised/) end end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/respond_to_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/respond_to_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/respond_to_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/respond_to_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -148,7 +148,7 @@ end end -describe "expect(...).to_not respond_to(:sym)" do +describe "expect(...).not_to respond_to(:sym)" do it "passes if target does not respond to :sym" do expect(Object.new).not_to respond_to(:some_method) end @@ -160,7 +160,7 @@ end end -describe "expect(...).to_not respond_to(:sym).with(1).argument" do +describe "expect(...).not_to respond_to(:sym).with(1).argument" do it "fails if target responds to :sym with 1 arg" do obj = Object.new def obj.foo(arg); end @@ -209,7 +209,7 @@ end end -describe "expect(...).to_not respond_to(message1, message2)" do +describe "expect(...).not_to respond_to(message1, message2)" do it "passes if target does not respond to either message1 or message2" do expect(Object.new).not_to respond_to(:some_method, :some_other_method) end @@ -233,7 +233,7 @@ end end -describe "expect(...).to_not respond_to(:sym).with(2).arguments" do +describe "expect(...).not_to respond_to(:sym).with(2).arguments" do it "fails if target responds to :sym with 2 args" do obj = Object.new def obj.foo(a1, a2); end diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/satisfy_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/satisfy_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/satisfy_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/satisfy_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -28,7 +28,7 @@ end end -describe "expect(...).to_not satisfy { block }" do +describe "expect(...).not_to satisfy { block }" do it "passes if block returns false" do expect(false).not_to satisfy { |val| val } expect(false).not_to satisfy do |val| diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/start_with_end_with_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/start_with_end_with_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/start_with_end_with_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/start_with_end_with_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -56,7 +56,7 @@ end end -describe "expect(...).to_not start_with" do +describe "expect(...).not_to start_with" do context "with a string" do it "passes if it does not match the start of the actual string" do expect("this string").not_to start_with "that str" @@ -149,7 +149,7 @@ end -describe "expect(...).to_not end_with" do +describe "expect(...).not_to end_with" do context "with a sting" do it "passes if it does not match the end of the actual string" do expect("this string").not_to end_with "stringy" diff -Nru ruby-rspec-expectations-2.13.0/spec/rspec/matchers/yield_spec.rb ruby-rspec-expectations-2.14.2/spec/rspec/matchers/yield_spec.rb --- ruby-rspec-expectations-2.13.0/spec/rspec/matchers/yield_spec.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/rspec/matchers/yield_spec.rb 2013-08-15 17:28:02.000000000 +0000 @@ -63,10 +63,87 @@ }.to fail_with(/expected given block to yield control/) end - it 'raises an error if it yields multiple times' do - expect { - expect { |b| [1, 2].each(&b) }.to yield_control - }.to raise_error(/not designed.*yields multiple times/) + context "with exact count" do + it 'fails if the block yields wrong number of times' do + expect { + expect { |b| [1, 2, 3].each(&b) }.to yield_control.twice + }.to fail_with(/expected given block to yield control twice/) + + expect { + expect { |b| [1, 2].each(&b) }.to yield_control.exactly(3).times + }.to fail_with(/expected given block to yield control 3 times/) + end + + it 'passes if the block yields the specified number of times' do + expect { |b| [1].each(&b) }.to yield_control.once + expect { |b| [1, 2].each(&b) }.to yield_control.twice + expect { |b| [1, 2, 3].each(&b) }.to yield_control.exactly(3).times + end + end + + context "with at_least count" do + it 'passes if the block yields the given number of times' do + expect { |b| [1, 2].each(&b) }.to yield_control.at_least(2).times + expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_least(3).times + end + + it 'passes if the block yields more times' do + expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_least(2).times + expect { |b| [1, 2, 3, 4].each(&b) }.to yield_control.at_least(3).times + end + + it 'allows :once and :twice to be passed as counts' do + expect { |b| [1].each(&b) }.to yield_control.at_least(:once) + expect { |b| [1, 2].each(&b) }.to yield_control.at_least(:once) + + expect { + expect { |b| [].each(&b) }.to yield_control.at_least(:once) + }.to fail_with(/at least once/) + + expect { |b| [1, 2].each(&b) }.to yield_control.at_least(:twice) + expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_least(:twice) + + expect { + expect { |b| [1].each(&b) }.to yield_control.at_least(:twice) + }.to fail_with(/at least twice/) + end + + it 'fails if the block yields too few times' do + expect { + expect { |b| _yield_with_no_args(&b) }.to yield_control.at_least(2).times + }.to fail_with(/expected given block to yield control at least twice/) + end + end + + context "with at_most count" do + it 'passes if the block yields the given number of times' do + expect { |b| [1, 2].each(&b) }.to yield_control.at_most(2).times + expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_most(3).times + end + + it 'passes if the block yields fewer times' do + expect { |b| [1, 2].each(&b) }.to yield_control.at_most(3).times + end + + it 'allows :once and :twice to be passed as counts' do + expect { |b| [1].each(&b) }.to yield_control.at_most(:once) + + expect { + expect { |b| [1, 2].each(&b) }.to yield_control.at_most(:once) + }.to fail_with(/expected given block to yield control at most once/) + + expect { |b| [1, 2].each(&b) }.to yield_control.at_most(:twice) + + expect { + expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_most(:twice) + }.to fail_with(/expected given block to yield control at most twice/) + end + + it 'fails if the block yields too many times' do + expect { + expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_most(2).times + }.to fail_with(/expected given block to yield control at most twice/) + end end end diff -Nru ruby-rspec-expectations-2.13.0/spec/spec_helper.rb ruby-rspec-expectations-2.14.2/spec/spec_helper.rb --- ruby-rspec-expectations-2.13.0/spec/spec_helper.rb 2013-03-26 09:27:13.000000000 +0000 +++ ruby-rspec-expectations-2.14.2/spec/spec_helper.rb 2013-08-15 17:28:02.000000000 +0000 @@ -46,7 +46,7 @@ def with_test_unit_loaded in_sub_process do require 'test/unit' - load 'rspec/matchers.rb' + load 'rspec/matchers/test_unit_integration.rb' yield end end