【发布时间】:2014-12-30 04:51:03
【问题描述】:
我在使用 RSpec 和 Draper 装饰对象中的相等匹配器时遇到问题。
说明正在发生的事情的规格:
context 'how to use the right equality matcher' do
let(:page) { build(:page) }
let(:decorated_page) { page.decorate }
it "should pass, but doesn't" do
expect(decorated_page).to_not eq page
end
it 'proves the classes are different' do
expect(decorated_page).to be_a PageDecorator
expect(page).to be_a Page
expect(decorated_page.class).to_not eq page.class
end
it 'has a work around' do
expect(decorated_page).to be_decorated_with PageDecorator
expect(page).to_not be_decorated_with PageDecorator
end
end
我知道 RSpec 有一个 few different equality checkers,而 eq 是“最弱的”,但我认为没有相同的课程会破坏交易。
如您所见,感谢Draper's matchers,我可以解决这个问题。但我觉得我一定是错过了一些东西才能让测试失败。
问题:
我应该使用什么相等匹配器来让should pass, but doesn't 测试通过?
【问题讨论】:
-
eq匹配器只是在对象上使用==运算符,所以这不是真正的 RSpec 问题,而是 Draper 问题。 -
如果你创建页面而不是构建呢?
-
@DavidGrayson 我同意。我希望有另一个平等匹配器适用于这种情况,但我认为不会。这可能就是 Draper 提供匹配器工作的原因。
-
@RustamA.Gasanov 不,同样的问题。我认为 David 的想法是正确的 - 这不是 Draper 的预期工作方式。