Skip to content

Commit

Permalink
Merge pull request #104 from jmuheim/master
Browse files Browse the repository at this point in the history
Display "Browser connected." only once. Never display "Browser disconnected."
  • Loading branch information
thibaudgg committed Mar 20, 2014
2 parents 49d3a28 + e759122 commit b329fa2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/guard/livereload/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
module Guard
class LiveReload
class Reactor
attr_reader :web_sockets, :thread, :options
attr_reader :web_sockets, :thread, :options, :connections_count

def initialize(options)
@web_sockets = []
@options = options
@thread = Thread.new { _start_reactor }
@web_sockets = []
@options = options
@thread = Thread.new { _start_reactor }
@connections_count = 0
end

def stop
Expand Down Expand Up @@ -51,7 +52,9 @@ def _start_reactor
end

def _connect(ws)
UI.info "Browser connected."
@connections_count += 1
UI.info "Browser connected." if connections_count == 1

ws.send MultiJson.encode(
command: 'hello',
protocols: ['http://livereload.com/protocols/official-7'],
Expand All @@ -64,7 +67,6 @@ def _connect(ws)
end

def _disconnect(ws)
UI.info "Browser disconnected."
@web_sockets.delete(ws)
end

Expand Down
17 changes: 17 additions & 0 deletions spec/lib/guard/livereload/reactor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
end
end

describe "#_connect(ws)" do
let(:ws) { double.as_null_object }
let(:reactor) { new_live_reactor }

it "displays a message once" do
expect(Guard::UI).to receive(:info).with("Browser connected.").once
reactor.send(:_connect, ws)
reactor.send(:_connect, ws)
end

it "increments the connection count" do
expect {
reactor.send(:_connect, ws)
}.to change { reactor.connections_count }.from(0).to 1
end
end

end

def new_live_reactor(options = {})
Expand Down

0 comments on commit b329fa2

Please sign in to comment.