fluid_cli 0.1.4 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/fluid_cli/api.rb +9 -3
- data/lib/fluid_cli/http_request.rb +7 -1
- data/lib/fluid_cli/theme/syncer.rb +93 -13
- data/lib/fluid_cli/version.rb +1 -1
- data/lib/fluid_cli.rb +1 -0
- data/packaging/homebrew/fluid_cli.base.rb +5 -9
- metadata +30 -97
- data/vendor/deps/listen/.github/release-drafter.yml +0 -17
- data/vendor/deps/listen/.github/workflows/development.yml +0 -67
- data/vendor/deps/listen/.github/workflows/push.yml +0 -12
- data/vendor/deps/listen/.gitignore +0 -28
- data/vendor/deps/listen/.rspec +0 -3
- data/vendor/deps/listen/.rubocop.yml +0 -283
- data/vendor/deps/listen/.yardopts +0 -11
- data/vendor/deps/listen/CHANGELOG.md +0 -1
- data/vendor/deps/listen/CONTRIBUTING.md +0 -45
- data/vendor/deps/listen/Gemfile +0 -33
- data/vendor/deps/listen/Guardfile +0 -26
- data/vendor/deps/listen/LICENSE.txt +0 -22
- data/vendor/deps/listen/README.md +0 -490
- data/vendor/deps/listen/Rakefile +0 -154
- data/vendor/deps/listen/bin/listen +0 -11
- data/vendor/deps/listen/lib/listen/adapter/base.rb +0 -129
- data/vendor/deps/listen/lib/listen/adapter/bsd.rb +0 -104
- data/vendor/deps/listen/lib/listen/adapter/config.rb +0 -31
- data/vendor/deps/listen/lib/listen/adapter/darwin.rb +0 -77
- data/vendor/deps/listen/lib/listen/adapter/linux.rb +0 -108
- data/vendor/deps/listen/lib/listen/adapter/polling.rb +0 -40
- data/vendor/deps/listen/lib/listen/adapter/windows.rb +0 -96
- data/vendor/deps/listen/lib/listen/adapter.rb +0 -43
- data/vendor/deps/listen/lib/listen/backend.rb +0 -40
- data/vendor/deps/listen/lib/listen/change.rb +0 -69
- data/vendor/deps/listen/lib/listen/cli.rb +0 -65
- data/vendor/deps/listen/lib/listen/directory.rb +0 -93
- data/vendor/deps/listen/lib/listen/error.rb +0 -11
- data/vendor/deps/listen/lib/listen/event/config.rb +0 -39
- data/vendor/deps/listen/lib/listen/event/loop.rb +0 -92
- data/vendor/deps/listen/lib/listen/event/processor.rb +0 -128
- data/vendor/deps/listen/lib/listen/event/queue.rb +0 -52
- data/vendor/deps/listen/lib/listen/file.rb +0 -95
- data/vendor/deps/listen/lib/listen/fsm.rb +0 -131
- data/vendor/deps/listen/lib/listen/listener/config.rb +0 -41
- data/vendor/deps/listen/lib/listen/listener.rb +0 -136
- data/vendor/deps/listen/lib/listen/logger.rb +0 -65
- data/vendor/deps/listen/lib/listen/monotonic_time.rb +0 -27
- data/vendor/deps/listen/lib/listen/options.rb +0 -24
- data/vendor/deps/listen/lib/listen/queue_optimizer.rb +0 -129
- data/vendor/deps/listen/lib/listen/record/entry.rb +0 -66
- data/vendor/deps/listen/lib/listen/record/symlink_detector.rb +0 -47
- data/vendor/deps/listen/lib/listen/record.rb +0 -122
- data/vendor/deps/listen/lib/listen/silencer/controller.rb +0 -50
- data/vendor/deps/listen/lib/listen/silencer.rb +0 -106
- data/vendor/deps/listen/lib/listen/thread.rb +0 -54
- data/vendor/deps/listen/lib/listen/version.rb +0 -5
- data/vendor/deps/listen/lib/listen.rb +0 -47
- data/vendor/deps/listen/listen.gemspec +0 -40
- data/vendor/deps/listen/spec/acceptance/listen_spec.rb +0 -320
- data/vendor/deps/listen/spec/lib/listen/adapter/base_spec.rb +0 -101
- data/vendor/deps/listen/spec/lib/listen/adapter/bsd_spec.rb +0 -13
- data/vendor/deps/listen/spec/lib/listen/adapter/config_spec.rb +0 -122
- data/vendor/deps/listen/spec/lib/listen/adapter/darwin_spec.rb +0 -82
- data/vendor/deps/listen/spec/lib/listen/adapter/linux_spec.rb +0 -199
- data/vendor/deps/listen/spec/lib/listen/adapter/polling_spec.rb +0 -83
- data/vendor/deps/listen/spec/lib/listen/adapter/windows_spec.rb +0 -13
- data/vendor/deps/listen/spec/lib/listen/adapter_spec.rb +0 -69
- data/vendor/deps/listen/spec/lib/listen/backend_spec.rb +0 -82
- data/vendor/deps/listen/spec/lib/listen/change_spec.rb +0 -102
- data/vendor/deps/listen/spec/lib/listen/cli_spec.rb +0 -116
- data/vendor/deps/listen/spec/lib/listen/directory_spec.rb +0 -284
- data/vendor/deps/listen/spec/lib/listen/event/config_spec.rb +0 -33
- data/vendor/deps/listen/spec/lib/listen/event/loop_spec.rb +0 -118
- data/vendor/deps/listen/spec/lib/listen/event/processor_spec.rb +0 -250
- data/vendor/deps/listen/spec/lib/listen/event/queue_spec.rb +0 -118
- data/vendor/deps/listen/spec/lib/listen/file_spec.rb +0 -254
- data/vendor/deps/listen/spec/lib/listen/fsm_spec.rb +0 -147
- data/vendor/deps/listen/spec/lib/listen/listener/config_spec.rb +0 -29
- data/vendor/deps/listen/spec/lib/listen/listener_spec.rb +0 -321
- data/vendor/deps/listen/spec/lib/listen/logger_spec.rb +0 -212
- data/vendor/deps/listen/spec/lib/listen/monotonic_time_spec.rb +0 -58
- data/vendor/deps/listen/spec/lib/listen/queue_optimizer_spec.rb +0 -111
- data/vendor/deps/listen/spec/lib/listen/record_spec.rb +0 -424
- data/vendor/deps/listen/spec/lib/listen/silencer/controller_spec.rb +0 -97
- data/vendor/deps/listen/spec/lib/listen/silencer_spec.rb +0 -109
- data/vendor/deps/listen/spec/lib/listen/thread_spec.rb +0 -133
- data/vendor/deps/listen/spec/lib/listen_spec.rb +0 -25
- data/vendor/deps/listen/spec/spec_helper.rb +0 -49
- data/vendor/deps/listen/spec/support/acceptance_helper.rb +0 -260
- data/vendor/deps/listen/spec/support/fixtures_helper.rb +0 -32
- data/vendor/deps/listen/spec/support/platform_helper.rb +0 -17
- data/vendor/deps/observer/.github/dependabot.yml +0 -6
- data/vendor/deps/observer/.github/workflows/test.yml +0 -33
- data/vendor/deps/observer/.gitignore +0 -8
- data/vendor/deps/observer/BSDL +0 -22
- data/vendor/deps/observer/COPYING +0 -56
- data/vendor/deps/observer/Gemfile +0 -9
- data/vendor/deps/observer/README.md +0 -139
- data/vendor/deps/observer/Rakefile +0 -10
- data/vendor/deps/observer/bin/console +0 -14
- data/vendor/deps/observer/bin/setup +0 -8
- data/vendor/deps/observer/lib/observer.rb +0 -229
- data/vendor/deps/observer/observer.gemspec +0 -32
- data/vendor/deps/observer/test/test_observer.rb +0 -66
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'listen/event/queue'
|
|
4
|
-
|
|
5
|
-
# TODO: not part of listener really
|
|
6
|
-
RSpec.describe Listen::Event::Queue do
|
|
7
|
-
let(:queue) { instance_double(Thread::Queue, 'my queue') }
|
|
8
|
-
|
|
9
|
-
let(:config) { instance_double(Listen::Event::Queue::Config) }
|
|
10
|
-
|
|
11
|
-
let(:relative) { false }
|
|
12
|
-
|
|
13
|
-
subject { described_class.new(config) }
|
|
14
|
-
|
|
15
|
-
before do
|
|
16
|
-
allow(config).to receive(:relative?).and_return(relative)
|
|
17
|
-
allow(Thread::Queue).to receive(:new).and_return(queue)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe '#empty?' do
|
|
21
|
-
before do
|
|
22
|
-
allow(queue).to receive(:empty?).and_return(empty)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context 'when empty' do
|
|
26
|
-
let(:empty) { true }
|
|
27
|
-
it { is_expected.to be_empty }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context 'when not empty' do
|
|
31
|
-
let(:empty) { false }
|
|
32
|
-
let(:watched_dir) { fake_path('watched_dir') }
|
|
33
|
-
before do
|
|
34
|
-
allow(queue).to receive(:empty?).and_return(false)
|
|
35
|
-
end
|
|
36
|
-
it { is_expected.to_not be_empty }
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe '#pop' do
|
|
41
|
-
before do
|
|
42
|
-
allow(queue).to receive(:pop).and_return('foo')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'when empty' do
|
|
46
|
-
let(:value) { 'foo' }
|
|
47
|
-
it 'forward the call to the queue' do
|
|
48
|
-
expect(subject.pop).to eq('foo')
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe '#<<' do
|
|
54
|
-
let(:watched_dir) { fake_path('watched_dir') }
|
|
55
|
-
before do
|
|
56
|
-
allow(queue).to receive(:<<)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context 'when relative option is true' do
|
|
60
|
-
let(:relative) { true }
|
|
61
|
-
|
|
62
|
-
context 'when watched dir is the current dir' do
|
|
63
|
-
let(:options) { { relative: true, directories: Pathname.pwd } }
|
|
64
|
-
|
|
65
|
-
let(:dir_rel_path) { fake_path('.') }
|
|
66
|
-
let(:foo_rel_path) { fake_path('foo', exist?: true) }
|
|
67
|
-
|
|
68
|
-
it 'registers relative paths' do
|
|
69
|
-
allow(dir_rel_path).to receive(:+).with('foo') { foo_rel_path }
|
|
70
|
-
|
|
71
|
-
allow(watched_dir).to receive(:relative_path_from).
|
|
72
|
-
with(Pathname.pwd).
|
|
73
|
-
and_return(dir_rel_path)
|
|
74
|
-
|
|
75
|
-
expect(queue).to receive(:<<).
|
|
76
|
-
with([:file, :modified, dir_rel_path, 'foo', {}])
|
|
77
|
-
|
|
78
|
-
subject.<<([:file, :modified, watched_dir, 'foo', {}])
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context 'when watched dir is not the current dir' do
|
|
83
|
-
let(:options) { { relative: true } }
|
|
84
|
-
let(:dir_rel_path) { fake_path('..') }
|
|
85
|
-
let(:foo_rel_path) { fake_path('../foo', exist?: true) }
|
|
86
|
-
|
|
87
|
-
it 'registers relative path' do
|
|
88
|
-
allow(watched_dir).to receive(:relative_path_from).
|
|
89
|
-
with(Pathname.pwd).
|
|
90
|
-
and_return(dir_rel_path)
|
|
91
|
-
|
|
92
|
-
expect(queue).to receive(:<<).
|
|
93
|
-
with([:file, :modified, dir_rel_path, 'foo', {}])
|
|
94
|
-
|
|
95
|
-
subject.<<([:file, :modified, watched_dir, 'foo', {}])
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
context 'when watched dir is on another drive' do
|
|
100
|
-
let(:watched_dir) { fake_path('watched_dir', realpath: 'd:/foo') }
|
|
101
|
-
let(:foo_rel_path) { fake_path('d:/foo', exist?: true) }
|
|
102
|
-
|
|
103
|
-
it 'registers full path' do
|
|
104
|
-
allow(watched_dir).to receive(:relative_path_from).
|
|
105
|
-
with(Pathname.pwd).
|
|
106
|
-
and_raise(ArgumentError)
|
|
107
|
-
|
|
108
|
-
allow(watched_dir).to receive(:+).with('foo') { foo_rel_path }
|
|
109
|
-
|
|
110
|
-
expect(queue).to receive(:<<).
|
|
111
|
-
with([:file, :modified, watched_dir, 'foo', {}])
|
|
112
|
-
|
|
113
|
-
subject.<<([:file, :modified, watched_dir, 'foo', {}])
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Listen::File do
|
|
4
|
-
let(:record) do
|
|
5
|
-
instance_double(
|
|
6
|
-
Listen::Record,
|
|
7
|
-
root: '/foo/bar',
|
|
8
|
-
file_data: record_data,
|
|
9
|
-
add_dir: true,
|
|
10
|
-
update_file: true,
|
|
11
|
-
unset_path: true
|
|
12
|
-
)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
let(:path) { Pathname.pwd }
|
|
16
|
-
let(:subject) { described_class.change(record, 'file.rb') }
|
|
17
|
-
|
|
18
|
-
around { |example| fixtures { example.run } }
|
|
19
|
-
|
|
20
|
-
before { allow(::File).to receive(:lstat) { fail 'Not stubbed!' } }
|
|
21
|
-
|
|
22
|
-
describe '#change' do
|
|
23
|
-
let(:expected_data) do
|
|
24
|
-
{ mtime: kind_of(Float), mode: kind_of(Integer), size: kind_of(Integer) }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'with file record' do
|
|
28
|
-
let(:record_mtime) { nil }
|
|
29
|
-
let(:record_sha) { nil }
|
|
30
|
-
let(:record_mode) { nil }
|
|
31
|
-
let(:record_size) { nil }
|
|
32
|
-
|
|
33
|
-
let(:record_data) do
|
|
34
|
-
{ mtime: record_mtime, sha: record_sha, mode: record_mode, size: record_size }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'with non-existing file' do
|
|
38
|
-
before { allow(::File).to receive(:lstat) { fail Errno::ENOENT } }
|
|
39
|
-
|
|
40
|
-
it { is_expected.to eq(:removed) }
|
|
41
|
-
|
|
42
|
-
it 'sets path in record' do
|
|
43
|
-
expect(record).to receive(:unset_path).with('file.rb')
|
|
44
|
-
subject
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'with existing file' do
|
|
49
|
-
let(:stat_mtime) { Time.now.to_f - 1234.567 }
|
|
50
|
-
let(:stat_ctime) { Time.now.to_f - 1234.567 }
|
|
51
|
-
let(:stat_atime) { Time.now.to_f - 1234.567 }
|
|
52
|
-
let(:stat_mode) { 0640 }
|
|
53
|
-
|
|
54
|
-
let(:record_size) { 42 }
|
|
55
|
-
let(:stat_size) { record_size }
|
|
56
|
-
|
|
57
|
-
let(:sha) { fail 'stub me (sha)' }
|
|
58
|
-
|
|
59
|
-
let(:stat) do
|
|
60
|
-
instance_double(
|
|
61
|
-
File::Stat,
|
|
62
|
-
mtime: stat_mtime,
|
|
63
|
-
atime: stat_atime,
|
|
64
|
-
ctime: stat_ctime,
|
|
65
|
-
mode: stat_mode,
|
|
66
|
-
size: stat_size
|
|
67
|
-
)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
before do
|
|
71
|
-
allow(::File).to receive(:lstat) { stat }
|
|
72
|
-
allow(Digest::SHA256).to receive(:file) { double(:sha, digest: sha) }
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context 'with different mode in record' do
|
|
76
|
-
let(:record_mode) { 0722 }
|
|
77
|
-
|
|
78
|
-
it { should be :modified }
|
|
79
|
-
|
|
80
|
-
it 'sets path in record with expected data' do
|
|
81
|
-
expect(record).to receive(:update_file).
|
|
82
|
-
with('file.rb', expected_data)
|
|
83
|
-
subject
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context 'with same mode in record' do
|
|
88
|
-
let(:record_mode) { stat_mode }
|
|
89
|
-
|
|
90
|
-
# e.g. file was overwritten by earlier copy
|
|
91
|
-
context 'with earlier mtime than in record' do
|
|
92
|
-
let(:record_mtime) { stat_mtime.to_f - 123.45 }
|
|
93
|
-
|
|
94
|
-
it { should be :modified }
|
|
95
|
-
|
|
96
|
-
it 'sets path in record with expected data' do
|
|
97
|
-
expect(record).to receive(:update_file).
|
|
98
|
-
with('file.rb', expected_data)
|
|
99
|
-
subject
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context 'with later mtime than in record' do
|
|
104
|
-
let(:record_mtime) { stat_mtime.to_f + 123.45 }
|
|
105
|
-
|
|
106
|
-
it { should be :modified }
|
|
107
|
-
|
|
108
|
-
it 'sets path in record with expected data' do
|
|
109
|
-
expect(record).to receive(:update_file).
|
|
110
|
-
with('file.rb', expected_data)
|
|
111
|
-
subject
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
context 'with identical mtime in record' do
|
|
116
|
-
let(:record_mtime) { stat_mtime.to_f }
|
|
117
|
-
|
|
118
|
-
context 'with accurate stat times' do
|
|
119
|
-
let(:stat_mtime) { Time.at(1_401_235_714.123).utc }
|
|
120
|
-
let(:stat_atime) { Time.at(1_401_235_714.123).utc }
|
|
121
|
-
let(:stat_ctime) { Time.at(1_401_235_714.123).utc }
|
|
122
|
-
let(:record_mtime) { stat_mtime.to_f }
|
|
123
|
-
it { should be_nil }
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context 'with inaccurate stat times' do
|
|
127
|
-
let(:stat_mtime) { Time.at(1_401_235_714.0).utc }
|
|
128
|
-
let(:stat_atime) { Time.at(1_401_235_714.0).utc }
|
|
129
|
-
let(:stat_ctime) { Time.at(1_401_235_714.0).utc }
|
|
130
|
-
|
|
131
|
-
let(:record_mtime) { stat_mtime.to_f }
|
|
132
|
-
|
|
133
|
-
context 'with real mtime barely not within last second' do
|
|
134
|
-
before { allow(Time).to receive(:now) { now } }
|
|
135
|
-
|
|
136
|
-
# NOTE: if real mtime is ???14.99, the
|
|
137
|
-
# saved mtime is ???14.0
|
|
138
|
-
let(:now) { Time.at(1_401_235_716.00).utc }
|
|
139
|
-
it { should be_nil }
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
context 'with real mtime barely within last second' do
|
|
143
|
-
# NOTE: real mtime is in range (???14.0 .. ???14.999),
|
|
144
|
-
# so saved mtime at ???14.0 means it could be
|
|
145
|
-
# ???14.999, so ???15.999 could still be within 1 second
|
|
146
|
-
# range
|
|
147
|
-
let(:now) { Time.at(1_401_235_715.999999).utc }
|
|
148
|
-
|
|
149
|
-
before { allow(Time).to receive(:now) { now } }
|
|
150
|
-
|
|
151
|
-
context 'without available sha' do
|
|
152
|
-
let(:sha) { fail Errno::ENOENT }
|
|
153
|
-
|
|
154
|
-
# Treat it as a removed file, because chances are ...
|
|
155
|
-
# whatever is listening for changes won't be able to deal
|
|
156
|
-
# with the file either (e.g. because of permissions)
|
|
157
|
-
it { should be :removed }
|
|
158
|
-
|
|
159
|
-
it 'should not unset record' do
|
|
160
|
-
expect(record).to_not receive(:unset_path)
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
context 'with available sha' do
|
|
165
|
-
let(:sha) { 'd41d8cd98f00b204e9800998ecf8427e' }
|
|
166
|
-
|
|
167
|
-
context 'with same sha in record' do
|
|
168
|
-
let(:record_sha) { sha }
|
|
169
|
-
it { should be_nil }
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
context 'with no sha in record' do
|
|
173
|
-
let(:record_sha) { nil }
|
|
174
|
-
it { should be_nil }
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
context 'with different sha in record' do
|
|
178
|
-
let(:record_sha) { 'foo' }
|
|
179
|
-
it { should be :modified }
|
|
180
|
-
|
|
181
|
-
it 'sets path in record with expected data' do
|
|
182
|
-
expected = expected_data.merge(sha: sha)
|
|
183
|
-
expect(record).to receive(:update_file).
|
|
184
|
-
with('file.rb', expected)
|
|
185
|
-
subject
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
context 'with empty record' do
|
|
197
|
-
let(:record_data) { {} }
|
|
198
|
-
|
|
199
|
-
context 'with existing path' do
|
|
200
|
-
let(:stat) do
|
|
201
|
-
instance_double(
|
|
202
|
-
File::Stat,
|
|
203
|
-
mtime: 1234,
|
|
204
|
-
mode: 0645,
|
|
205
|
-
size: 0
|
|
206
|
-
)
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
before do
|
|
210
|
-
allow(::File).to receive(:lstat) { stat }
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
it 'returns added' do
|
|
214
|
-
expect(subject).to eq :added
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
it 'sets path in record with expected data' do
|
|
218
|
-
expect(record).to receive(:update_file).
|
|
219
|
-
with('file.rb', expected_data)
|
|
220
|
-
subject
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
describe '#inaccurate_mac_time?' do
|
|
227
|
-
let(:stat) do
|
|
228
|
-
instance_double(File::Stat, mtime: mtime, atime: atime, ctime: ctime, size: 0)
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
subject { Listen::File.inaccurate_mac_time?(stat) }
|
|
232
|
-
|
|
233
|
-
context 'with no accurate times' do
|
|
234
|
-
let(:mtime) { Time.at(1_234_567.0).utc }
|
|
235
|
-
let(:atime) { Time.at(1_234_567.0).utc }
|
|
236
|
-
let(:ctime) { Time.at(1_234_567.0).utc }
|
|
237
|
-
it { should be_truthy }
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
context 'with all accurate times' do
|
|
241
|
-
let(:mtime) { Time.at(1_234_567.89).utc }
|
|
242
|
-
let(:atime) { Time.at(1_234_567.89).utc }
|
|
243
|
-
let(:ctime) { Time.at(1_234_567.89).utc }
|
|
244
|
-
it { should be_falsey }
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
context 'with one accurate time' do
|
|
248
|
-
let(:mtime) { Time.at(1_234_567.0).utc }
|
|
249
|
-
let(:atime) { Time.at(1_234_567.89).utc }
|
|
250
|
-
let(:ctime) { Time.at(1_234_567.0).utc }
|
|
251
|
-
it { should be_falsey }
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
end
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Listen::FSM do
|
|
4
|
-
context 'simple FSM' do
|
|
5
|
-
class SpecSimpleFsm
|
|
6
|
-
include Listen::FSM
|
|
7
|
-
|
|
8
|
-
attr_reader :entered_started
|
|
9
|
-
|
|
10
|
-
start_state :initial
|
|
11
|
-
|
|
12
|
-
state :started, to: :stopped do
|
|
13
|
-
@entered_started = true
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
state :failed, to: :stopped
|
|
17
|
-
|
|
18
|
-
state :stopped
|
|
19
|
-
|
|
20
|
-
def start
|
|
21
|
-
transition(:started)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def stop
|
|
25
|
-
transition(:stopped)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def fail
|
|
29
|
-
transition(:failed)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def initialize
|
|
33
|
-
initialize_fsm
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
subject(:fsm) { SpecSimpleFsm.new }
|
|
38
|
-
|
|
39
|
-
it 'starts in start_state' do
|
|
40
|
-
expect(subject.state).to eq(:initial)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'allows transitions' do
|
|
44
|
-
subject.start
|
|
45
|
-
expect(subject.state).to eq(:started)
|
|
46
|
-
expect(subject.entered_started).to eq(true)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'raises on disallowed transitions' do
|
|
50
|
-
subject.fail
|
|
51
|
-
expect do
|
|
52
|
-
subject.start
|
|
53
|
-
end.to raise_exception(ArgumentError,
|
|
54
|
-
"SpecSimpleFsm can't change state from 'failed' to 'started', only to: stopped")
|
|
55
|
-
expect(subject.state).to eq(:failed)
|
|
56
|
-
expect(subject.entered_started).to eq(nil)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'declares transition and transition! private' do
|
|
60
|
-
expect { subject.transition(:started) }.to raise_exception(NoMethodError, /private.*transition/)
|
|
61
|
-
expect { subject.transition!(:started) }.to raise_exception(NoMethodError, /private.*transition!/)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe '#wait_for_state' do
|
|
65
|
-
it 'returns truthy immediately if already in the desired state' do
|
|
66
|
-
expect(subject.instance_variable_get(:@state_changed)).to_not receive(:wait)
|
|
67
|
-
result = subject.wait_for_state(:initial)
|
|
68
|
-
expect(result).to be_truthy
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'waits for the next state change and returns truthy if then in the desired state' do
|
|
72
|
-
expect(subject.instance_variable_get(:@state_changed)).to receive(:wait).with(anything, anything) do
|
|
73
|
-
subject.instance_variable_set(:@state, :started)
|
|
74
|
-
end
|
|
75
|
-
result = subject.wait_for_state(:started)
|
|
76
|
-
expect(result).to be_truthy
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it 'waits for the next state change and returns falsey if then not the desired state' do
|
|
80
|
-
expect(subject.instance_variable_get(:@state_changed)).to receive(:wait).with(anything, anything)
|
|
81
|
-
result = subject.wait_for_state(:started)
|
|
82
|
-
expect(result).to be_falsey
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'passes the timeout: down to wait, if given' do
|
|
86
|
-
expect(subject.instance_variable_get(:@state_changed)).to receive(:wait).with(anything, 5.0)
|
|
87
|
-
subject.wait_for_state(:started, timeout: 5.0)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'passes nil (infinite) timeout: down to wait, if none given' do
|
|
91
|
-
expect(subject.instance_variable_get(:@state_changed)).to receive(:wait).with(anything, nil)
|
|
92
|
-
subject.wait_for_state(:started)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it 'enforces precondition that states must be symbols' do
|
|
96
|
-
expect do
|
|
97
|
-
subject.wait_for_state(:started, 'stopped')
|
|
98
|
-
end.to raise_exception(ArgumentError, /states must be symbols .*got "stopped"/)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context 'FSM with no start state' do
|
|
104
|
-
class SpecFsmWithNoStartState
|
|
105
|
-
include Listen::FSM
|
|
106
|
-
|
|
107
|
-
state :started, to: :stopped
|
|
108
|
-
|
|
109
|
-
state :failed, to: :stopped
|
|
110
|
-
|
|
111
|
-
state :stopped
|
|
112
|
-
|
|
113
|
-
def initialize
|
|
114
|
-
initialize_fsm
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
subject(:fsm) { SpecFsmWithNoStartState.new }
|
|
119
|
-
|
|
120
|
-
it 'raises ArgumentError on new' do
|
|
121
|
-
expect { subject }.to raise_exception(ArgumentError,
|
|
122
|
-
/`start_state :<state>` must be declared before `new`/)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context 'FSM with string state name' do
|
|
127
|
-
subject(:fsm) do
|
|
128
|
-
instance_exec do
|
|
129
|
-
class SpecFsmWithStringState
|
|
130
|
-
include Listen::FSM
|
|
131
|
-
|
|
132
|
-
state 'started', to: 'stopped'
|
|
133
|
-
|
|
134
|
-
state 'stopped'
|
|
135
|
-
|
|
136
|
-
def initialize
|
|
137
|
-
initialize_fsm
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it 'raises ArgumentError on new' do
|
|
144
|
-
expect { subject }.to raise_exception(ArgumentError, /state name must be a Symbol/)
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'listen/listener/config'
|
|
4
|
-
RSpec.describe Listen::Listener::Config do
|
|
5
|
-
describe 'options' do
|
|
6
|
-
context 'custom options' do
|
|
7
|
-
subject do
|
|
8
|
-
described_class.new(
|
|
9
|
-
latency: 1.234,
|
|
10
|
-
wait_for_delay: 0.85,
|
|
11
|
-
force_polling: true,
|
|
12
|
-
relative: true)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'extracts adapter options' do
|
|
16
|
-
klass = Class.new do
|
|
17
|
-
DEFAULTS = { latency: 5.4321 }.freeze
|
|
18
|
-
end
|
|
19
|
-
expected = { latency: 1.234 }
|
|
20
|
-
expect(subject.adapter_instance_options(klass)).to eq(expected)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'extract adapter selecting options' do
|
|
24
|
-
expected = { force_polling: true, polling_fallback_message: nil }
|
|
25
|
-
expect(subject.adapter_select_options).to eq(expected)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|