[rspec-users] Formatting shared example descriptions with test data

Ashley Moran ashley.moran at patchspace.co.uk
Mon Jul 26 03:31:21 EDT 2010


Hi

I'm back again, and still on a quest to tame shared example to do my bidding.  This time what I'm wondering is... is there any way to format shared example specdoc description output with data passed in with #let, or otherwise?  eg: How do I get "1" and "2" into either of the placeholders <i> here?

  shared_examples_for "Comparable" do
    describe "comparing <i>" do
      it "defines equality for <i>" do
        object.should eq object
      end    
    end
  end

  describe Integer do
    it_should_behave_like "Comparable" do
      let(:object) { 1 }
    end
    it_should_behave_like "Comparable" do
      let(:object) { 2 }
    end
  end

(If I had to duplicate the 1 and 2 that wouldn't be the end of the world, as long as the syntax for including the shared examples was simple enough.)

Cheers
Ash

-- 
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran





More information about the rspec-users mailing list