Article#to_archive
是Article#archived!
的别名:
class Article
alias to_archive archived!
end
我需要确保这一点,所以我写了这个测试:
describe '#to_archive' do
it 'is an alias to #archived!' do
expect(subject.method(:to_archive)).to eq(subject.method(:archived!))
end
end
但是,我收到错误
Failure/Error: expect(subject.method(:to_archive)).to eq(subject.method(:archived!))
expected: #<Method: Article(#<Module:0x00000005a7c240>)#archived!>
got: #<Method: Article(#<Module:0x00000005a7c240>)#to_archive(archived!)>
它曾用于ruby&lt; 2.3 IIRC。我试过了alias_method
,但没有用。
答案 0 :(得分:5)
Method#==
的定义不明确和/或有用,所以你不应该依赖它。
要检查它是否为别名,您可以执行以下操作:
expect(subject.method(:to_archive).original_name).to eq(:archived!)