您的位置:首页 > 编程语言 > Python开发

Style Guide for Python Code 推荐的python代码风格

2008-05-03 18:34 519 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: