Documente Academic
Documente Profesional
Documente Cultură
INSTALL
=======
$ gem install rspec
RSPEC-RAILS
===========
RAILS-3
=======
RAILS-2
=======
INSTALL
=======
$ gem install rspec-rails -v 1.3.3
HOW TO USE
==========
COMMAND LINE
=============
rspec --color --format doc spec/widget_spec.rb
RAILS 3 (RSPEC 2)
=============
./rails/generate model User
rake -T spec # lists all rspec rake tasks
rake spec # run all specs
rake spec/models/mymodel_spec.rb # run a single spec file
rake spec/models/mymodel_spec.rb:27 # run a single example or group on line 27
RAILS 2 (RSPEC 1)
=============
./script/generate rspec_model User
rake -T spec # lists all rspec rake tasks
rake spec # run all specs
rake spec SPEC=spec/models/mymodel_spec.rb SPEC_OPTS="-e \"should do
something\"" #run a single spec
module UserSpecHelper
def valid_user_attributes
{ :email => "joe@bloggs.com",
:username => "joebloggs",
:password => "abcdefg"}
end
end
before(:each) do
@user = User.new
end
EXPECTATIONS
=====================
target.should satisfy {|arg| ...}
target.should_not satisfy {|arg| ...}
target.should be <value>
target.should_not be <value>
target.should be < 6
target.should == 5
target.should_not == 'Samantha'
target.should have(<number>).things
target.should have_at_least(<number>).things
target.should have_at_most(<number>).things
target.should have(<number>).errors_on(:field)
user_stub = mock_model("User", :id => 23, :username => "pat", :email =>
"pat@example.com")