[b]1. Install[/b]
[b]2. Create rails project (ep. blog)[/b]
[b]3. Generate rspec dirs[/b]
[b]4. Generate rspec MVC files (ep. post)[/b]
[b]5. DB[/b]
[b]6. Use auto test[/b]
[b]7. Test a file[/b]
[b]8. Test models[/b]
[b]9. Test controllers[/b]
[b]10. Test all[/b]
[b]11. more pls to see "rake -T spec"
Wrapped assertions[/b]
[b]Tree[/b]
[list]
[*]project
[*] |
[*] +—app
[*] |
[*] +—…
[*] |
[*] +—spec
[*] |
[*] +— spec_helper.rb
[*] |
[*] +— controllers
[*] |
[*] +— helpers
[*] |
[*] +— models
[*] |
[*] +— views
[/list]
sudo gem install rspec
sudo gem install rspec-rails
[b]2. Create rails project (ep. blog)[/b]
rails blog
cd blog
[b]3. Generate rspec dirs[/b]
ruby script/generate rspec
[b]4. Generate rspec MVC files (ep. post)[/b]
model:
ruby script/generate rspec_mode Post title:string content:text
controller:
ruby script/generate rspec_controller Post title:string content:text
scaffold:
ruby script/generate rspec_scaffold Post title:string content:text
[b]5. DB[/b]
rake db:migrate
rake db:migrate RAILS_ENV=test
[b]6. Use auto test[/b]
autospec
[b]7. Test a file[/b]
ruby -S bundle exec rspec ./spec/helpers/users_helper_spec.rb
[b]8. Test models[/b]
rake spec:models
[b]9. Test controllers[/b]
rake spec:controllers
[b]10. Test all[/b]
rake spec
[b]11. more pls to see "rake -T spec"
Wrapped assertions[/b]
assert_equal 'aaa', 'aaa':
'aaa'.should equal('aaa'), 'aaa'.should == 'aaa'
assert_not_equal 'aaa', 'bbb': 'bbb'.should_not equal('aaa'), 'bbb'.should_not == 'aaa'
assert_same: should be()
assert_not_same: should_not be()
assert_nil: should be_nil
assert_not_nil: should_not be_nil
assert_in_delta: should be_close
assert_match: should match(), should =~
assert_no_match: should_not match(), should.not =~
assert_instance_of: should be_an_instance_of()
assert_kind_of: should be_a_kind_of
assert_respond_to: should respond_to
assert_raise: should raise
assert_nothing_raised: should_not raise
assert_throws: should throw
assert_nothing_thrown: should_not throw
assert_block: should satisfy
[b]Tree[/b]
[list]
[*]project
[*] |
[*] +—app
[*] |
[*] +—…
[*] |
[*] +—spec
[*] |
[*] +— spec_helper.rb
[*] |
[*] +— controllers
[*] |
[*] +— helpers
[*] |
[*] +— models
[*] |
[*] +— views
[/list]