tags:

views:

58

answers:

1

In the test below, the Bar and Baz blocks contain identical specs.

Leaving aside why such repetition was necessary in the first place, I'm wondering how one could dry this up.

I tried turning the blocks into objects and calling them under Bar and Baz, but possibly because I did not get the scopes right, I have not been able to make it work.

describe Foo do
  describe Bar do
    before(:each) do
      prepare
    end

    it "should do something" do
      true
    end

    it "should do something else" do
      true
    end
  end

  describe Baz do
    before(:each) do
      prepare_something_else
    end

    it "should do something" do
      true
    end

    it "should do something else" do
      true
    end
  end
end