I keep getting this validation error in rspec. Could someone please tell what I'm doing wrong?
1) MyServer uses module
Failure/Error: expect(MyClient.methods.include?(:connect)).to be true
expected true
got false
# ./spec/myclient_spec.rb:13:in `block (2 levels) in <top (required)>'
This is my client.rb
#!/bin/ruby
require 'socket'
# Simple reuseable socket client
module SocketClient
def connect(host, port)
sock = TCPSocket.new(host, port)
begin
result = yield sock
ensure
sock.close
end
result
rescue Errno::ECONNREFUSED
end
end
# Should be able to connect to MyServer
class MyClient
include SocketClient
end
And this is my spec.rb
describe 'My server' do
subject { MyClient.new('localhost', port) }
let(:port) { 1096 }
it 'uses module' do
expect(MyClient.const_defined?(:SocketClient)).to be true
expect(MyClient.methods.include?(:connect)).to be true
end
I have method connect
defined in module SocketClient
. I don't understand why the test keeps failing.