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

Ashley Moran
Mon, 26 Jul 2010 07:31:21 -0000

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 here?

  shared_examples_for "Comparable" do
describe "comparing " do
it "defines equality for " 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.)