It’s Not Always A Commit That Breaks the Build

In many cases a red build means, that some commit to the version control system broke it.

However, occasionally it can be something as simple as waiting that breaks it. Here’s what happened to me very recently when changing a Ruby project:

  1. I didn’t commit (& push) to one of my projects for a while.
  2. Then I made a pretty minor change.
  3. The local test run was fine.
  4. So I committed & pushed the change to GitHub.
  5. The builds on Travis-CI turned red.
  6. Oh?!?

What happened?

Travis-CI always sets up an entirely new environment, including this:

bundle install

Now, RSpec has been updated (to 3.0.0) since the last test execution on Travis, and I didn’t specify a version in the Gemfile (actually the gem spec file of the project), and I didn’t specify which RSpec version to use, and some RSpec methods have been changed in the meantime.

In particular, some of the specs used be_true, to check a number of predicate methods. However the new RSpec way is to use is_truthy (and its counterpart is_falsey). These methods check something slightly different compared to this line:

expect(value).to be true

In RSpec 3.0 only true is true, and everything that is interpreted as true (everything other than false and nil) is truthy. Also note the absent underscore in be_true (as used in earlier versions of RSpec). See this short example of RSpec:

describe 'RSpec 3.0 true vs. truthy' do
  it {expect(true).to be_truthy}
  it {expect(true).to be true}
  it {expect(1).to be_truthy}
  it {expect(1).not_to be true}
end

Notice here, that 1 is truthy, but not true.

Lesson learned

In order to avoid trouble like this, it seems to be a good idea to fix gem versions for a project in the Gemfile (or the gemspec).

This can avoid broken builds on your Continuous Integration Service (as in my case), but it can also prevent a new team member from struggling through dependency issues after running the bundle command to set up a new machine for development. See, for example “Ruby’s Pessimistic Operator” and “Ruby Gems Guides – Patterns” on how to use the ‘twiddle wakka’ operator for gem versions.

4 Replies to “It’s Not Always A Commit That Breaks the Build”

  1. Yes, time and date add interesting twists to testing (and dependencies). So interesting in fact, it could be worth a blog post. 🙂

    Some ways to deal with this, are described in “How to fake Time.now?” at http://stackoverflow.com/questions/1215245/how-to-fake-time-now.
    Also, there are some Ruby gems to fake time, e.g. TimeCop (https://github.com/travisjeffery/timecop).
    More gems are listed on “The Ruby Tool Box” at https://www.ruby-toolbox.com/categories/time_warping.

    1. We managed to have a date 3 months a two days in the future that just happens to be the day when we switch out of summer time … And therefore the time is ambiguous.

      1. Oh, that’s cool (in the software tester way). 🙂

        It could also be interesting to find out what happens when a date and time combination is used of a time that ‘doesn’t exist’, such as the hour that’s skipped when switching to summer time (daylight savings time) in spring.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Seaside Testing

Subscribe now to keep reading and get access to the full archive.

Continue reading