Treetop 解析器输出的 RSpec 测试在应该匹配时不匹配
我有这个规范:
it 'can parse armies with only section headers' do
list = <<-LIST
:Core
:Special
:Omgg
:Moarheaders
LIST
expected_output = "## Core\n## Special\n## Omgg\n## Moarheaders\n"
parsed = @parser.parse(list)
parsed.should_not be_nil
parsed.transform.should be expected_output
end
产生这个输出:
expected ## Core
## Special
## Omgg
## Moarheaders
, got "## Core\n## Special\n## Omgg\n## Moarheaders\n"
如果我删除双引号,我会得到这个输出:
expected ## Core\n## Special\n## Omgg\n## Moarheaders\n,
got "## Core\n## Special\n## Omgg\n## Moarheaders\n"
如果我向预期输出添加引号,我会得到这个: (expected_output = '"## Core\n## Special\n## Omgg\n## Moarheaders\n"'
)
expected "## Core\n## Special\n## Omgg\n## Moarheaders\n",
got "## Core\n## Special\n## Omgg\n## Moarheaders\n"
这是怎么回事?
我无法获得 Treetop 结果来将 \n 评估为换行符,并且无论我尝试什么,我都无法使预期输出匹配。
我很困惑。
I have this spec:
it 'can parse armies with only section headers' do
list = <<-LIST
:Core
:Special
:Omgg
:Moarheaders
LIST
expected_output = "## Core\n## Special\n## Omgg\n## Moarheaders\n"
parsed = @parser.parse(list)
parsed.should_not be_nil
parsed.transform.should be expected_output
end
Which produces this output:
expected ## Core
## Special
## Omgg
## Moarheaders
, got "## Core\n## Special\n## Omgg\n## Moarheaders\n"
If I remove the double quotes, I get this output:
expected ## Core\n## Special\n## Omgg\n## Moarheaders\n,
got "## Core\n## Special\n## Omgg\n## Moarheaders\n"
If I add quotes to my expected_output, I get this:
(expected_output = '"## Core\n## Special\n## Omgg\n## Moarheaders\n"'
)
expected "## Core\n## Special\n## Omgg\n## Moarheaders\n",
got "## Core\n## Special\n## Omgg\n## Moarheaders\n"
What's going on here?
I can't get the Treetop result to evaluate the \n as newlines, and I can't get the expected_output to match regardless of what I try.
I'm confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过:
parsed.transform.should == Expected_output
be
可能会使用对象标识而不是比较字符串值。Did you try:
parsed.transform.should == expected_output
be
might use object identity instead of comparing the string values.