【发布时间】:2016-07-18 14:40:50
【问题描述】:
此代码循环并打印整个散列,但如果散列的大小大于 4MB,它只会遍历前十个元素。
<% sections_content.each do |title, summary| %>
<tr>
<td style="border-bottom: 1px solid #eeeeee;"><%= raw title %></td>
</tr>
<tr>
<td><%= raw summary %></td>
</tr>
<% break if ObjectSpace.memsize_of(sections_content) > 4194304 && index == 9 %>
<% end %>
我想为它编写一个测试,以确保在索引等于 9 时循环中断,这意味着它会循环前十个元素。
我在想这样的事情:
require 'test_helper'
test "should size> 400" do
assert_equal(9, index, [msg])
end
测试不起作用。对测试此代码的更好方法的任何帮助[原文如此]
【问题讨论】:
标签: ruby-on-rails ruby testing rubygems