[rspec-users] Conditionally turning some specs on and off depending on runtime platform

Scott Taylor mailing_lists at railsnewbie.com
Fri Sep 26 10:35:58 EDT 2008

On Sep 26, 2008, at 10:31 AM, Wincent Colaiuta wrote:

> El 26/9/2008, a las 16:16, "David Chelimsky" <dchelimsky at gmail.com>  
> escribió:
>> On Fri, Sep 26, 2008 at 8:42 AM, Wincent Colaiuta <win at wincent.com>  
>> wrote:
>>> El 26/9/2008, a las 14:59, "David Chelimsky" <dchelimsky at gmail.com>
>>> escribió:
>>>> On Thu, Sep 25, 2008 at 3:50 PM, Wincent Colaiuta  
>>>> <win at wincent.com> wrote:
>>>>> The following trick, calling "pending" from inside the before  
>>>>> block,
>>>>> effectively does what I want. But I'm wondering if I can count  
>>>>> on this
>>>>> behaviour going forward? What do you think?
>>>> Pending is not going anywhere.
>>> I didn't think so... I was mostly concerned about the fact that I am
>>> (ab)using it by calling it from inside the "before" block...
>> That doesn't strike me as abuse :)
> Glad to hear you think so!
> The truth is, sticking the check in the "before" block "feels"  
> right, at least to me, because asking "can I run this example?" is  
> something that I (obviously) want to do _before_ running each  
> example. Bonus is that the examples in question print out the  
> pending message rather than just disappearing into the nether.
> In contrast, nesting all the affected examples inside a large "if"  
> feels much nastier.

I don't think so.  In fact, I've seen it in spec's codebase itself,  
where they skipped some examples for jruby, but not for MRI.

Here is another variation on the technique:

pend_if_on_ruby_1_8_5 do
... your examples here ..

def pend_if_on_ruby_1_8_5
   if RUBY_VERSION == "1.8.5"
	xit "Skipping examples because on 1.8.5"


More information about the rspec-users mailing list