Presentation for Fog City Ruby based on https://blog.blockscore.com/how-to-write-better-code-using-mutation-testing/.
Mutation testing can help you:
* Improve your test coverage
* Think about edge cases and catch more bugs before they break in production
* Learn more about Ruby, the libraries you depend on, and your own codebase
52. 1 it 'returns a user when given a valid id' do
2 expect(get(:show, id: 1)).to eq(id: 1, name: 'John')
3 end
4
5 it 'renders JSON error when given an invalid id' do
6 expect(get(:show, id: 0))
7 .to eq(error: "Could not find User with 'id'=0")
8 end
1 class UsersController < ApplicationController
2 def show
3 render json: User.find(params[:id].to_i)
4 rescue User::RecordNotFound => error
5 render json: { error: error.to_s }
6 end
7 end
74. 1 module YourApp
2 class User < ActiveRecord::Base
3 # Dozens of includes, scopes, class methods, rails magic
4 # 100+ methods
5
6 def validate_email
7 # Simple method you're fixing
8 end
9 end
10 end
75. 1 RSpec.describe YourApp::User do
2 # 100s of tests and setup unrelated to your task
3
4 describe '#validate_email' do
5 # Half dozen tests you are focusing on
6 end
7 end