Check the message to be encoded is the wrong type. (#4885) (#4949)

* Check the message to be encoded is the wrong type. (#4885)

* Change TypeError to ArgumentError
diff --git a/ruby/tests/encode_decode_test.rb b/ruby/tests/encode_decode_test.rb
index 2bd9b98..f8b991c 100644
--- a/ruby/tests/encode_decode_test.rb
+++ b/ruby/tests/encode_decode_test.rb
@@ -84,4 +84,14 @@
 
     assert_match 'optional_int32', json
   end
+
+  def test_encode_wrong_msg
+    e = assert_raise ::ArgumentError do
+      m = A::B::C::TestMessage.new(
+          :optional_int32 => 1,
+      )
+      Google::Protobuf::Any.encode(m)
+    end
+  end
+
 end