spec/webmachine/adapters/reel_spec.rb in webmachine-1.2.2 vs spec/webmachine/adapters/reel_spec.rb in webmachine-1.3.0

- old
+ new

@@ -1,17 +1,21 @@ require 'spec_helper' require 'webmachine/spec/adapter_lint' describe Webmachine::Adapters::Reel do - it_should_behave_like :adapter_lint - - let(:configuration) { Webmachine::Configuration.default } - let(:dispatcher) { Webmachine::Dispatcher.new } - let(:adapter) do - described_class.new(configuration, dispatcher) + context 'lint' do + it_should_behave_like :adapter_lint end context 'websockets' do + let(:application) { Webmachine::Application.new } + let(:adapter) do + server = TCPServer.new('0.0.0.0', 0) + application.configuration.port = server.addr[1] + server.close + described_class.new(application) + end + let(:example_host) { "www.example.com" } let(:example_path) { "/example"} let(:example_url) { "ws://#{example_host}#{example_path}" } let :handshake_headers do { @@ -26,12 +30,12 @@ end let(:client_message) { "Hi server!" } let(:server_message) { "Hi client!" } it 'supports websockets' do - configuration.adapter_options[:websocket_handler] = proc do |socket| - socket.read.should eq client_message + application.configuration.adapter_options[:websocket_handler] = proc do |socket| + expect(socket.read).to eq client_message socket << server_message end reel_server(adapter) do |client| client << WebSocket::ClientHandshake.new(:get, example_url, handshake_headers).to_data @@ -42,21 +46,21 @@ client << WebSocket::Message.new(client_message).to_data parser = WebSocket::Parser.new parser.append client.readpartial(4096) until message = parser.next_message - message.should eq server_message + expect(message).to eq server_message end end end def reel_server(adptr = adapter) thread = Thread.new { adptr.run } begin timeout(5) do begin - sock = TCPSocket.new(adptr.configuration.ip, adptr.configuration.port) + sock = TCPSocket.new(adptr.application.configuration.ip, adptr.application.configuration.port) begin yield(sock) ensure sock.close end @@ -64,9 +68,9 @@ Thread.pass retry end end ensure - adptr.shutdown + thread.kill if thread end end end