I’ve just released RSpec 2.13. It’s a minor release containing a few backward-compatible enhancements and lots of bug fixes. It is a recommended upgrade for all users.
Thanks to all the contributors who helped make this RSpec release happen.
Notable New Features
Profile more than 10 examples
RSpec has featured a
--profile option for a long time. It dumps a report of the 10 slowest examples. Now you can pass a numeric option to have it print more than 10 examples.
To print off the 15 slowest examples, you could use:
subject declarations can use
Users have requested this for a while. This allows to override a
subject declaration in a nested group while delegating to the original definition from the parent group. Just use
Note that to use this feature, you must use explicit parens in the call to
super; otherwise ruby will give you an ugly
implicit argument passing of super from method defined by
define_method() is not supported error.
be_within matcher supports percent deltas
This is best illustrated by an example:
include matcher can accept a list of matchers
This is handy when you want to verify something about the items in a list rather that simply verifying the items’ identity.
--profileoption to take a count argument that determines the number of slow examples to dump (Greggory Rothmeier).
subject!that is the analog to
let!. It defines an explicit subject and sets a
beforehook that will invoke the subject (Zubin Henner).
subjectdeclaration so that
returncan be used in them, just like in a normal method. (Myron Marston)
- Allow output colors to be configured individually. (Charlie Maffitt)
- Don’t blow up when dumping error output for instances of anonymous error classes (Myron Marston).
- Fix default backtrace filters so lines from projects containing “gems” in the name are not filtered, but lines from installed gems still are (Myron Marston).
- Fix autotest command so that is uses double quotes rather than single quotes for windows compatibility (Jonas Tingeborn).
itsso that uses of
letdeclaration in the parent group continue to reference the parent group’s subject. (Olek Janiszewski)
- Add support for percent deltas to
expect(value).to be_within(10).percent_of(expected)(Myron Marston).
- Add support to
includematcher to allow it to be given a list of matchers as the expecteds to match against (Luke Redpath).
changematcher so that it dups strings in order to handle mutated strings (Myron Marston).
should be =~ /some regex//
expect(...).to be =~ /some regex/. Previously, these either failed with a confusing
undefined method matches?' for false:FalseClasserror or were no-ops that didn’t actually verify anything (Myron Marston).
- Add compatibility for diff-lcs 1.2 and relax the version constraint (Peter Goldstein).
- Fix DSL-generated matchers to allow multiple instances of the same matcher in the same example to have different description and failure messages based on the expected value (Myron Marston).
undefined method #split for Arrayerror when dumping the diff of an array of multiline strings (Myron Marston).
- Don’t blow up when comparing strings that are in an encoding that is not ASCII compatible (Myron Marston).
- Remove confusing “Check the implementation of #==” message printed for empty diffs (Myron Marston).
- Fix bug that caused weird behavior when a method that had previously been stubbed with multiple return values (e.g.
obj.stub(:foo).and_return(1, 2)) was later mocked with a single return value (e.g.
obj.should_receive(:foo).once.and_return(1)). (Myron Marston)
- Fix bug related to a mock expectation for a method that already had multiple stubs with different
withconstraints. Previously, the first stub was used, even though it may not have matched the passed args. The fix defers this decision until the message is received so that the proper stub response can be chosen based on the passed arguments (Myron Marston).
- Do not call
nil?extra times on a mocked object, in case
nil?itself is expected a set number of times (Myron Marston).
missing_default_stub_errormessage so array args are handled properly (Myron Marston).
- Explicitly disallow
any_instancestubbing so that it works with
Delegatorsubclasses (Myron Marston).
and_call_originalso that it works with
Delegatorsubclasses (Myron Marston).
any_instance.should_receiveis used on the same class in the same example. Previously it would wrongly report a failure even when the message was not received (Myron Marston).
be_validmatcher includes validation error messages. (Tom Scott)
- Adds cucumber scenario showing how to invoke an anonymous controller’s non-resourceful actions. (Paulo Luis Franchini Casaretto)
- Null template handler is used when views are stubbed. (Daniel Schierbeck)
- The generated
spec_helper.rbin Rails 4 includes a check for pending migrations. (Andy Lindeman)
rake spec:featurestask. (itzki)
- Rake tasks are automatically generated for each spec/ directory. (Rudolf Schmidt)