This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
mcornick (author)
Wed Mar 05 12:30:19 -0800 2008
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Fri Aug 24 10:59:07 -0700 2007 | |
| |
README | Mon Nov 19 05:36:03 -0800 2007 | |
| |
init.rb | Mon Oct 08 19:38:39 -0700 2007 | |
| |
install.rb | Fri Aug 24 10:59:07 -0700 2007 | |
| |
lib/ | Tue Feb 05 11:30:29 -0800 2008 | |
| |
test/ | Fri Aug 24 10:59:07 -0700 2007 |
README
= TesterXtreme
The Tester Xtreme plugin is a way to distill common testing patterns into easy-to-use macros that
are added as class methods to your test cases. There are currently macros for both unit (ActiveRecord
model) and functional (ActionController controllers) tests.
== Unit Test Macros
=== Validation Tests
Each of the validation testing macros checks to make sure there is an appropriate validation method
defined in the model for each attribute specified.
*should_require*
Ensures that +validates_presence_of+ was used.
*should_require_numeric*
Ensures that +validates_numericality_of+ was used.
*should_require_unique*
Ensures that +validates_uniqueness_of+ was used.
*should_protect*
Ensures that +attr_protected+ was used for this attribute.
*Usage*:
class UserTest < ActiveSupport::TestCase
should_require :first_name, :last_name
should_require_unique :username
should_require_numeric :friends_count
should_protect :hashed_password
end
=== Association Tests
Each of the association testing macros checks to make sure the correct associations were defined on
this model. The names map directly to the association definitions:
*should_have_many*
Ensures that +has_many+ was used.
*should_belong_to*
Ensures that +belongs_to+ was used.
*should_have_one*
Ensures that +has_one+ was used.
*should_have_and_belong_to_many*
Ensures that +has_and_belongs_to_many+ was used.
*Usage*:
class UserTest < ActiveSupport::TestCase
should_have_many :friends
should_belong_to :organization
should_have_one :credit_card
should_have_and_belong_to_many :categories
end
== Functional Test Macros
Each of the functional testing macros require that you first request an action on the controller. To
accomplish this, the 4 standard actions are implemented as class methods for the test:
* get
* post
* put
* delete
In addition to simple requests, you can also specify parameters and initial states:
get(:show){ User.expects(:find).returns(mocked_user) }.with(:id => 1)
post(:create).with(:username => 'foobar')
From here, you can use the macros to define certain expectations on the controller:
*should_assign*
Asserts that the specified variable is set as an instance variable.
*should_not_assign*
Asserts that the specified variable is *not* set as an instance variable.
*should_use_filter*
Asserts that the designated filter method is run.
*should_not_use_filter*
Asserts that the designated filter method is *not* run.
*should_render*
Asserts that the response for the action is successful and that the specified template is rendered.
*should_set_flash*
Asserts that the specified key and value was set in the flash collection.
*should_set_session*
Asserts that the specified variable was set in session.
*should_redirect_to*
Asserts that the response was a redirect and that the action redirects to the specified route.
*Usage*:
class UsersController < ActionController::TestCase
get(:new).should_render(:new)
post(:create).with(:username => 'foo').should_redirect_to(:new_user_url)
delete(:destroy).should_set_flash(:notice, 'You must log in')
get(:show).with(:id => 1).should_use_filter(:check_for_current_user)
get(:show).with({:id => 1}, {:user_id => 3}).should_assign(:current_user)
end
= Credits
Copyright (c) 2007 Ben Scofield, released under the MIT license







