`
tom_cjp
  • 浏览: 42412 次
  • 性别: Icon_minigender_1
  • 来自: 温州
文章分类
社区版块
存档分类
最新评论

rspec test

阅读更多
1. Install
   sudo gem install rspec
   sudo gem install rspec-rails


2. Create rails project (ep. blog)
   rails blog
   cd blog


3. Generate rspec dirs
    ruby script/generate rspec


4. Generate rspec MVC files (ep. post)
    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


5. DB
    rake db:migrate
    rake db:migrate RAILS_ENV=test


6. Use auto test
autospec


7. Test a file
ruby -S bundle exec rspec ./spec/helpers/users_helper_spec.rb


8. Test models
    
rake spec:models


9. Test controllers
    
rake spec:controllers


10. Test all
    
rake spec


11. more pls to see "rake -T spec"
Wrapped assertions

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



Tree

  • project
  •   |
  •   +—app
  •   |
  •   +—…
  •   |
  •   +—spec
  •       |
  •       +— spec_helper.rb
  •       |
  •       +— controllers
  •       |
  •       +— helpers
  •       |
  •       +— models
  •       |
  •       +— views

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics