0
如何訪問在Minitest中的安裝方法中定義的變量?Ruby Minitest:在設置方法中訪問變量
require 'test_helper'
class TimestampTest < ActiveSupport::TestCase
setup do
@ag = AG.create(..., foo = bar(:foobar))
@ap = AP.create(..., foo = bar(:foobar))
@c = C.create(..., foo = bar(:foobar))
end
[@ag, @ap, @c].each do |obj|
test "test if #{obj.class} has a timestamp" do
assert_instance_of(ActiveSupport::TimeWithZone, obj.created_at)
end
end
end
如果我運行這個@ag
,@ap
和@c
都是nil
。需要使用第5-7行的bar(:foobar)來訪問燈具數據。