【发布时间】:2009-12-01 09:36:24
【问题描述】:
我的 Ruby On Rails 单元测试在简单的字符串比较中失败,我不知道为什么。
在模型TestItem中,我有
doc = REXML::Document.new(data)
@bugtitle = doc.root.get_text("/bugzilla/bug/short_desc")
其中 data 是 Net::HTTP::post 请求返回的 xml 字符串。数据看起来不错,如果我输出 @bugtitle 它包含预期的字符串。在我的单元测试中,我有
test "bugtitle" do
ti = testitems(:one)
assert_equal("different RID folder for gating x-ray correction images",ti.bugtitle)
end
令人惊讶的是(至少对我而言)测试失败并显示以下输出(从 shell 逐字复制):
1) Failure:
test_bugtitle(TestTest) [unit/testitem_test.rb:7]:
<"different RID folder for gating x-ray correction images"> expected but was
<"different RID folder for gating x-ray correction images">.
我不知道这个错误是从哪里来的,因为这个字符串看起来和我一模一样。对于它的价值,这是在 Windows 上使用 rails 2.3.4 和 ruby 1.8.6(不要让我开始)。
【问题讨论】:
标签: ruby-on-rails ruby unit-testing string