spec/cucumber/pro/web_socket/worker_spec.rb in cucumber-pro-0.0.14 vs spec/cucumber/pro/web_socket/worker_spec.rb in cucumber-pro-0.0.15

- old
+ new

@@ -35,11 +35,29 @@ eventually do expect( worker ).to be_closed end end - it "throws an error if the server responds with an error" + it "throws an error if the server responds with an error" do + worker.send(good_data) + worker.close + eventually do + expect(socket.data.last).to eq good_data + end + eventually do + expect( worker ).to_not be_closed + end + begin + socket.send_error + fail + rescue => expected + expect(expected.message).to eq('an error happened on the server') + eventually do + expect( worker ).to be_closed + end + end + end def create_fake_socket(worker) socket.worker = worker EM.next_tick { worker.method(:on_open).call(double('ws event')) @@ -70,10 +88,15 @@ def send_ack event = ws_event(1000, { 'type' => 'metadata_saved' }) worker.method(:on_message).call(event) end + def send_error + event = ws_event(1000, { 'error' => 'an error happened on the server' }) + worker.method(:on_message).call(event) + end + def data @data ||= [] while !@q.empty? @data << @q.pop end @@ -81,10 +104,10 @@ end private def ws_event(code, data = {}) - double('ws event', code: 1000, data: data) + double('ws event', code: 1000, data: data.to_json) end end require 'anticipate'