基本上,我想创建一个数组,然后在我的规范中附加到它,最后处理并显示给用户。我可以想出一些变通办法,但理想情况下,我想做以下几件事。
RSpec.configure do |config|
config.before(:suite) { @array_of_stuff ||= [] }
config.after(:suite) { process_and_print(@array_of_stuff) }
end
def process_and_print(array)
# do stuff
end不幸的是,但并不奇怪,@array_of_stuff不在我的规范范围内,也不能附加到我的规范中,不像在before(:all)块中设置。
有没有什么RSpec提供的东西可以让这样的事情变得非常简单?
发布于 2011-03-16 01:30:05
它可能不是为此而设计的,但是您可以使用custom settings
spec_helper
RSpec.configure do |config|
config.add_setting :my_array
config.before(:suite) { RSpec.configuration.my_array = [] }
end示例规范
it "should do something" do
RSpec.configuration.my_array << "some value"
RSpec.configuration.my_array.length.should eql(1)
endhttps://stackoverflow.com/questions/5312333
复制相似问题