cheat sheets.

$ cheat shoulda
= Assertions

assert_contains ['a', '1'], /a/
assert_does_not_contain ['a', '1'], /b/

assert_same_elements [1, 2, 3], [3, 2, 1]

assert_bad_value User, :birthdate, "Older than you!"
assert_good_value User, :email, "bob@email.com"

assert_save @user
assert_valid @user

assert_sent_email do |email| 
 email.subject =~ /activated/ && email.to.include?('bob@email.com') 
end
assert_did_not_send_email do |email| 
 email.subject =~ /activated/ && email.to.include?('bob@email.com') 
end

assert_xml_response

= Macros

should_eventually 'be awesome'
should_eventually 'clean my room' do
  raise "I am so broken"
end

should_change "Post.count", :from => 0, :to => 1
should_change "@post.title", :from => "old", :to => "new"
should_change "@post.title"
should_change "@post.title" :from => "old"
should_change "@post.title" :to   => "new"
should_not_change "Post.count"

== Class under test

should_have_class_methods :find, :destroy
should_have_instance_methods :email, :name, :name=

== ActiveRecord

should_have_db_columns :id, :email, :name, :created_at
should_have_db_column :email, :type => "string", :default => nil, :precision =>
nil, :limit => 255, :null => true, :primary => false, :scale => nil, :sql_type
=> 'varchar(255)'

should_have_indices :email, :name, [:commentable_type, :commentable_id]
should_have_index :age

should_have_named_scope 'recent(5)', :limit => 5
should_have_named_scope 'recent(1)', :limit => 1

should_require_acceptance_of :eula

should_ensure_length_at_least :name, 3
should_ensure_length_is :ssn, 9
should_ensure_value_in_range :age, (0..100)

should_only_allow_numeric_values_for :age

should_have_readonly_attributes :password, :admin_flag

should_require_attributes :name, :phone_number

should_require_unique_attributes :keyword, :username
should_require_unique_attributes :name, :message => "someone stole your name"
should_require_unique_attributes :email, :scoped_to => :name
should_require_unique_attributes :address, :scoped_to => [:first_name,
:last_name]

should_protect_attributes :password, :admin_flag

should_allow_values_for :phone, "(123) 999-3049", "201-0023"
should_not_allow_values_for :phone, "I am totally not a phone number",
"201-0023"

should_belong_to :parent

should_have_one :god

should_have_many :friends
should_have_many :enemies, :through => :friends
should_have_many :enemies, :dependent => :destroy

should_have_and_belong_to_many :posts, :cars



== ActionController

should_assign_to
should_be_restful
should_belong_to
should_filter_params
should_not_assign_to
should_not_set_the_flash
should_redirect_to
should_render_a_form
should_render_template
should_respond_with
should_respond_with_xml_for
should_route
should_set_the_flash_to


Version 7, updated 52 days ago.
. o 0 ( | previous | history | revert to | current | diff )
( add new | see all )