guard-livereload 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require 'guard/compat/test/template'
2
+
3
+ RSpec.describe Guard::LiveReload do
4
+ describe 'template' do
5
+ subject { Guard::Compat::Test::Template.new(described_class) }
6
+
7
+ context 'Rails' do
8
+ context 'with view template files' do
9
+ it 'reloads full page' do
10
+ expect(subject.changed('app/views/foo.haml')).to eq(%w(app/views/foo.haml))
11
+ expect(subject.changed('app/views/foo.html.erb')).to eq(%w(app/views/foo.html.erb))
12
+ end
13
+ end
14
+
15
+ context 'when static files changes' do
16
+ it 'reloads just the assets' do
17
+ expect(subject.changed('public/foo.html')).to eq(%w(public/foo.html))
18
+ expect(subject.changed('public/foo.css')).to eq(%w(public/foo.css))
19
+ expect(subject.changed('public/foo.js')).to eq(%w(public/foo.js))
20
+ expect(subject.changed('public/foo.png')).to eq(%w(public/foo.png))
21
+ expect(subject.changed('public/foo.gif')).to eq(%w(public/foo.gif))
22
+ expect(subject.changed('public/foo.jpg')).to eq(%w(public/foo.jpg))
23
+ expect(subject.changed('public/foo.jpeg')).to eq(%w(public/foo.jpeg))
24
+ end
25
+ end
26
+
27
+ context 'with old Rails asset pipeline naming' do
28
+ it 'reloads' do
29
+ expect(subject.changed('app/assets/css/foo.css')).to eq(%w(/assets/foo.css))
30
+ expect(subject.changed('app/assets/css/foo.css.scss')).to eq(%w(/assets/foo.css))
31
+ expect(subject.changed('app/assets/css/foo.css.scss.erb')).to eq(%w(/assets/foo.css))
32
+
33
+ expect(subject.changed('app/assets/css/foo.js')).to eq(%w(/assets/foo.js))
34
+ expect(subject.changed('app/assets/css/foo.html')).to eq(%w(/assets/foo.html))
35
+ expect(subject.changed('app/assets/css/foo.png')).to eq(%w(/assets/foo.png))
36
+ expect(subject.changed('app/assets/css/foo.jpg')).to eq(%w(/assets/foo.jpg))
37
+ end
38
+
39
+ it 'handles edge cases' do
40
+ expect(subject.changed('app/assets/css/foo.css.')).to eq([])
41
+ expect(subject.changed('app/assets/css/foo.cssx')).to eq([])
42
+ expect(subject.changed('app/assets/css/foo.cssx.scss')).to eq([])
43
+ expect(subject.changed('app/assets/css/foo.bar.css')).to eq([])
44
+ end
45
+ end
46
+
47
+ context 'with new Rails asset pipeline naming' do
48
+ it 'reloads' do
49
+ expect(subject.changed('app/assets/css/foo.scss')).to eq(%w(/assets/foo.css))
50
+ expect(subject.changed('app/assets/css/foo.sass')).to eq(%w(/assets/foo.css))
51
+ expect(subject.changed('app/assets/js/foo.coffee')).to eq(%w(/assets/foo.js))
52
+
53
+ expect(subject.changed('app/assets/css/foo.sass.erb')).to eq(%w(/assets/foo.css))
54
+ end
55
+
56
+ it 'handles edge cases' do
57
+ expect(subject.changed('app/assets/css/foo_sass')).to eq([])
58
+ expect(subject.changed('app/assets/css/foo.sass.')).to eq([])
59
+ expect(subject.changed('app/assets/css/foo..sass')).to eq([])
60
+ expect(subject.changed('app/assets/css/foo.sassx')).to eq([])
61
+ expect(subject.changed('app/assets/css/foo.cssx.scss')).to eq([])
62
+ expect(subject.changed('app/assets/css/foo.bar.css')).to eq([])
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,12 +1,28 @@
1
- require 'spec_helper'
1
+ require 'guard/compat/test/helper'
2
2
 
3
- describe Guard::LiveReload do
3
+ RSpec.describe Guard::LiveReload do
4
4
  let(:plugin) { Guard::LiveReload.new }
5
5
  let(:reactor) { double(Guard::LiveReload::Reactor) }
6
- before { allow(plugin).to receive(:reactor) { reactor } }
7
6
 
8
- describe "#initialize" do
9
- describe ":host option" do
7
+ let(:tmp_path) { '/tmp/livereload-123' }
8
+ let(:snippet) { instance_double(Guard::LiveReload::Snippet, path: tmp_path) }
9
+
10
+ before do
11
+ allow(File).to receive(:expand_path) do |*args|
12
+ fail "stub called for File.expand_path(#{args.map(&:inspect) * ','})"
13
+ end
14
+
15
+ allow(File).to receive(:expand_path).
16
+ with('../../../js/livereload.js.erb', anything).
17
+ and_return('/foo/js/livereload.js.erb')
18
+
19
+ allow(Guard::LiveReload::Snippet).to receive(:new).and_return(snippet)
20
+
21
+ allow(plugin).to receive(:reactor) { reactor }
22
+ end
23
+
24
+ describe '#initialize' do
25
+ describe ':host option' do
10
26
  it "is '0.0.0.0' by default" do
11
27
  plugin = Guard::LiveReload.new
12
28
  expect(plugin.options[:host]).to eq '0.0.0.0'
@@ -18,7 +34,7 @@ describe Guard::LiveReload do
18
34
  end
19
35
  end
20
36
 
21
- describe ":port option" do
37
+ describe ':port option' do
22
38
  it "is '35729' by default" do
23
39
  plugin = Guard::LiveReload.new
24
40
  expect(plugin.options[:port]).to eq '35729'
@@ -30,83 +46,119 @@ describe Guard::LiveReload do
30
46
  end
31
47
  end
32
48
 
33
- describe ":apply_css_live option" do
34
- it "is true by default" do
49
+ describe ':apply_css_live option' do
50
+ it 'is true by default' do
35
51
  plugin = Guard::LiveReload.new
36
52
  expect(plugin.options[:apply_css_live]).to be_truthy
37
53
  end
38
54
 
39
- it "can be set to false" do
55
+ it 'can be set to false' do
40
56
  plugin = Guard::LiveReload.new(apply_css_live: false)
41
57
  expect(plugin.options[:apply_css_live]).to be_falsey
42
58
  end
43
59
  end
44
60
 
45
- describe ":override_url option" do
46
- it "is false by default" do
61
+ describe ':override_url option' do
62
+ it 'is false by default' do
47
63
  plugin = Guard::LiveReload.new
48
64
  expect(plugin.options[:override_url]).to be_falsey
49
65
  end
50
66
 
51
- it "can be set to false" do
67
+ it 'can be set to false' do
52
68
  plugin = Guard::LiveReload.new(override_url: true)
53
69
  expect(plugin.options[:override_url]).to be_truthy
54
70
  end
55
71
  end
56
72
 
57
- describe ":grace_period option" do
58
- it "is 0 by default" do
73
+ describe ':grace_period option' do
74
+ it 'is 0 by default' do
59
75
  plugin = Guard::LiveReload.new
60
76
  expect(plugin.options[:grace_period]).to eq 0
61
77
  end
62
78
 
63
- it "can be set to 0.5" do
79
+ it 'can be set to 0.5' do
64
80
  plugin = Guard::LiveReload.new(grace_period: 0.5)
65
81
  expect(plugin.options[:grace_period]).to eq 0.5
66
82
  end
67
83
  end
84
+
85
+ describe ':js_template option' do
86
+ subject { described_class.new(*args) }
87
+
88
+ context 'when no value is provided' do
89
+ let(:args) { [] }
90
+
91
+ it 'is set to full path to default JS' do
92
+ expect(subject.options[:js_template]).to eq '/foo/js/livereload.js.erb'
93
+ end
94
+
95
+ it 'evalutes the default snippet' do
96
+ expect(Guard::LiveReload::Snippet).to receive(:new).
97
+ with('/foo/js/livereload.js.erb', anything).and_return(snippet)
98
+ subject
99
+ end
100
+ end
101
+
102
+ context 'with a custom path' do
103
+ let(:args) { [js_template: 'foo/bar.js.erb'] }
104
+
105
+ it 'is set to the given JS' do
106
+ expect(subject.options[:js_template]).to eq 'foo/bar.js.erb'
107
+ end
108
+
109
+ it 'evalutes the provided snippet' do
110
+ expect(Guard::LiveReload::Snippet).to receive(:new).
111
+ with('foo/bar.js.erb', anything).and_return(snippet)
112
+ subject
113
+ end
114
+ end
115
+ end
68
116
  end
69
117
 
70
- describe "#start" do
71
- it "creates reactor with default options" do
118
+ describe '#start' do
119
+ it 'creates reactor with default options' do
72
120
  plugin = Guard::LiveReload.new
73
121
  expect(Guard::LiveReload::Reactor).to receive(:new).with(
74
122
  host: '0.0.0.0',
75
123
  port: '35729',
76
124
  apply_css_live: true,
77
125
  override_url: false,
78
- grace_period: 0
126
+ grace_period: 0,
127
+ js_template: '/foo/js/livereload.js.erb',
128
+ livereload_js_path: '/tmp/livereload-123'
79
129
  )
80
130
  plugin.start
81
131
  end
82
132
 
83
- it "creates reactor with given options" do
133
+ it 'creates reactor with given options' do
84
134
  plugin = Guard::LiveReload.new(host: '127.3.3.1', port: '12345', apply_css_live: false, override_url: true, grace_period: 1)
85
135
  expect(Guard::LiveReload::Reactor).to receive(:new).with(
86
136
  host: '127.3.3.1',
87
137
  port: '12345',
88
138
  apply_css_live: false,
89
139
  override_url: true,
90
- grace_period: 1
140
+ grace_period: 1,
141
+ js_template: '/foo/js/livereload.js.erb',
142
+ livereload_js_path: '/tmp/livereload-123'
91
143
  )
92
144
  plugin.start
93
145
  end
94
146
  end
95
147
 
96
- describe "#stop" do
97
- it "stops the reactor" do
148
+ describe '#stop' do
149
+ it 'stops the reactor' do
98
150
  expect(reactor).to receive(:stop)
99
151
  plugin.stop
100
152
  end
101
153
  end
102
154
 
103
- describe "#run_on_modifications" do
104
- it "reloads browser" do
155
+ describe '#run_on_modifications' do
156
+ it 'reloads browser' do
105
157
  expect(reactor).to receive(:reload_browser).with(['foo'])
106
158
  plugin.run_on_modifications(['foo'])
107
159
  end
108
160
 
109
- it "can wait 0.5 seconds before reloading the browser" do
161
+ it 'can wait 0.5 seconds before reloading the browser' do
110
162
  expect(reactor).to receive(:reload_browser).with(['foo'])
111
163
  expect(plugin).to receive(:sleep).with(0.5)
112
164
  plugin.options[:grace_period] = 0.5
@@ -3,10 +3,33 @@ Coveralls.wear!
3
3
 
4
4
  require 'rspec'
5
5
  require 'guard/livereload'
6
- ENV["GUARD_ENV"] = 'test'
7
6
 
8
7
  RSpec.configure do |config|
9
- config.color = true
10
- config.filter_run focus: true
8
+
9
+ def ci?
10
+ ENV['CI'] == 'true'
11
+ end
12
+
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
15
+ end
16
+
17
+ config.mock_with :rspec do |mocks|
18
+ mocks.verify_partial_doubles = true
19
+ end
20
+
21
+ config.filter_run focus: !ci?
11
22
  config.run_all_when_everything_filtered = true
23
+
24
+ config.disable_monkey_patching!
25
+
26
+ config.warnings = true
27
+
28
+ config.default_formatter = 'doc' if config.files_to_run.one?
29
+
30
+ # config.profile_examples = 10
31
+
32
+ config.order = :random
33
+
34
+ Kernel.srand config.seed
12
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaud Guillaume-Gentil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard-compat
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: em-websocket
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,34 +80,6 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: 1.3.5
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  description: Guard::LiveReload automatically reloads your browser when 'view' files
98
84
  are modified.
99
85
  email: thibaud@thibaud.me
@@ -102,6 +88,13 @@ extensions: []
102
88
  extra_rdoc_files: []
103
89
  files:
104
90
  - ".gitignore"
91
+ - ".hound.yml"
92
+ - ".hound/defaults.yml"
93
+ - ".hound/overrides.yml"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
96
+ - ".rubocop_merged_for_hound.yml"
97
+ - ".rubocop_todo.yml"
105
98
  - ".travis.yml"
106
99
  - Gemfile
107
100
  - Guardfile
@@ -109,13 +102,16 @@ files:
109
102
  - README.md
110
103
  - Rakefile
111
104
  - guard-livereload.gemspec
112
- - js/livereload.js
105
+ - js/livereload.js.erb
113
106
  - lib/guard/livereload.rb
114
107
  - lib/guard/livereload/reactor.rb
108
+ - lib/guard/livereload/snippet.rb
115
109
  - lib/guard/livereload/templates/Guardfile
116
110
  - lib/guard/livereload/version.rb
117
111
  - lib/guard/livereload/websocket.rb
118
112
  - spec/lib/guard/livereload/reactor_spec.rb
113
+ - spec/lib/guard/livereload/snippet_spec.rb
114
+ - spec/lib/guard/livereload/template_spec.rb
119
115
  - spec/lib/guard/livereload_spec.rb
120
116
  - spec/spec_helper.rb
121
117
  homepage: https://rubygems.org/gems/guard-livereload
@@ -138,11 +134,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
134
  version: '0'
139
135
  requirements: []
140
136
  rubyforge_project:
141
- rubygems_version: 2.2.2
137
+ rubygems_version: 2.4.8
142
138
  signing_key:
143
139
  specification_version: 4
144
140
  summary: Guard plugin for livereload
145
141
  test_files:
146
142
  - spec/lib/guard/livereload/reactor_spec.rb
143
+ - spec/lib/guard/livereload/snippet_spec.rb
144
+ - spec/lib/guard/livereload/template_spec.rb
147
145
  - spec/lib/guard/livereload_spec.rb
148
146
  - spec/spec_helper.rb