/
pusher_spec.rb
73 lines (63 loc) · 2.19 KB
/
pusher_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'spec_helper'
describe Guard::Pusher do
describe "configuration" do
context "provided through YAML file" do
before(:each) do
File.should_receive(:file?).
with('config/pusher.yml').
and_return(true)
YAML.should_receive(:load_file).
with('config/pusher.yml').
and_return({ "development" => { "app_id" => 42, "key" => "fake_key", "secret" => "fake_secret" }})
end
it "requires 'app_id', 'key' and 'secret'" do
Pusher.should_receive(:app_id=).with(42)
Pusher.should_receive(:key=).with('fake_key')
Pusher.should_receive(:secret=).with('fake_secret')
Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
Guard::Pusher.new([])
end
end
context "provided through options" do
before(:each) do
File.should_receive(:file?).
with('config/pusher.yml').
and_return(false)
end
it "requires 'app_id', 'key' and 'secret'" do
Pusher.should_receive(:app_id=).with(42)
Pusher.should_receive(:key=).with('fake_key')
Pusher.should_receive(:secret=).with('fake_secret')
Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
Guard::Pusher.new([], {
:app_id => 42,
:key => 'fake_key',
:secret => 'fake_secret'
})
end
end
context "missing the necessery keys" do
before(:each) do
File.should_receive(:file?).
with('config/pusher.yml').
and_return(false)
end
it "does not attempt to configure Pusher and issues a warning" do
Pusher.should_not_receive(:app_id=)
Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
Guard::Pusher.new([], {
:key => 'fake_key',
:secret => 'fake_secret'
})
end
end
end
describe "run_on_change" do
it "sends Pusher message" do
channel = mock(Pusher::Channel)
Pusher.should_receive(:[]).with('guard-pusher').and_return(channel)
channel.should_receive(:trigger).with('guard', {})
subject.run_on_change(['foo'])
end
end
end