Ylan Segal

Ruby Block Precedence: An Rspec Gotcha

Recently I came across a spec that didn’t seem to be executing the assertion block passed in to the raise_error expectation. Leaving the bare essentials for the example:

require 'rspec'

describe 'Block Precedence' do
  it 'expecting this spec to fail' do
    expect { raise 'Opps'}.to raise_error do |error|
      1.should == 2

We raise an exception, assert that it was raised and the try to assert something about the exception. In this example, 1.should == 2 should clearly fail. However, when we run this:

$ rspec rspec_example.rb

Finished in 0.001 secon

It would seem that the block is never being executed.

DelayedJob Workers Are Not Thread Safe

I love DelayedJob. It’s my go-to-gem for background processing in Rails, mainly because it works with whatever data store your project already has in place. No need to bring a different dependency just for background processing. However, using Delayed::Worker in threads is problematic.

Exercism: Practice Your Coding Technique

Perfect practice makes perfect

I have recently discovered exercism.io, by Katrina Owen of Ruby Rogues fame.

Exercism is a great way to practice your code and get feedback on it from others. You work on one exercise at the time and re-submit for review as often as needed until your code is considered great code. You then move on to the next exercise.

It’s awesome because you get feedback on your code, but also because you get to give feedback on other’s code and get to benefit form seeing others code evolve.

So far, it’s been a really fun experience. Thank you Katrina.

Conway's Game of Life

I recently read a blog post recently about Conway’s Game Of Life: Since I had not written an implementation myself, I decided to give it a go.

It was a fun exercise. I did not use any external library other than ruby’s stdlib and used TDD for most of the classes. The interface uses curses. Not knowing how to test it, I took a page from Gary Bernhardt in Functional Core, Imperative Shell and didn’t test the shell at all :)

Here it is: My Take on Conway’s Game Of Life

Testing With Multiple Ruby and Gem Versions

I found myself writting a gem for internal use that needed to run in several different ruby versions and MRI. In addition, the projects that it would be used in had other dependencies which also meant that it would need to function with different versions of dependencies. Here is how I ensured I was testing all scenarios.