【发布时间】:2012-09-23 10:32:39
【问题描述】:
确实不知道如何表达标题,但我的问题如下:
shared_examples "something" do
context "for something" do
fields.each do |field|
it "should have #{field} field" do
#Check something
end
end
end
end
describe Clazz do
it_behaves_like "something" do
let(:fields) {%w{something something2}}
end
end
由于变量是在it 范围中引入的,而不是在context 中,因此当然会在fields.each 部分执行失败。
所以我的问题是如何将带有 it_behaves_like 的变量引入上下文范围?或者我应该使用其他东西。
【问题讨论】: