2009-08-22 45 views

回答

1

我們可以隨時編寫自定義匹配器。

或者使用by_at_most的組合by_at_least的匹配,像這樣的精度:

lambda { ...}.should change(unit, :price).by_at_most(12.15 + 10e-5).by_at_least(12.15 - 10e-5) 
0

這似乎並不可能與代碼的當前狀態。這裏是Matchers :: Change的來源,您可以在其中看到它:http://github.com/dchelimsky/rspec/blob/f9ef5bff62c10d33414c9ab2f3ac87e1256e07b8/lib/spec/matchers/change.rb

匹配上限是否可以接受?例如:

lambda { ...}.should change(unit, :price).by_at_most(12.15) 
+0

是的,如果我們使用by_at_most和by_at_least在一起,可以解決這個問題。不完美的解決方案,但工程。 – 2009-08-23 06:51:21