October 2008
Beginner to intermediate
224 pages
5h 34m
English
rake test # Test all units and functionals rake test:functionals # Run tests for functionals rake test:integration # Run tests for integration rake test:units # Run tests for units
rake test:units
Available assertions:
assert_kind_of Class, @var # same class
assert @var # not nil
assert_equal 1, @p.id # equality
@product.destroy
assert_raise(ActiveRecord::RecordNotFound) { Product.find( @product.id ) }
assert_difference 'Photo.count' { Photo.create }
assert_no_difference 'Photo.count { Photo.create(:name => 'invalid name') }rake test:functionals
get :action # a get request of the specificed action
get :action, :id => 1,
{ session_hash }, # optional session variables
{ flash_hash } # optional messages in the flash
post :action, :foo => { :value1 => 'abc', :value2 => '123' },
{ :user_id => 17 },
{ :message => 'success' }
get, post, put, delete, head
assert_response :success
# possible parameters are:
# :success
# :redirect
# :missing
# :errorassert_redirected_to :action => :other_action assert_redirected_to :controller => 'foo', :action => 'bar' assert_redirected_to http://www.invisible.ch
assert_template "post/index"
assert_nil assigns(:some_variable) assert_not_nil assigns(:some_variable) assert_equal 17, assigns(:posts).size
Note: assert_tag is deprecated. Use assert_select instead. Cheat sheet: http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/ cheat/assert_select.html ...
Read now
Unlock full access