Sha256: f57bbdb8507d345fdc0be27c72e2e53ef255bccd7861cbff636bf2978bbf19d0

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'pokeplot/socket'
require 'pokeplot/database'
require 'eventmachine'

describe Pokeplot::Socket do

  describe ".new" do
    data = [{:pokemon => 1, :spawn_point_id => 1}, {:pokemon => 2, :spawn_point_id => 2}, {:pokemon => 1, :spawn_point_id => 1}]

    it "should start a websocket" do
      ws = double()
      allow(ws).to receive(:onopen).and_yield(ws)
      allow(ws).to receive(:onclose).and_yield
      allow(ws).to receive(:onmessage)
      allow(ws).to receive(:send)

      db = double()
      allow(db).to receive(:[]).and_return(db)
      allow(db).to receive(:find).and_return(data)

      expect(Thread).to receive(:new).and_yield
      expect(Pokeplot::Database).to receive(:mongo).and_return(db)
      expect(EventMachine).to receive(:run).and_yield
      expect(EM::WebSocket).to receive(:run).and_yield(ws)
      described_class.new
    end
  end

  describe "#started" do
    data = {'insert' => 'encounters', 'documents' => ["pokemon data"]}

    it "should send data to the clients" do
      client = double()
      allow(client).to receive(:send)

      event = double(:command => data)

      expect(Thread).to receive(:new).and_return(nil)
      socket = described_class.new
      socket.instance_variable_set(:@clients, [client])
      socket.started(event)
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pokeplot-0.2.1beta spec/socket_spec.rb
pokeplot-0.2.0beta spec/socket_spec.rb