【发布时间】:2011-06-22 13:23:01
【问题描述】:
我正在尝试使用 rspec 做一些事情,但我无法在我需要的地方访问我需要的变量。例如:
describe "some things" do
it "should have things in App" do
App.things.should_not be_nil #no problems here
# puts App.things.count
# => 10
end
# puts App.things.count
# => 0
App.things.each do |thing|
#this doesn't work at all as App.things is empty
it "#{thing.title} should have an account number" do
thing.acc_no.should_not be_nil
end
end
我猜这是因为调用不同块的时间。或者也许我完全没有抓住重点。
我需要遍历“事物”并对每个事物做出断言,但我不能这样做,因为事物在 describe 块的上下文中没有任何元素,只有在 it 块中。
有什么帮助吗?
【问题讨论】: