#TDD Practices
##Bad Practices Patterns that can be improved, or simply bad practices spotted within unit tests.
##PHP
###1) Repetition in all tests. Create a setUp() to handle this:
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
| <title>Hungry Kid!</title> | |
| <style type="text/css"> |
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
| <title>Drag and Drop</title> | |
| <style type="text/css"> | |
| body { | |
| margin:15px; | |
| padding:0; |
| """ | |
| IAM boto examples: | |
| In this example we create a group that provides access | |
| to all EC2 and S3 resources and actions and then add a | |
| user to that group. | |
| """ | |
| import boto | |
| # | |
| # First create a connection to the IAM service |
#TDD Practices
##Bad Practices Patterns that can be improved, or simply bad practices spotted within unit tests.
##PHP
###1) Repetition in all tests. Create a setUp() to handle this:
| strs = ['foo', 'bar', 'baz'] | |
| # standard long form way | |
| caps = strs.map { |str| str.upcase } | |
| # short hand | |
| caps = strs.map(&:upcase) | |
| # The & takes any object and calls to_proc on it | |
| # In the above example we're using a Symbol and not an object |
| # When calling a method with a splat then the parameters are passed as a comma separated list | |
| # When receiving arguments with a splat then they are converted into an Array | |
| # When using a double splat (2.0+) then the argument is converted into a Hash (i.e. named parameters) | |
| def foo(*args) | |
| p args | |
| end | |
| foo 'a', 'b', 'c' | |
| # => ["a", "b", "c"] |