In shoulda’s case, it’s a project that can be used in and out of Rails. It’s a
pain to have both a plugin and a gem.

Ryan McGeary and Josh Nichols did the bulk of this conversion and related
refactoring. They deserve extra acclaim because they’ve made it easier for
everyone to contribute to shoulda.

Improvements to current macros

should_assign_to now takes an :equals option. This is now the preferred way to
use should_assign_to for edit, show, update, and destroy actions because it is
a better test when you explicitly compare assigns(:user) to an expected
object.

should_assign_to :user, :equals => "@user"

should_assign_to also now takes a :class option. This is especially good for
new actions.

should_assign_to :user, :class => User

should_have_one now supports the :dependent option.

should_have_one :address, :dependent => :destroy

ActiveRecord::Errors.default_error_messages is used instead of home-brewed
regexes for all Active Record macros.

New Macros

should_change creates a test asserting a change between the return value of an
expression that is run before and after the current setup block is run. This is
similar to Active Support’s assert_difference assertion, but supports more
than just numeric values.

should_return_from_session creates a test asserting that a value returned from
the session is correct. The given string is evaled to produce the resulting
redirect path. All of the instance variables set by the controller are
available to the evaled string.

should_return_from_session :user_id, "@user.id"

Before statements

Before statements are should statements that run before the current context’s
setup. These are especially useful when setting expectations.

class UserControllerTest < Test::Unit::TestCase
context "the index action" do
setup do
@users = [Factory(:user)]
User.stubs(:find).returns(@users)
end
context "on GET" do
setup { get :index }
should_respond_with :success
# runs before "get :index"
before_should "find all users" do
User.expects(:find).with(:all).returns(@users)
end
end
end
end

should_be_restful is being deprecated

should_be_restful will be removed in a future release. It is currently in a
grace period where you’ll see a warning during your test runs. It will be added
to the new woulda gem if you care to keep
using it. Its problems:

It dissuades the programmer from good TDD practice. It’s working at too high level of
abstraction and encourages the programmer to take too many big steps.

It is an attempt to be like Rails scaffolding, which is a good way to learn
REST, but the syntax is so cryptic it doesn’t accomplish that goal.

It’s near impossible to find the line in your test file that is actually
failing or erroring.

You have no idea how many tests it generates or how they’re implemented, which
lulls the programmer into a false sense of security.