colorls/spec/flags_spec.rb

92 lines
2.6 KiB
Ruby
Raw Normal View History

2017-10-22 15:41:00 +02:00
require 'spec_helper'
RSpec.describe ColorLS::Flags do
FIXTURES = 'spec/fixtures'.freeze
2017-10-22 17:05:28 +02:00
subject { capture_stdout { ColorLS::Flags.new(*args).process } }
def capture_stdout
old = $stdout
$stdout = fake = StringIO.new
yield
fake.string
ensure
$stdout = old
end
2017-10-22 15:41:00 +02:00
context 'with no flags' do
let(:args) { [FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to_not match(/((r|-).*(w|-).*(x|-).*){3}/) } # does not list file info
2017-10-22 20:48:17 +02:00
it { is_expected.to_not match(/\.hidden-file/) } # does not display hidden files
2017-10-22 17:05:28 +02:00
it { is_expected.to_not match(/Found \d+ contents/) } # does not show a report
it { is_expected.to_not match(/(.*\n){3}/) } # displays multiple files per line
it { is_expected.to_not match(%r(\.{1,2}/)) } # does not display ./ or ../
it { is_expected.to_not match(/├──/) } # does not display file hierarchy
2017-10-22 15:41:00 +02:00
end
2017-10-23 15:25:27 +02:00
xcontext 'with no flags' do
it { is_expected.to match(/a-file.+symlinks.+z-file/) } # displays dirs & files alphabetically
end
2017-10-22 15:41:00 +02:00
context 'with --long flag & file path' do
let(:args) { ['--long', "#{FIXTURES}/.hidden-file"] }
2017-10-22 17:05:28 +02:00
it { is_expected.to_not match(/No Info/) } # lists info of a hidden file
2017-10-22 15:41:00 +02:00
end
context 'with --long flag' do
let(:args) { ['--long', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/((r|-).*(w|-).*(x|-).*){3}/) } # lists file info
2017-10-22 15:41:00 +02:00
end
context 'with --all flag' do
let(:args) { ['--all', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/\.hidden-file/) } # lists hidden files
2017-10-22 15:41:00 +02:00
end
context 'with --sort-dirs flag' do
let(:args) { ['--sort-dirs', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/symlinks.+a-file.+z-file/) } # sorts results alphabetically, directories first
2017-10-22 15:41:00 +02:00
end
context 'with --sort-files flag' do
let(:args) { ['--sort-files', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/a-file.+z-file.+symlinks/) } # sorts results alphabetically, files first
2017-10-22 15:41:00 +02:00
end
context 'with --dirs flag' do
let(:args) { ['--dirs', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to_not match(/a-file/) } # displays dirs only
2017-10-22 15:41:00 +02:00
end
context 'with --files flag' do
let(:args) { ['--files', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to_not match(/symlinks/) } # displays files only
2017-10-22 15:41:00 +02:00
end
context 'with -1 flag' do
let(:args) { ['-1', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/(.*\n){3}/) } # displays one file per line
2017-10-22 15:41:00 +02:00
end
context 'with --almost-all flag' do
let(:args) { ['--almost-all', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/\.hidden-file/) } # displays hidden files
2017-10-22 15:41:00 +02:00
end
context 'with --tree flag' do
let(:args) { ['--tree', FIXTURES] }
2017-10-22 17:05:28 +02:00
it { is_expected.to match(/├──/) } # displays file hierarchy
2017-10-22 15:41:00 +02:00
end
end