之前:每个都没有在共享示例中执行

时间:2014-11-14 19:06:25

标签: ruby rspec

我有一个看起来像这样的测试:

describe "test" do
  shared_example "a thing" do
    before :each do
      puts 'in before'
    end

    describe 'the thing' do
      puts 'in test'
    end
  end

  it_behaves_like "a thing"
end

运行此代码时,输​​出为in test。为什么呢?

1 个答案:

答案 0 :(得分:4)

你没忘记it {}吗?

describe "test" do
  shared_examples "a thing" do
    before :each do
      puts 'in before'
    end

    describe 'the thing' do
      it 'should puts in test' do
        puts 'in test'
      end
    end
  end

  it_behaves_like "a thing"
end

# output:

  test
    behaves like a thing
      the thing
in before
in test
相关问题