# Bruce 的玩具間

## Use codeclimate-test-reporter without a CI server

For some reason, we didn't setup a CI server. But we still want Code Climate to know test coverage after each deployment.

After some searching and experiment. We came up with this solution.

Because we don't have a CI server. We use Ben Dixon's run_tests technique covered in his book Reliably Deploying Rails Applications, which is:

It will run test before every deploy. And stop deploy process if there are any failed test.

## 2. Install and setup codeclimate-test-reporter

Install codeclimate-test-reporter by adding it into Gemfile

and run bundle install

Start the test reporter. Make sure that you put these lines at top of your spec_helper.rb.

Manually tirgger fist test report (your project token can be found at Settings > Test Coverage)

It should show following message:

Now you should be able to see the report showing in Code Climate. Sometimes it can take a few minutes.

## 3. Modify run_tests and make it report after each deployment

When you run rspec without CODECLIMATE_REPO_TOKEN, even you have test reporter started, it won't send test report to Code Climate. In other words, you can control when to send report by giving token or not.

Modify the rspec command in lib/capistrano/tasks/run_tests.cap

I assume you always run complete test suit with this technique.

Now, test will be run before every deployment and test report will be sent after that.

Note: you can put your token in run_tests.cap for simplicity. But I rarely commit any key or token into repostory. Instead, I put it in a git-ignored, separated config file. Than read and assign the value in config/deploy.rb.