-
Notifications
You must be signed in to change notification settings - Fork 2k
Common Mistakes
Sam Joseph edited this page May 21, 2015
·
7 revisions
- Minimise logic in the controller (presentation logic in view, business logic in objects)
- Avoid any redundancy - everything must have a purpose
- Everything should be as simple as possible
- attr_*
- Avoid 'case' and 'elsif'
- Use sessions or class instance variable in Sinatra but not both
- Indent consistently
- Beware vacuous tests
- Stub out random behaviour
- Correct use of expectations with Cucumber
- Avoid unnecessary initialization
Cucumber/RSpec
- Indent consistently +++
- Avoid vacuous tests +
- Ensure feature files are in feature directory, not support
- Prefer more specific click_button or click_link to click_on
- Prefer rspec expect syntax over should syntax
- Separate out features correctly
- Go for simple descriptions of tests
- Stub out random behaviour
- Avoid testing if something responds to a method
- Ensure cucumber steps use correct variables
- Leave expectations to cucumber Then blocks
- stub out random behaviour
- Instead of testing that it is not nil, you could give an array of possible values and check that it responds with one of those values.
- Use before blocks to DRY out code
- Prefer to not raise exceptions except for exceptional behaviour
- Don't copy-paste
- calling a unit test a feature test
Code
- No need to initialize vars to nil or to empty hashes in other methods +++
- Minimise logic in the controller +++
- Looking up winning combination can be done through nested hash --> go to classes for Rock, Paper, Scissor? (either way avoid case statements or lots of elsif) +
- Use the simplest code possible (i.e. avoid redundant code that does nothing) +
- No presentation logic in controller or in business objects +
- Remove anything that is not being used +
- Avoid attr_accessor where possible, but use to shorten code where necessary +
- Avoid combination of attr_reader and separate reader method
- Use attr_* methods to DRY out code
- Use sessions or global in Sinatra but not both
- Avoid vacuous wrapper classes
- Avoid adding objects to session - prefer ids due to restricted session space
- Rescue specific errors, not general ones
- Avoid get_ prefix on ruby methods
- Prefer to use the private keyword once
- Prefer to not raise exceptions except for exceptional behaviour
- Don't copy-paste
- font tags are evil
- Avoid vacuous assignments
def initialize; @name = name
- Lower case for symbols
- Avoid instance variables where unnecessary
- Avoid assigning dummy vars to objects, i.e. no need to pass in a symbol when variable can be set later
- Indent correctly
HTML
- Indent correctly ++
- Prefer Semantic HTML
- Remove redundant components (e.g. forms when all you have is a link)
- Avoid br tags - prefer p or extend margin-bottom
- Prefer internal images
- Wrap a tags in p tags
- Prefer a layout