diff --git a/README.rdoc b/README.rdoc index b83b981e..ff86ab0a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -51,23 +51,25 @@ Quick macro tests for your ActiveRecord associations and validations: class PostTest < Test::Unit::TestCase fixtures :all - should_belong_to :user - should_have_many :tags, :through => :taggings + should belong_to(:user) + should have_many(:tags).through(:taggings) - should_validate_uniqueness_of :title - should_validate_presence_of :body, :message => /wtf/ - should_validate_presence_of :title - should_validate_numericality_of :user_id + should validate_uniqueness_of(:title) + should validate_presence_of(:body).with_message(/wtf/) + should validate_presence_of(:title) + should validate_numericality_of(:user_id) end class UserTest < Test::Unit::TestCase - should_have_many :posts + should have_many(:posts) - should_not_allow_values_for :email, "blah", "b lah" - should_allow_values_for :email, "a@b.com", "asdf@asdf.com" - should_ensure_length_in_range :email, 1..100 - should_ensure_value_in_range :age, 1..100 - should_not_allow_mass_assignment_of :password + should_not allow_value("blah").for(:email) + should_not allow_value("b lah").for(:email) + should allow_value("a@b.com").for(:email) + should allow_value("asdf@asdf.com").for(:email) + should ensure_inclusion_of(:email).in_range(1..100) + should ensure_inclusion_of(:age).in_range(1..100) + should_not allow_mass_assignment_of(:password) end Makes TDD so much easier. @@ -82,10 +84,10 @@ Macros to test the most common controller patterns... get :show, :id => 1 end - should_assign_to :user - should_respond_with :success - should_render_template :show - should_not_set_the_flash + should assign_to(:user) + should respond_with(:success) + should render_template(:show) + should_not set_the_flash should "do something else really cool" do assert_equal 1, assigns(:user).id @@ -101,18 +103,6 @@ More to come here, but have fun with what's there. assert_contains(['a', '1'], /\d/) assert_contains(['a', '1'], 'a') -=== 3rd Party and Application Specific Macros - -Any *.rb file under RAILS_ROOT/test/shoulda_macros/ or vendor/(plugins|gems)/gem_name/shoulda_macros/ will be automatically required when you run your tests. This allows you to distribute macros with your plugins, or to organize the macros inside your application. Remember to add your macro to Test::Unit::TestCase in the macro file: - - # test/shoulda_macros/security.rb - class Test::Unit::TestCase - def self.should_be_denied(opts = {}) - should_set_the_flash_to(opts[:flash] || /Please log in/i) - should_redirect_to(opts[:redirect] || 'login_url') - end - end - = Rails Installation (Test::Unit) Specify the gem dependency in your config/environment.rb file: