Thursday 6 June 2013

Rails: TDD Workflow

I try to keep things simple. This is my personal workflow as a single developer. This workflow evolves continually as I grow as a developer and as new tools and practices becomes available. These are my tools: Ruby, Rails, Rspec, Capybara, Git

This is an overview: For production apps I have a development, staging and production environment. As a start to a cycle I only have a master branch. I create a new branch for every feature (named after the feature) and when ready (all tests green) I create the development branch from the feature branch. The development branch pushes to the staging environment. When all tests green on staging I merge with master branch, push to production and delete the feature and development branches.

Here are more detailed steps:

  1. I write out a story for a feature with sketches.
  2. I create a new branch(I try to not code in master branch)
    git checkout -b newfeaturename
  3. I write my Rspec tests to test the feature
  4. I use Spork to pre-load my rails environment (run spork from the console) and a focus tag in the test to only run my new tests.

    In rspec test

    it "can email advertisers with no listings", focus: true do

    Then in console run:

    rspec spec --drb --tag focus

    The --drb option above make use of the spork service allready running

  5. Implement the code to make tests pass.
  6. After each test is green or refactored commit to version control

    git add .

    git commit -am "My commit message"

  7. When all tests are green and the feature is implemented I create the development branch
    git checkout -b development
  8. Push to staging:(I use Heroku)
    git push staging development:master
  9. Do integration tests against staging with saucelabs and a seed database
  10. If all good, merge with master

    git checkout master

    git merge development

  11. Push to git repositry (I use Bitbucket)
    git push bitbucket master
  12. Push to production (I use Heroku)
    git push heroku master
  13. Rinse and repeat with new features

No comments:

Post a Comment