Skip to content

Instantly share code, notes, and snippets.

@rogercampos
Created June 25, 2012 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogercampos/2991763 to your computer and use it in GitHub Desktop.
Save rogercampos/2991763 to your computer and use it in GitHub Desktop.
Test an object without a method
# 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
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
@txus
Copy link

txus commented Jun 26, 2012

nice!

@rogercampos
Copy link
Author

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