RSpec-1.1.4
May 27th, 2008
We released RSpec-1.1.4 today. It’s mostly a maintenance release but there are a few of cool new features that you may want to know about and take advantage of.
<h3>hash_including</h3>
<p>One thing that has always been a drag is having to specify every key/value pair in a hash that is received as an argument. This is especially painful in Rails controller examples because Rails adds some data to the hash and the examples really don’t care about that extra data.</p>
<p>Enter <code>hash_including()</code>.</p>
<p>This is a mock argument matcher that let’s you expect a hash including certain key/value pairs regardless of anything else that shows up in the hash. So instead of:</p>
account.should_receive(:deposit).with({:amount => 37.42, :date => anything()})
you can just say:
account.should_receive(:deposit).with(hash_including(:amount => 37.42))
and keep the example focused on what you’re really interested in
<p>Thanks to <a href="http://talklikeaduck.denhaven2.com/">Rick DeNatale</a> who submitted this feature request and the patch to implement it.</p>
<h3>The heckler returns</h3>
<p>RSpec wasn’t correctly supporting heckle for a while but the spec-heckler is back in action. For those unfamiliar, you can read about heckle at <a href="http://blog.zenspider.com/2007/06/heckle-version-141-has-been-re.html">zenspider’s blog</a>.</p>
<p>Here’s how you heckle your Animal model in your PetStore app:</p>
spec spec/models/animal_spec.rb --heckle Animal
Thanks to Antti Tarvainen for resurrecting this one.
<h3>stub_model</h3>
<p>This is for rails developers who like writing view examples with <code>mock_model()</code> but are sick and tired of having to stub every single attribute that gets referenced in a view.</p>
<p>Instead of creating a mock object like <code>mock_model()</code> does, <code>stub_model()</code> creates an instance of a real model class, but cuts off it’s connection to the database, raising an error any time it tries to connect to the database.</p>
<p>This is inspired by projects like <a href="http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database">unit_record</a> and <a href="http://agilewebdevelopment.com/plugins/nulldb">NullDB</a>, but let’s you do things at a more granular level – allowing you to hit the db in some cases (where you think you really need it) and not in others.</p>
<p>Of course, you may prefer to the sort of “protection” you get from those projects, which ensure that no code touches the DB at all. If you do, have at it. This is just another option for you.</p>
<h3>All this and more</h3>
<p>These are just a few of the issues addressed in 1.1.4. For more information, check out the <a href="http://rspec.info/changes.html">changelog</a> and <a href="http://rspec.lighthouseapp.com/projects/5645">lighthouse</a>.</p>



May 27th, 2008 at 1:07 am
Thanks for the great piece of software, it made my life a lot easier. I just noticed that I don’t get the current 1.1.4 Version via svn when doing a svn update with the externals pointing to the CURRENT tag.
May 27th, 2008 at 1:07 am
its on github.com now.
May 27th, 2008 at 1:07 am
Congrats on the release. FYI, if you’re using Mocha for your mocking/stubbing, it has the equivalent functinoality to hash_including but with a different API:
no error raised
object = mock() object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) object.method_1('key_1' => 1, 'key_2' => 99)
error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
It also has has_entry, has_key and has_value.
May 27th, 2008 at 1:07 am
The problem is that the rspec.info site doesn’t yet have update installation instructions.
May 27th, 2008 at 1:07 am
Thank you! I am very excited about stub_model, as we have also experienced the excessive stubbing in our view specs. Keep up the good work!
May 27th, 2008 at 1:07 am
Theres also the NestedTextFormatter, which prints out your spec output in a way that follows how you nested your ExampleGroups and Examples.
end end
Prints out:
To give it a shot, pass in:
or