cheat sheets.

$ cheat rspec
INSTALL
=======
$ sudo gem install rspec

$ ./script/plugin install
svn://rubyforge.org/var/svn/rspec/tags/REL_X_Y_Z/rspec_on_rails/vendor/plugins/rs
ec_on_rails
Where X_Y_Z is the version number.

$ ./script/generate rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/test2spec.erb
      create  test/test2spec_help.rb
      create  script/rails_spec
      create  script/rails_spec_runner



HOW TO USE
==========
./script/generate rspec_model User


module UserSpecHelper
  def valid_user_attributes
    { :email => "joe@bloggs.com",
      :username => "jobbloggs",
      :password => "abcdefg"}
  end
end


context "A User (in general)"
  include UserSpecHelper
  
  def setup
    @user = User.new
  end
  
  specify "should be invalid without a username" do
    @user.attributes = valid_user_attributes.except(:username)
    @user.should_not_be_valid
    @user.errors.on(:username).should_equal "is required"
    @user.username = "someusername"
    @user.should_be_valid
  end
end

SHOULDA COULDA WOULDA
=====================
target.should_satisfy {|arg| ...}
target.should_not_satisfy {|arg| ...}

target.should_equal <value>
target.should_not_equal <value>

target.should_be_close <value>, <tolerance>
target.should_not_be_close <value>, <tolerance>

target.should_be <value>
target.should_not_be <value>

target.should_predicate [optional args]
target.should_be_predicate [optional args]
target.should_not_predicate [optional args]
target.should_not_be_predicate [optional args]

target.should_be < 6
target.should == 5
target.should_not == 'Samantha'

target.should_match <regex>
target.should_not_match <regex>

target.should_be_an_instance_of <class>
target.should_not_be_an_instance_of <class>

target.should_be_a_kind_of <class>
target.should_not_be_a_kind_of <class>

target.should_respond_to <symbol>
target.should_not_respond_to <symbol>

proc.should_raise <exception>
proc.should_not_raise <exception>

proc.should_throw <symbol>
proc.should_not_throw <symbol>

target.should_include <object>
target.should_not_include <object>

target.should_have(<number>).things
target.should_have_at_least(<number>).things
target.should_have_at_most(<number>).things
Version 8, updated 722 days ago.
. o 0 ( | previous | history | revert to | current | diff )
( add new | see all )