RSpec 2.99 and 3.0 beta2 have been released!
Myron Marston
Feb 21, 2014The RSpec team has released 3.0.0.beta2 and 2.99.0.beta2.
This is a huge release that includes tons of new features. I plan to do a full blog post listing and giving examples for all the notable new 3.0 features at a later date. For now, I’ve just got the full release notes.
Thanks to all the contributors who helped make this release happen!
I also want to thank those of you who have put your projects though the upgrade process and have been using 3.0.0.beta1–your feedback has been invaluable.
For more details on the upgrade process, see the beta1 annoucement blog post.
This will be the last 2.99/3.0 beta release. Next up are the release candidates!
Release Notes
rspec-core 2.99.0.beta2
Enhancements:
- Add
is_expectedfor one-liners that read well with theexpect-based syntax.is_expectedis simply defined asexpect(subject)and can be used in an expression like:it { is_expected.to read_well }. (Myron Marston) - Backport
skipfrom RSpec 3, which acts likependingdid in RSpec 2 when not given a block, since the behavior ofpendingis changing in RSpec 3. (Xavier Shay)
Deprecations:
- Deprecate inexact
mock_withconfig options. RSpec 3 will only support the exact symbols:rspec,:mocha,:flexmock,:rror:nothing(or any module that implements the adapter interface). RSpec 2 did fuzzy matching but this will not be supported going forward. (Myron Marston) - Deprecate
show_failures_in_pending_blocksconfig option. To achieve the same behavior as the option enabled, you can use a custom formatter instead. (Xavier Shay) - Add a deprecation warning for the fact that the behavior of
pendingis changing in RSpec 3 – rather than skipping the example (as it did in 2.x when no block was provided), it will run the example and mark it as failed if no exception is raised. Useskipinstead to preserve the old behavior. (Xavier Shay) - Deprecate ‘s’, ‘n’, ‘spec’ and ‘nested’ as aliases for documentation formatter. (Jon Rowe)
- Deprecate
RSpec::Core::Reporter#abortin favor ofRSpec::Core::Reporter#finish. (Jon Rowe)
Bug Fixes:
- Fix failure (undefined method
path) in end-of-run summary whenraise_errors_for_deprecations!is configured. (Myron Marston) - Fix issue were overridding spec ordering from the command line wasn’t fully recognised interally. (Jon Rowe)
rspec-core 3.0.0.beta2
Breaking Changes for 3.0.0:
- Make
mock_withoption more strict. Strings are no longer supported (e.g.mock_with "mocha") – use a symbol instead. Also, unrecognized values will now result in an error rather than falling back to the null mocking adapter. If you want to use the null mocking adapter, usemock_with :nothing(as has been documented for a long time). (Myron Marston) - Remove support for overriding RSpec’s built-in
:ifand:unlessfilters. (Ashish Dixit) - Custom formatters are now required to call
RSpec::Core::Formatters.register(formatter_class, *notifications)wherenotificationsis the list of events the formatter wishes to be notified about. Notifications are handled by methods matching the names on formatters. This allows us to add or remove notifications without breaking existing formatters. (Jon Rowe) - Change arguments passed to formatters. Rather than passing multiple arguments (which limits are ability to add additional arguments as doing so would break existing formatters), we now pass a notification value object that exposes the same data via attributes. This will allow us to add new bits of data to a notification event without breaking existing formattesr. (Jon Rowe)
- Remove support for deprecated
:aliasoption forRSpec.configuration.add_setting. (Myron Marston) - Remove support for deprecated
RSpec.configuration.requires = [...]. (Myron Marston) - Remove support for deprecated
--formatterCLI option. (Myron Marston) - Remove support for deprecated
--configureCLI option. (Myron Marston) - Remove support for deprecated
RSpec::Core::RakeTask#spec_opts=. (Myron Marston) - An example group level
pendingblock or:pendingmetadata now executes the example and cause a failure if it passes, otherwise it will be pending if it fails. The old “never run” behaviour is still used forxexample,xit, andxspecify, or via a newskipmethod or:skipmetadata option. (Xavier Shay) - After calling
pendinginside an example, the remainder of the example will now be run. If it passes a failure is raised, otherwise the example is marked pending. The old “never run” behaviour is provided a by a newskipmethod. (Xavier Shay) - Pending blocks inside an example have been removed as a feature with no
direct replacement. Use
skiporpendingwithout a block. (Xavier Shay) - Pending statement is no longer allowed in
before(:all)hooks. Useskipinstead. (Xavier Shay) - Remove
show_failures_in_pending_blocksconfiguration option. (Xavier Shay) - Remove support for specifying the documentation formatter using ‘s’, ‘n’, ‘spec’ or ‘nested’. (Jon Rowe)
Enhancements:
- Add example run time to JSON formatter output. (Karthik Kastury)
- Add more suggested settings to the files generated by
rspec --init. (Myron Marston) - Add
config.alias_example_group_to, which can be used to define a new method that defines an example group with the provided metadata. (Michi Huber) - Add
xdescribeandxcontextas shortcuts to make an example group pending. (Myron Marston) - Add
fdescribeandfcontextas shortcuts to focus an example group. (Myron Marston) - Don’t autorun specs via
#at_exitby default.require 'rspec/autorun'is only needed when running specs viaruby, as it always has been. Running specs viarakeorrspecare both unaffected. (Ben Hoskings) - Add
expose_dsl_globallyconfig option, defaulting to true. When disabled it will remove the monkey patches rspec-core adds tomainandModule(e.g.describe,shared_examples_for, etc). (Jon Rowe) - Expose RSpec DSL entry point methods (
describe,shared_examples_for, etc) on theRSpecconstant. Intended for use whenexpose_dsl_globallyis set tofalse. (Jon Rowe) - For consistency, expose all example group aliases (including
context) on theRSpecconstant. Ifexpose_dsl_globallyis set totrue, also expose them onmainandModule. Historically, onlydescribewas exposed. (Jon Rowe, Michi Huber)
Bug Fixes:
- Fix failure (undefined method
path) in end-of-run summary whenraise_errors_for_deprecations!is configured. (Myron Marston) - Issue error when attempting to use -i or –I on command line, too close to -I to be considered short hand for –init. (Jon Rowe)
- Prevent adding formatters to an output target if the same formatter has already been added to that output. (Alex Peattie)
- Allow a matcher-generated example description to be used when the example is pending. (Myron Marston)
- Ensure the configured
failure_exit_codeis used by the rake task when there is a failure. (Jon Rowe) - Restore behaviour whereby system exclusion filters take priority over working directory (was broken in beta1). (Jon Rowe)
- Prevent RSpec mangling file names that have substrings containing
line_numberordefault_path. (Matijs van Zuijlen)
rspec-expectations 2.99.0.beta2
Deprecations:
- Deprecate chaining
by,by_at_least,by_at_mostortooff ofexpect { }.not_to change { }. The docs have always said these are not supported for the negative form but now they explicitly raise errors in RSpec 3. (Myron Marston) - Change the semantics of
expect { }.not_to change { x }.from(y). In RSpec 2.x, this expectation would only fail ifxstarted with the value ofyand changed. If it started with a different value and changed, it would pass. In RSpec 3, it will pass only if the value starts atyand it does not change. (Myron Marston) - Deprecate
matcher == valueas an alias formatcher.matches?(value), in favor ofmatcher === value. (Myron Marston) - Deprecate
RSpec::Matchers::OperatorMatcherin favor ofRSpec::Matchers::BuiltIn::OperatorMatcher. (Myron Marston) - Deprecate auto-integration with Test::Unit and minitest.
Instead, include
RSpec::Matchersin the appropriate test case base class yourself. (Myron Marston) - Deprecate treating
#expectedon a DSL-generated custom matcher as an array when only 1 argument is passed to the matcher method. In RSpec 3 it will be the single value in order to make diffs work properly. (Jon Rowe)
rspec-expectations 3.0.0.beta2
Breaking Changes for 3.0.0:
- Remove deprecated support for accessing the
RSpecconstant usingRspecorSpec. (Myron Marston) - Remove deprecated
RSpec::Expectations.differ=. (Myron Marston) - Remove support for deprecated
expect(...).should. (Myron Marston) - Explicitly disallow
expect { }.not_to change { }withby,by_at_least,by_at_mostorto. These have never been supported but did not raise explicit errors. (Myron Marston) - Provide
===rather than==as an alias ofmatches?for all matchers. The semantics of===are closer to an RSpec matcher than==. (Myron Marston) - Remove deprecated
RSpec::Matchers::OperatorMatcherconstant. (Myron Marston) - Make
RSpec::Expectations::ExpectationNotMetErrorsubclassExceptionrather thanStandardErrorso they can bypass a barerescuein end-user code (e.g. when an expectation is set from within a rspec-mocks stub implementation). (Myron Marston) - Remove Test::Unit and Minitest 4.x integration. (Myron Marston)
Enhancements:
- Simplify the failure message of the
bematcher when matching against:true,falseandnil. (Sam Phippen) - Update matcher protocol and custom matcher DSL to better align
with the newer
expectsyntax. If you want your matchers to maintain compatibility with multiple versions of RSpec, you can alias the new names to the old. (Myron Marston)failure_message_for_should=>failure_messagefailure_message_for_should_not=>failure_message_when_negatedmatch_for_should=>matchmatch_for_should_not=>match_when_negated
- Improve generated descriptions from
changematcher. (Myron Marston) - Add support for compound matcher expressions using
andandor. Simply chain them off of any existing matcher to create an expression likeexpect(alphabet).to start_with("a").and end_with("z"). (Eloy Espinaco) - Add
contain_exactlyas a less ambiguous version ofmatch_array. Note that it expects the expected array to be splatted as individual args:expect(array).to contain_exactly(1, 2)is the same asexpect(array).to match_array([1, 2]). (Myron Marston) - Update
contain_exactly/match_arrayso that it can match against other non-array collections (such as aSet). (Myron Marston) - Update built-in matchers so that they can accept matchers as arguments to allow you to compose matchers in arbitrary ways. (Myron Marston)
- Add
RSpec::Matchers::Composablemixin that can be used to make a custom matcher composable as well. Note that custom matchers defined viaRSpec::Matchers.definealready have this. (Myron Marston) - Define noun-phrase aliases for built-in matchers, which can be used when creating composed matcher expressions that read better and provide better failure messages. (Myron Marston)
- Add
RSpec::Machers.alias_matcherso users can define their own matcher aliases. Thedescriptionof the matcher will reflect the alternate matcher name. (Myron Marston) - Add explicit
be_betweenmatcher.be_betweenhas worked for a long time as a dynamic predicate matcher, but the failure message was suboptimal. The new matcher provides a much better failure message. (Erik Michaels-Ober) - Enhance the
be_betweenmatcher to allow forinclusiveorexclusivecomparison (e.g. inclusive of min/max or exclusive of min/max). (Pedro Gimenez) - Make failure message for
not_to be #{operator}less confusing by only saying it’s confusing when comparison operators are used. (Prathamesh Sonpatki) - Improve failure message of
eqmatcher whenTimeorDateTimeobjects are used so that the full sub-second precision is included. (Thomas Holmes, Jeff Wallace) - Add
outputmatcher for expecting that a block outputsto_stdoutorto_stderr. (Luca Pette, Matthias Günther) - Forward a provided block on to the
has_xyz?method call when thehave_xyzmatcher is used. (Damian Galarza) - Provide integration with Minitest 5.x. Require
rspec/expectations/minitest_integrationafter loading minitest to use rspec-expectations with minitest. (Myron Marston)
Bug Fixes:
- Fix wrong matcher descriptions with falsey expected value (yujinakayama)
- Fix
expect { }.not_to change { }.from(x)so that the matcher only passes if the starting value isx. (Tyler Rick, Myron Marston) - Fix hash diffing, so that it colorizes properly and doesn’t consider trailing commas when performing the diff. (Jared Norman)
- Fix built-in matchers to fail normally rather than raising
ArgumentErrorwhen given an object of the wrong type to match against, so that they work well in composite matcher expressions likeexpect([1.51, "foo"]).to include(a_string_matching(/foo/), a_value_within(0.1).of(1.5)). (Myron Marston)
Deprecations:
- Retain support for RSpec 2 matcher protocol (e.g. for matchers
in 3rd party extension gems like
shoulda), but it will print a deprecation warning. (Myron Marston)
rspec-mocks 2.99.0.beta2
Deprecations:
- Deprecate
RSpec::Mocks::Mockin favor ofRSpec::Mocks::Double. (Myron Marston) - Deprecate the
hostargument ofRSpec::Mocks.setup. InsteadRSpec::Mocks::ExampleMethodsshould be included directly in the scope where RSpec’s mocking capabilities are used. (Sam Phippen) - Deprecate using any of rspec-mocks’ features outside the per-test
lifecycle (e.g. from a
before(:all)hook). (Myron Marston) - Deprecate re-using a test double in another example. (Myron Marston)
- Deprecate
and_return { value }andand_returnwithout arguments. (Yuji Nakayama)
rspec-mocks 3.0.0.beta2
Breaking Changes for 3.0.0:
- Rename
RSpec::Mocks::MocktoRSpec::Mocks::Double. (Myron Marston) - Change how to integrate rspec-mocks in other test frameworks. You now
need to include
RSpec::Mocks::ExampleMethodsin your test context. (Myron Marston) - Prevent RSpec mocks’ doubles and partial doubles from being used outside of
the per-test lifecycle (e.g. from a
before(:all)hook). (Sam Phippen) - Remove the
hostargument ofRSpec::Mocks.setup. InsteadRSpec::Mocks::ExampleMethodsshould be included directly in the scope where RSpec’s mocking capabilities are used. (Sam Phippen) - Make test doubles raise errors if you attempt to use them after they get reset, to help surface issues when you accidentally retain references to test doubles and attempt to reuse them in another example. (Myron Marston)
- Remove support for
and_return { value }andand_returnwithout arguments. (Yuji Nakayama)
Enhancements:
- Add
receive_message_chainwhich provides the functionality of the oldstub_chainfor the new allow/expect syntax. Use it like so:allow(...).to receive_message_chain(:foo, :bar, :bazz). (Sam Phippen). - Change argument matchers to use
===as their primary matching protocol, since their semantics mirror that of a case or rescue statement (which uses===for matching). (Myron Marston) - Add
RSpec::Mocks.with_temporary_scope, which allows you to create temporary rspec-mocks scopes in arbitrary places (such as abefore(:all)hook). (Myron Marston) - Support keyword arguments when checking arity with verifying doubles. (Xavier Shay)
Bug Fixes:
- Fix regression in 3.0.0.beta1 that caused
double("string_name" => :value)to stop working. (Xavier Shay) - Fix the way rspec-mocks and rspec-core interact so that if users
define a
letwith the same name as one of the methods fromRSpec::Mocks::ArgumentMatchers, the user’slettakes precedence. (Michi Huber, Myron Marston) - Fix verified doubles so that their methods match the visibility (public, protected or private) of the interface they verify against. (Myron Marston)
- Fix verified null object doubles so that they do not wrongly report that they respond to anything. They only respond to methods available on the interface they verify against. (Myron Marston)
- Fix deprecation warning for use of old
:shouldsyntax w/o explicit config so that it no longer is silenced by an extension gem such as rspec-rails when it callsconfig.add_stub_and_should_receive_to. (Sam Phippen) - Fix
expectsyntax so that it does not wrongly emit a “You’re overriding a previous implementation for this stub” warning when you are not actually doing that. (Myron Marston) - Fix
any_instance.unstubwhen used on sub classes for whom the super class has hadany_instance.stubinvoked on. (Jon Rowe) - Fix regression in
stub_chain/receive_message_chainthat caused it to raise anArgumentErrorwhen passing args to the stubbed methods. (Sam Phippen) - Correct stub of undefined parent modules all the way down when stubbing a nested constant. (Xavier Shay)
- Raise
VerifyingDoubleNotDefinedErrorwhen a constant is not defined for a verifying class double. (Maurício Linhares) - Remove
Double#to_str, which caused confusingraise some_doublebehavior. (Maurício Linhares)
rspec-rails 2.99.0.beta2
Deprecations:
- Deprecates the
--webratoption to the scaffold and request spec generator (Andy Lindeman) - Deprecates the use of
Capybara::DSL(e.g.,visit) in controller specs. It is more appropriate to use capybara in feature specs (spec/features) instead. (Andy Lindeman)
Bug Fixes:
- Use
__send__rather thansendto prevent naming collisions (Bradley Schaefer) - Supports Rails 4.1. (Andy Lindeman)
- Loads ActiveSupport properly to support changes in Rails 4.1. (Andy Lindeman)
- Anonymous controllers inherit from
ActionController::BaseifApplicationControlleris not present. (Jon Rowe)
rspec-rails 3.0.0.beta2
Breaking Changes for 3.0.0:
- Removes the
--webratoption for the request spec generator (Andy Lindeman) - Methods from
Capybara::DSL(e.g.,visit) are no longer available in controller specs. It is more appropriate to use capybara in feature specs (spec/features) instead. (Andy Lindeman) infer_base_class_for_anonymous_controllersis enabled by default. (Thomas Holmes)- Capybara 2.2.0 or above is required for feature specs. (Andy Lindeman)
Enhancements:
- Improve
be_validmatcher for non-ActiveModel::Errors implementations (Ben Hamill)
Bug Fixes:
- Use
__send__rather thansendto prevent naming collisions (Bradley Schaefer) - Supports Rails 4.1. (Andy Lindeman)
- Routes are drawn correctly for anonymous controllers with abstract parents. (Billy Chan)
- Loads ActiveSupport properly to support changes in Rails 4.1. (Andy Lindeman)
- Anonymous controllers inherit from
ActionController::BaseifApplicationControlleris not present. (Jon Rowe) - Require
rspec/collection_matcherswhenrspec/railsis required. (Yuji Nakayama)