Ruby 上下文范围中的Rspec字段
我真的不知道如何表达标题,但我的问题如下:Ruby 上下文范围中的Rspec字段,ruby,rspec,ruby-1.9,Ruby,Rspec,Ruby 1.9,我真的不知道如何表达标题,但我的问题如下: 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 "some
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
范围中引入的,而不是在上下文中引入的
所以我的问题是,我应该如何将变量引入到它的上下文范围中?或者我应该使用其他方法。在每个块之前对其进行求值,但就我所知,不针对上下文或描述
describe "something" do
let(:fields) { %w{something something2} }
it "should have all fields" do
fields.each do |field|
end
end
end
Let在每个it
块之前进行求值,但据我所知,它不是针对上下文
或描述
describe "something" do
let(:fields) { %w{something something2} }
it "should have all fields" do
fields.each do |field|
end
end
end
不知道共享\u示例
,但如果使用,可以向块传递参数,如下所示:
shared_examples_for "something" do |fields|
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", %w{something something2}
end
不知道共享\u示例
,但如果使用,可以向块传递参数,如下所示:
shared_examples_for "something" do |fields|
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", %w{something something2}
end
共享的示例已经创建了一个新的上下文,因此我认为最干净的方法是像shioyama的示例一样,没有额外的上下文:
shared_examples_for "something" do |fields|
fields.each do |field|
it "should have #{field} field" do
# specify something
end
end
end
describe Clazz do
it_behaves_like "something", %w{something something2}
end
共享的示例已经创建了一个新的上下文,因此我认为最干净的方法是像shioyama的示例一样,没有额外的上下文:
shared_examples_for "something" do |fields|
fields.each do |field|
it "should have #{field} field" do
# specify something
end
end
end
describe Clazz do
it_behaves_like "something", %w{something something2}
end