Skip to content

Instantly share code, notes, and snippets.

@stigi
Created September 12, 2014 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigi/6f61c89ab45b69c48637 to your computer and use it in GitHub Desktop.
Save stigi/6f61c89ab45b69c48637 to your computer and use it in GitHub Desktop.

Guide for writing Specs

Facts

  • One method = One describe
  • Use -foo for instance methods
  • Use +foo for class methods
  • Use .foo for properties
  • Use <ProtocolName>methodname: for delegate methods
  • Use context inside of describe to describe the behavior for a specific state
  • Use it blocks to verify specific behavior
  • Describe what is happening, not what should happen. it does something instead of it should do something
  • One assertion per it block
  • Don't test private methods (User visible stuff is public)
  • Extract method parameters that matter for the context (for example in beforeEach)

References

http://betterspecs.org/
https://github.com/howaboutwe/rspec-style-guide
http://blog.carbonfive.com/2010/10/21/rspec-best-practices/
http://jakegoulding.com/presentations/rspec-structure/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment