foo.should_receive( :save ).with( html )
HTML 字符串在哪里html
,但我不想检查特定的 HTML,因为这会使测试变得脆弱。
有没有办法检查 foo 应该收到的参数的长度?是否可以使用匹配器或类似的东西html.should include '<html'
?
在 RSpec 中工作。
foo.should_receive( :save ).with( html )
HTML 字符串在哪里html
,但我不想检查特定的 HTML,因为这会使测试变得脆弱。
有没有办法检查 foo 应该收到的参数的长度?是否可以使用匹配器或类似的东西html.should include '<html'
?
在 RSpec 中工作。
I don't see why that would not work using the code you provided. Maybe use include?
instead. You also could use a regex to determine if it was HTML. While for this specific example it might be a little much, you may be able to determine more specific things about the html then just if it has that tag.
如上面的评论所述,您可以使用正则表达式作为参数匹配器。
foo.should_receive(:save).with(/<html/)
如果你想做更复杂的断言,你可以提供一个块:
foo.should_receive(:save).with do |arg|
arg.should include '<html'
end