Menu

code

A 6-post collection

As a consultant, I come across a lot of bad test suites in Rails and JavaScript apps. The following are all RSpec, Jest, or Jasmine tests that I have found in the wild – with minor changes for clarity or to protect the guilty :) (myself included!)
These are some simple things not to do, along with some advice about what to do to accomplish the same goal.
Don’t test internals in a system test
System
»

We add indexes to our database in order to speed up read operations. Basically, an index is a sorted copy of a particular set of columns the database uses to quickly look up the attributes of another table, most commonly, foreign keys of relations. There are several ways this can actually be implemented on the database; essentially, we tell the database which values we’ll be looking up most often and
»

I love abstraction. It’s great to compartmentalize complexity and keep your application modular. SQL is not that. Relying on SQL strings in your code ties your implementation directly to the type, structure, and even the version of your database. ActiveRecord (the ORM behind Rails) is great for letting us focus on our application and not worry so much about the database particulars.
However, understanding
»

One of my eureka moments as a developer came when my programming pair suggested I separate some very simple math in the body of a method into another method. At the time it seemed like overkill to create an entirely new method when the operation was so simple. Wouldn’t that make it more complicated? But I quickly realized the benefits outweighed the cost.
The first benefit is code reuse. This is rather
»

As a developer, written communication and reading comprehension are more valuable than math proficiency.
Sometimes, I tweet. When I tweet, sometimes people agree with me. One such occasion happened recently when I said this.
Modern software development has way more to do with reading comprehension and written communication than math.— Ross Hunter (@Ross_Hunter) November 30, 2013
This was part
»

Are you working on a PhoneGap/Cordova app that needs to be able to communicate with other native applications? You may want to get the demo code, maybe give it a once over, and then continue reading.
Note: This work was completed in a pre-PhoneGap 3.0.0 world. There is now a Plugin Specification Guide that should be adhered to. This code would need to be adapted to fit that structure.
Prologue
»