Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Codesmanship

Codesmanship

Adds assertions for enforcing Ruby coding conventions.

Example

test/unit/codesmanship_test.rb

class TestCodesmanship < Test::Unit::TestCase
  1. Rails Trac – Source style
  2. * Two spaces, no tabs
  3. * MyClass.my_method(my_arg)—not my_method( my_arg ) or my_method my_arg def test_should_follow_rails_source_style assert_rails_source_style end
def test_should_restrict_maximum_line_length
  assert_restriction_of_line_length 120
end
  1. Bad Smells from “When V is for Vexing” presentation
  2. (http://www.codefluency.com/assets/2007/5/18/VisForVexing.pdf)
  3. 1. Calling find on a model directly
  4. 2. Calling find on an association
  5. 3. Conditionally inserting content; if/else, clauses, case statements, etc
  6. 4. Doing complex inline map, sort, select, etc on a collection
  7. 5. Assigning temporary variables def test_should_stop_view_bad_smells assert_no_view_bad_smells end
def test_should_find_blank_lines_with_extra_spaces
  assert_codesmanship_on :ruby,  "  $", "Remove extra whitespace at the end of the line" 
  assert_codesmanship_on :views, "  $", "Remove extra whitespace at the end of the line" 
end
def test_should_find_hash_with_no_spaces
  assert_codesmanship_on :ruby,  '\b=>\b', "Use :key => value" 
  assert_codesmanship_on :views, '\b=>\b', "Use :key => value" 
end
def test_should_find_method_with_no_extra_spaces_in_their_default_arguments
  assert_codesmanship_on :ruby, 'def .\((.[a-z]=.*)\)', "Use def foo(options = {})" 
end
end

Copyright© 2007 Joshua Peek, released under the MIT license

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly


Homepage: http://projects.wh.joshpeek.com/browser/plugins/codesmanship