4 rules for squashing bugs

Would you like to more? "Someone asked me once if I knew the difference between a civilian and a citizen. I know now. A citizen has the courage to make the safety of the human race their personal responsibility." - Johnny Rico

We are currently on high alert for a bug invasion and the infantry has already been deployed. It's up to you citizen--there is no looking back; the task at hand is finding and eliminating all bugs.

The term "Test Driven Development" is thrown around quite often in regards to programming and web development. While strategizing in the war against bugs I have found the similar method of "Test First Debugging" to be extremely helpful in gaining the upper hand on the opposition.

Testing is very important here at Bloc, where we make this Bug War as personal as a punch in the nose. Writing tests first improves the performance of tracking down and annihilating any bugs in the code base. Most recently, I personally had to battle a bug preventing the collection of enrolled students into a roster. My gift to you is 4 simple rules in defeating a bug.

Step 1: Stand your ground

Citizens at Bloc do their part to file and report bugs with proper descriptions and paths to allow engineering the ability to hunt and track down these vermin. Setting up planetary defenses is extremely important, writing tests help our troops gain crucial ground in the war.

Write a simple test for the desired behavior, and don't cringe at the idea of watching it fail at first: It will be the foundation for reconnaissance in finding the bug base.

# test
  describe '.roster_data' do
    let(:roster_data) { Enrollment.roster_data }

    it 'includes only new enrollments' do
      let(:old_enrollment) { create(:enrollment) }
      expect(roster_data).to_not include(old_enrollment)
    end
  end

Step 2: Find the source

Having a test to defend your code could not be easier; commence recon to eventually find the source of these bugs. You may now feel free to add or update code with the confidence of your test. Don't forget to actually run tests frequently between each change. The answer might be right under your nose.

Step 3: Complete annihilation

Once you have found the source of the bug, you must then write the code that will turn that test green. This will not only ensure that the bug is dead, it will also prevent future bug regeneration.

# code
class Enrollment  
  scope :roster_data, -> do
    where('enrollment is active')
  end
end  

Step 4: Fine-tuning your code

Take this time to set up camp and take pride in your work. While you wait for the cavalry to arrive for code review, clean up any unnecessary code and poke around to refactor in consideration of best practices and style guides.

# code
class Enrollment  
  scope :roster_data, -> { where(active: true) }
end  

Remember, the only good bug is a DEAD bug!
bug squash