Skip to content

Conditional pending

Created by: myronmarston

I've had some cases where I've got a spec that runs in multiple contexts, and it passes in one and fails in another. For example, this may be because of running the specs against different versions of ruby (say, it passes on MRI 1.8.7 but fails on JRuby).

Before now, I've used code like this to handle it:

it "does someting" do
  run_test = lambda do
    # put the actual spec logic here
  end

  if RUBY_PLATFORM == 'java'
    pending("waiting for the JRuby devs to fix issue XXX", &run_test)
  else
    run_test.call
  end
end

This is functional, but not terribly elegant. I came up with the idea to allow pending to take :if and :unless options. Now I could rewrite like this:

it "does someting" do
  pending("waiting for the JRuby guys to fix issue XXX", :if => RUBY_PLATFORM == 'java') do
    # spec logic goes here
  end
end

This is a bit more elegant, I think.

Merge request reports