我有一个看起来像这样的测试:
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
。为什么呢?
答案 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