AnApprentice
AnApprentice

Reputation: 111060

With RSpec, is there a way to define a before(:each) for a describe block?

Right now my rpsec goes like this:

describe Ability do

  before(:each) do
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

end

Is there a way I can define a before each for just one of the describe blocks? Something like this:

describe Ability do

  before(:each) do
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

  describe 'xxx' do
    it "should xxx" do
    end
    it "should xxx" do
    end
  end

  describe 'xxx' do

    before(:each) do
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    end

    it "should xxx" do
    end
    it "should xxx" do
    end
  end

end

Thanks

Upvotes: 1

Views: 195

Answers (1)

Cydonia7
Cydonia7

Reputation: 3846

The solution you gave should work. Have you tried it ?

Upvotes: 3

Related Questions