Skip to content

Commit

Permalink
run polling acceptance tests separately
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed May 30, 2015
1 parent 174cbdb commit a35c2b2
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 172 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ env:
- LISTEN_GEM_FSEVENT_NO_RECURSION=0 LISTEN_GEM_SIMULATE_FSEVENT=0
# try without recursion on both OSX and Linux (simulated OSX)
- LISTEN_GEM_FSEVENT_NO_RECURSION=1 LISTEN_GEM_SIMULATE_FSEVENT=1
- LISTEN_GEM_FSEVENT_NO_RECURSION=1 LISTEN_GEM_SIMULATE_FSEVENT=1 LISTEN_TESTS_POLLING=1
sudo: false
340 changes: 169 additions & 171 deletions spec/acceptance/listen_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# encoding: UTF-8

RSpec.describe 'Listen' do
def polling_tests?
/1|true/i =~ ENV['LISTEN_TESTS_POLLING']
end

let(:base_options) { { wait_for_delay: 0.1, latency: 0.1 } }
let(:polling_options) { {} }
let(:options) { {} }
let(:polling_options) { { force_polling: polling_tests? } }

let(:all_options) { base_options.merge(polling_options).merge(options) }

let(:wrapper) { setup_listener(all_options, :track_changes) }
Expand All @@ -27,201 +32,194 @@
end
end

[false, true].each do |polling|
context "force_polling option to #{polling}" do
let(:polling_options) { { force_polling: polling } }

context 'with default ignore options' do
context 'with nothing in listen dir' do

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.to process_addition_of('.hidden') }

it 'listens to multiple files addition' do
result = wrapper.listen do
change_fs(:added, 'file1.rb')
change_fs(:added, 'file2.rb')
end

expect(result).to eq(modified: [],
added: %w(file1.rb file2.rb),
removed: [])
end

it 'listens to file moved inside' do
touch '../file.rb'
expect(wrapper.listen do
mv '../file.rb', 'file.rb'
end).to eq(modified: [], added: ['file.rb'], removed: [])
end
end
context 'with default ignore options' do
context 'with nothing in listen dir' do
it { is_expected.to process_addition_of('file.rb') }
it { is_expected.to process_addition_of('.hidden') }

context 'existing file.rb in listen dir' do
around do |example|
change_fs(:added, 'file.rb')
example.run
end

it { is_expected.to process_modification_of('file.rb') }
it { is_expected.to process_removal_of('file.rb') }

it 'listens to file.rb moved out' do
expect(wrapper.listen do
mv 'file.rb', '../file.rb'
end).to eq(modified: [], added: [], removed: ['file.rb'])
end

it 'listens to file mode change' do
prev_mode = File.stat('file.rb').mode

result = wrapper.listen do
windows? ? `attrib +r file.rb` : chmod(0444, 'file.rb')
end

new_mode = File.stat('file.rb').mode
no_event = result[:modified].empty? && prev_mode == new_mode

# Check if chmod actually works or an attrib event happens,
# or expect nothing otherwise
#
# (e.g. fails for polling+vfat on Linux, but works with
# INotify+vfat because you get an event regardless if mode
# actually changes)
#
files = no_event ? [] : ['file.rb']

expect(result).to eq(modified: files, added: [], removed: [])
end
it 'listens to multiple files addition' do
result = wrapper.listen do
change_fs(:added, 'file1.rb')
change_fs(:added, 'file2.rb')
end

context 'hidden file in listen dir' do
around do |example|
change_fs(:added, '.hidden')
example.run
end
expect(result).to eq(modified: [],
added: %w(file1.rb file2.rb),
removed: [])
end

it { is_expected.to process_modification_of('.hidden') }
end
it 'listens to file moved inside' do
touch '../file.rb'
expect(wrapper.listen do
mv '../file.rb', 'file.rb'
end).to eq(modified: [], added: ['file.rb'], removed: [])
end
end

context 'dir in listen dir' do
around do |example|
mkdir_p 'dir'
example.run
end
context 'existing file.rb in listen dir' do
around do |example|
change_fs(:added, 'file.rb')
example.run
end

it { is_expected.to process_addition_of('dir/file.rb') }
end
it { is_expected.to process_modification_of('file.rb') }
it { is_expected.to process_removal_of('file.rb') }

context 'dir with file in listen dir' do
around do |example|
mkdir_p 'dir'
touch 'dir/file.rb'
example.run
end

it 'listens to file move' do
expected = { modified: [],
added: %w(file.rb),
removed: %w(dir/file.rb)
}

expect(wrapper.listen do
mv 'dir/file.rb', 'file.rb'
end).to eq expected
end
end
it 'listens to file.rb moved out' do
expect(wrapper.listen do
mv 'file.rb', '../file.rb'
end).to eq(modified: [], added: [], removed: ['file.rb'])
end

it 'listens to file mode change' do
prev_mode = File.stat('file.rb').mode

context 'two dirs with files in listen dir' do
around do |example|
mkdir_p 'dir1'
touch 'dir1/file1.rb'
mkdir_p 'dir2'
touch 'dir2/file2.rb'
example.run
end

it 'listens to multiple file moves' do
expected = {
modified: [],
added: ['dir1/file2.rb', 'dir2/file1.rb'],
removed: ['dir1/file1.rb', 'dir2/file2.rb']
}

expect(wrapper.listen do
mv 'dir1/file1.rb', 'dir2/file1.rb'
mv 'dir2/file2.rb', 'dir1/file2.rb'
end).to eq expected
end

it 'listens to dir move' do
expected = { modified: [],
added: ['dir2/dir1/file1.rb'],
removed: ['dir1/file1.rb'] }

expect(wrapper.listen do
mv 'dir1', 'dir2/'
end).to eq expected
end
result = wrapper.listen do
windows? ? `attrib +r file.rb` : chmod(0444, 'file.rb')
end

context 'with .bundle dir ignored by default' do
around do |example|
mkdir_p '.bundle'
example.run
end
new_mode = File.stat('file.rb').mode
no_event = result[:modified].empty? && prev_mode == new_mode

it { is_expected.not_to process_addition_of('.bundle/file.rb') }
end
# Check if chmod actually works or an attrib event happens,
# or expect nothing otherwise
#
# (e.g. fails for polling+vfat on Linux, but works with
# INotify+vfat because you get an event regardless if mode
# actually changes)
#
files = no_event ? [] : ['file.rb']

expect(result).to eq(modified: files, added: [], removed: [])
end
end

context 'when :ignore is *ignored_dir*' do
context 'ignored dir with file in listen dir' do
let(:options) { { ignore: /ignored_dir/ } }
context 'hidden file in listen dir' do
around do |example|
change_fs(:added, '.hidden')
example.run
end

around do |example|
mkdir_p 'ignored_dir'
example.run
end
it { is_expected.to process_modification_of('.hidden') }
end

it { is_expected.not_to process_addition_of('ignored_dir/file.rb') }
end
context 'dir in listen dir' do
around do |example|
mkdir_p 'dir'
example.run
end

context 'when :only is *.rb' do
let(:options) { { only: /\.rb$/ } }
it { is_expected.to process_addition_of('dir/file.rb') }
end

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
end
context 'dir with file in listen dir' do
around do |example|
mkdir_p 'dir'
touch 'dir/file.rb'
example.run
end

context 'when :ignore is bar.rb' do
context 'when :only is *.rb' do
let(:options) { { ignore: /bar\.rb$/, only: /\.rb$/ } }
it 'listens to file move' do
expected = { modified: [],
added: %w(file.rb),
removed: %w(dir/file.rb)
}

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
it { is_expected.not_to process_addition_of('bar.rb') }
end
end
expect(wrapper.listen do
mv 'dir/file.rb', 'file.rb'
end).to eq expected
end
end

context 'when default ignore is *.rb' do
let(:options) { { ignore: /\.rb$/ } }
context 'two dirs with files in listen dir' do
around do |example|
mkdir_p 'dir1'
touch 'dir1/file1.rb'
mkdir_p 'dir2'
touch 'dir2/file2.rb'
example.run
end

it { is_expected.not_to process_addition_of('file.rb') }
it 'listens to multiple file moves' do
expected = {
modified: [],
added: ['dir1/file2.rb', 'dir2/file1.rb'],
removed: ['dir1/file1.rb', 'dir2/file2.rb']
}

expect(wrapper.listen do
mv 'dir1/file1.rb', 'dir2/file1.rb'
mv 'dir2/file2.rb', 'dir1/file2.rb'
end).to eq expected
end

context 'with #ignore on *.txt mask' do
before { wrapper.listener.ignore(/\.txt/) }
it 'listens to dir move' do
expected = { modified: [],
added: ['dir2/dir1/file1.rb'],
removed: ['dir1/file1.rb'] }

it { is_expected.not_to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
end
expect(wrapper.listen do
mv 'dir1', 'dir2/'
end).to eq expected
end
end

context 'with #ignore! on *.txt mask' do
before { wrapper.listener.ignore!(/\.txt/) }
context 'with .bundle dir ignored by default' do
around do |example|
mkdir_p '.bundle'
example.run
end

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
end
end
it { is_expected.not_to process_addition_of('.bundle/file.rb') }
end
end

context 'when :ignore is *ignored_dir*' do
context 'ignored dir with file in listen dir' do
let(:options) { { ignore: /ignored_dir/ } }

around do |example|
mkdir_p 'ignored_dir'
example.run
end

it { is_expected.not_to process_addition_of('ignored_dir/file.rb') }
end

context 'when :only is *.rb' do
let(:options) { { only: /\.rb$/ } }

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
end

context 'when :ignore is bar.rb' do
context 'when :only is *.rb' do
let(:options) { { ignore: /bar\.rb$/, only: /\.rb$/ } }

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
it { is_expected.not_to process_addition_of('bar.rb') }
end
end

context 'when default ignore is *.rb' do
let(:options) { { ignore: /\.rb$/ } }

it { is_expected.not_to process_addition_of('file.rb') }

context 'with #ignore on *.txt mask' do
before { wrapper.listener.ignore(/\.txt/) }

it { is_expected.not_to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
end

context 'with #ignore! on *.txt mask' do
before { wrapper.listener.ignore!(/\.txt/) }

it { is_expected.to process_addition_of('file.rb') }
it { is_expected.not_to process_addition_of('file.txt') }
end
end
end
Expand Down