ruby - Why do I get "Undefined method ::new" in simple classes? -


i writing atm-system-like socket/server solution. appreciate if tell me i'm missing. reason, following error running stub test suite:

# running tests:  .e  finished tests in 0.002411s, 829.4384 tests/s, 414.7192 assertions/s.    1) error: test_0001_connects_to_a_host_with_a_socket(atmclient::connection): nomethoderror: undefined method `new' #<spoofserver:0x9dce2dc @clients=[], @server=#<tcpserver:fd 5>>     /media/wildfyre/files/programming/kth/progp/atm/spec/client/spoofserver.rb:12:in `start'     /media/wildfyre/files/programming/kth/progp/atm/spec/client/client_spec.rb:12:in `block (3 levels) in <top (required)>'  2 tests, 1 assertions, 0 failures, 1 errors, 0 skips 

my minispec file is:

require_relative '../spec_helper.rb' require_relative '../../lib/atmclient.rb' require_relative 'spoofserver.rb'  describe atmclient   "can created no arguments"     atmclient.new.must_be_instance_of atmclient   end    describe 'connection'     "connects host socket"       spoof = spoofserver.new.start       client = atmclient.new.connect       spoof.any_incoming_connection?.must_be true       spoof.kill     end   end end 

my spoofserver file is:

require 'socket'  class spoofserver    def initialize   end    def start     @clients = []     @server = tcpserver.new 1234      @listener_thread = new thread       @clients.add @server.accept     end   end    def any_incoming_connection?     @clients.size > 0   end    def kill     @listener_thread.exit     @clients.each {|c| c.close}   end  end 

as can read in trace of calls stack:

nomethoderror: undefined method `new' #<spoofserver:...>     /.../spec/client/spoofserver.rb:12:in `start' 

the error inside start method defined in spoofserver.rb, @ line 12, wrong line is:

@listener_thread = new thread 

that should be:

@listener_thread = thread.new 

as have written it, doing calling new method passing thread class argument. since no new method defined instances of spoofserver class nomethoderror exception.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -