Created
June 25, 2012 22:23
-
-
Save rogercampos/2991763 to your computer and use it in GitHub Desktop.
Test an object without a 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
# https://github.com/rogercampos/armot/blob/master/test/armot_test.rb#L514 | |
test "should work if the I18n backend has not fallbacks" do | |
with_no_method(I18n.singleton_class, :fallbacks) do | |
assert_equal false, I18n.respond_to?(:fallbacks) | |
post = Post.last | |
I18n.locale = :pt | |
assert_equal nil, post.title | |
end | |
end |
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
def with_no_method(target, name) | |
target.send(:alias_method, :method_backup, name) | |
target.send(:remove_method, name) | |
yield | |
ensure | |
target.send(:alias_method, name, :method_backup) | |
end |
Thanks! Was playing a bit with how to do this and it's the best I could get. Do you have any advice?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!