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

Ashley Moran ashley.moran at patchspace.co.uk
Thu Sep 25 17:34:03 EDT 2008


On Sep 25, 2008, at 9:50 pm, Wincent Colaiuta 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?
>
>  describe 'Something' do
>    before do
>      if required_tools_not_installed
>        pending 'not running on this platform'
>      end
>    end
>
>    it 'should do something' do
>      1.should == 1
>    end
>  end

Hi Wincent

How about wrapping it this way instead...

  describe 'Something' do
    if required_tools_installed
      it 'should do something' do
        1.should == 1
      end
    end
  end

That will make them invisible (for better or worse).

How come you need this?  Is what you really need to spec that the tool  
itself degrades gracefully? eg

  describe 'Something' do
    if required_tools_installed
      it 'should do something' do
        1.should == 1
      end
    else
      it 'should inform the user the tool is missing'
    end
  end

Ashley

-- 
http://www.patchspace.co.uk/
http://aviewfromafar.net/



More information about the rspec-users mailing list