开发者

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

开发者 https://www.devze.com 2023-04-04 04:23 出处:网络
Right now my rpsec goes like this: describe Ability do before(:each) do end describe \'xxx\' do it \"should xxx\" do

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' 开发者_JAVA百科do

    before(:each) do
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    end

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

end

Thanks


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

0

精彩评论

暂无评论...
验证码 换一张
取 消