-
-
Save Pamplemousse/47b56760a1e20e391b0b to your computer and use it in GitHub Desktop.
RSpec matcher for alias_method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RSpec matcher for alias_method. | |
# https://gist.github.com/47b56760a1e20e391b0b | |
# Usage: | |
# | |
# describe User do | |
# it { expect(subject).to alias_from(:username).to(:email) } | |
# end | |
RSpec::Matchers.define :alias_from do |alias_method| | |
match do |subject| | |
begin | |
subject.send(alias_method) | |
rescue NoMethodError | |
raise "expected alias_method from #{alias_method} to #{@original_method} but #{alias_method} is not defined" | |
end | |
expect(subject.method(alias_method)).to eq(subject.method(@original_method)) | |
end | |
description do | |
"RSpec matcher for alias_method" | |
end | |
failure_message do |text| | |
"expected alias_method from #{alias_method} to #{@original_method}" | |
end | |
failure_message_when_negated do |text| | |
"do not expected alias_method from #{alias_method} to #{@original_method}" | |
end | |
chain(:to) { |original_method| @original_method = original_method } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment