From: "Jon A. Lambert" Date: 2005-10-02T01:21:36+09:00 Subject: Flexmock question How do I use flexmock to mock a Socket? It seems to trip up on the defining a method named 'send' on the object. Simple code to reproduce the problem. ----- require 'test/unit' require 'flexmock' class TestSocket < Test::Unit::TestCase def setup @sock = FlexMock.new @sock.mock_handle(:recv, 1) { |size,flag| "hello world\r\n" } @sock.mock_handle(:send, 1) { |message,flag| message.size } @sock.mock_handle(:xsend, 1) { |message,flag| message.size } end def test_recv assert_equal("hello world\r\n", @sock.recv) end def test_send assert_equal(13, @sock.send("hello world\r\n")) end def test_xsend assert_equal(13, @sock.xsend("hello world\r\n")) end end ------------- $ ruby test/test_socket.rb Loaded suite test/test_socket Started .E. Finished in 0.003 seconds. 1) Error: test_send(TestSocket): NoMethodError: undefined method `hello world ' for # /usr/lib/ruby/gems/1.8/gems/flexmock-0.0.3-/lib/flexmock.rb:72:in `method_missing' test/test_socket.rb:17:in `send' test/test_socket.rb:17:in `test_send' 3 tests, 2 assertions, 0 failures, 1 errors -- J. Lambert