guard-pusher 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module PusherVersion
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/lib/guard/pusher.rb CHANGED
@@ -1,22 +1,36 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
3
  require 'pusher'
4
+ require 'erb'
4
5
 
5
6
  module Guard
6
7
  class Pusher < Guard
7
8
 
9
+ def self.configure(options)
10
+ %w{app_id key secret}.inject(Hash.new) { |hash, key|
11
+ hash[key] = options[key] || options[key.to_sym]
12
+ hash
13
+ }.each { |config, value|
14
+ ::Pusher.send("#{config}=", value)
15
+ }
16
+
17
+ ::Pusher['guard-pusher']
18
+
19
+ rescue ::Pusher::ConfigurationError
20
+ end
21
+
8
22
  def initialize(watchers = [], options = {})
9
23
  super
10
24
 
11
25
  @options = options
12
26
 
13
27
  config = if File.file?('config/pusher.yml')
14
- YAML.load_file('config/pusher.yml')['development']
28
+ YAML.load(ERB.new(File.read('config/pusher.yml')).result)['development']
15
29
  else
16
30
  options
17
31
  end
18
32
 
19
- if config_pusher_with(config)
33
+ if self.class.configure(config)
20
34
  UI.info('Pusher is ready.', :reset => true)
21
35
  else
22
36
  UI.info("D'oh! Pusher not properly configured. Make sure to add app_id, key and secret.", :reset => true)
@@ -24,18 +38,7 @@ module Guard
24
38
  end
25
39
 
26
40
  def run_on_change(paths)
27
- ::Pusher['guard-pusher'].trigger(@options[:event] || 'guard', {})
28
- end
29
-
30
-
31
- private
32
-
33
- def config_pusher_with(credentials)
34
- %w{app_id key secret}.each do |config|
35
- return false unless (value = credentials[config] || credentials[config.to_sym])
36
- ::Pusher.send("#{config}=", value)
37
- end
38
- true
41
+ ::Pusher['guard-pusher'].trigger(@options[:event] || 'guard', { :paths => paths })
39
42
  end
40
43
 
41
44
  end
@@ -2,70 +2,103 @@ require 'spec_helper'
2
2
 
3
3
  describe Guard::Pusher do
4
4
 
5
+ def with_yaml(config = nil)
6
+ config ||= {
7
+ 'development' => {
8
+ 'app_id' => 42,
9
+ 'key' => 'fake_key',
10
+ 'secret' => 'fake_secret'
11
+ }
12
+ }
13
+
14
+ File.should_receive(:file?).with('config/pusher.yml').and_return(true)
15
+ File.should_receive(:read).with('config/pusher.yml')
16
+ ERB.should_receive(:new).and_return(double('erb', :result => 'erb_foo'))
17
+ YAML.should_receive(:load).with('erb_foo').and_return(config)
18
+ end
19
+
20
+ def without_yaml
21
+ File.should_receive(:file?).with('config/pusher.yml').and_return(false)
22
+ end
23
+
5
24
  describe "configuration" do
6
- context "provided through YAML file" do
7
- before(:each) do
8
- File.should_receive(:file?).
9
- with('config/pusher.yml').
10
- and_return(true)
11
-
12
- YAML.should_receive(:load_file).
13
- with('config/pusher.yml').
14
- and_return({ "development" => { "app_id" => 42, "key" => "fake_key", "secret" => "fake_secret" }})
25
+
26
+ context "via YAML file" do
27
+ context "when credentials are complete" do
28
+ before(:each) do
29
+ with_yaml
30
+ end
31
+
32
+ it "is successful" do
33
+ Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
34
+ Guard::Pusher.new([])
35
+ end
15
36
  end
16
37
 
17
- it "requires 'app_id', 'key' and 'secret'" do
18
- Pusher.should_receive(:app_id=).with(42)
19
- Pusher.should_receive(:key=).with('fake_key')
20
- Pusher.should_receive(:secret=).with('fake_secret')
21
- Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
22
- Guard::Pusher.new([])
38
+ context "when credentials are incomplete" do
39
+ before(:each) do
40
+ with_yaml({ 'development' => { 'key' => 'fake_key', 'secret' => 'fake_secret' }})
41
+ Pusher.app_id = nil
42
+ end
43
+
44
+ it "issues a warning" do
45
+ Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
46
+ Guard::Pusher.new([])
47
+ end
23
48
  end
24
49
  end
25
50
 
26
- context "provided through options" do
27
- before(:each) do
28
- File.should_receive(:file?).
29
- with('config/pusher.yml').
30
- and_return(false)
51
+ context "via options" do
52
+ context "when credentials are complete" do
53
+ before(:each) do
54
+ without_yaml
55
+ end
56
+
57
+ it "is successful" do
58
+ Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
59
+ Guard::Pusher.new([], {
60
+ :app_id => 42,
61
+ :key => 'fake_key',
62
+ :secret => 'fake_secret'
63
+ })
64
+ end
31
65
  end
32
66
 
33
- it "requires 'app_id', 'key' and 'secret'" do
34
- Pusher.should_receive(:app_id=).with(42)
35
- Pusher.should_receive(:key=).with('fake_key')
36
- Pusher.should_receive(:secret=).with('fake_secret')
37
- Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
38
- Guard::Pusher.new([], {
39
- :app_id => 42,
40
- :key => 'fake_key',
41
- :secret => 'fake_secret'
42
- })
67
+ context "when credentials are incomplete" do
68
+ before(:each) do
69
+ without_yaml
70
+ end
71
+
72
+ it "issues a warning" do
73
+ Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
74
+ Guard::Pusher.new([], {
75
+ :key => 'fake_key',
76
+ :secret => 'fake_secret'
77
+ })
78
+ end
43
79
  end
44
80
  end
45
81
 
46
- context "missing the necessery keys" do
47
- before(:each) do
48
- File.should_receive(:file?).
49
- with('config/pusher.yml').
50
- and_return(false)
51
- end
82
+ end
52
83
 
53
- it "does not attempt to configure Pusher and issues a warning" do
54
- Pusher.should_not_receive(:app_id=)
55
- Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
56
- Guard::Pusher.new([], {
57
- :key => 'fake_key',
58
- :secret => 'fake_secret'
59
- })
60
- end
84
+ describe "options" do
85
+ before(:each) do
86
+ with_yaml
87
+ end
88
+
89
+ it ":event" do
90
+ channel = mock(Pusher::Channel)
91
+ Pusher.stub(:[]).and_return(channel)
92
+ channel.should_receive(:trigger).with('custom', { :paths => ['foo'] })
93
+ Guard::Pusher.new([], { :event => 'custom' }).run_on_change(['foo'])
61
94
  end
62
95
  end
63
96
 
64
- describe "run_on_change" do
97
+ describe "#run_on_change" do
65
98
  it "sends Pusher message" do
66
99
  channel = mock(Pusher::Channel)
67
- Pusher.should_receive(:[]).with('guard-pusher').and_return(channel)
68
- channel.should_receive(:trigger).with('guard', {})
100
+ Pusher.should_receive(:[]).with('guard-pusher').twice.and_return(channel)
101
+ channel.should_receive(:trigger).with('guard', { :paths => ['foo'] })
69
102
  subject.run_on_change(['foo'])
70
103
  end
71
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease: !!null
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire: !!null
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-01 00:00:00.000000000 +01:00
12
+ date: 2011-06-16 00:00:00.000000000 +02:00
13
13
  default_executable: !!null
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: guard
17
- requirement: &2156752380 !ruby/object:Gem::Requirement
17
+ requirement: &2165084760 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156752380
25
+ version_requirements: *2165084760
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: pusher
28
- requirement: &2156751880 !ruby/object:Gem::Requirement
28
+ requirement: &2165084260 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2156751880
36
+ version_requirements: *2165084260
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &2156751420 !ruby/object:Gem::Requirement
39
+ requirement: &2165083800 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2156751420
47
+ version_requirements: *2165083800
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &2156750960 !ruby/object:Gem::Requirement
50
+ requirement: &2165083340 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.3.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2156750960
58
+ version_requirements: *2165083340
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: guard-rspec
61
- requirement: &2156750580 !ruby/object:Gem::Requirement
61
+ requirement: &2165082960 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2156750580
69
+ version_requirements: *2165082960
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rb-fsevent
72
- requirement: &2156750120 !ruby/object:Gem::Requirement
72
+ requirement: &2165082500 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2156750120
80
+ version_requirements: *2165082500
81
81
  description: Pusher guard allows to automatically send a Pusher message to any number
82
82
  of browsers.
83
83
  email: