mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Use rspec-its
This commit is contained in:
parent
ca6c073252
commit
e88a786a13
3 changed files with 82 additions and 78 deletions
|
@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
|
|||
spec.add_development_dependency 'diffy'
|
||||
spec.add_development_dependency 'rake'
|
||||
spec.add_development_dependency 'rspec'
|
||||
spec.add_development_dependency 'rspec-its'
|
||||
spec.add_development_dependency 'rubocop'
|
||||
spec.add_development_dependency 'rubygems-tasks'
|
||||
end
|
||||
|
|
|
@ -1,85 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe ColorLS do
|
||||
FIXTURES = 'spec/fixtures'.freeze
|
||||
|
||||
it 'has a version number' do
|
||||
expect(ColorLS::VERSION).not_to be nil
|
||||
end
|
||||
|
||||
it 'lists info of a hidden file with --long option' do
|
||||
expect { ColorLS::Flags.new('--long', "#{FIXTURES}/.hidden-file").process }.to_not output(/No Info/).to_stdout
|
||||
end
|
||||
|
||||
it 'does not list file info without --long' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout
|
||||
end
|
||||
|
||||
it 'lists file info with --long' do
|
||||
expect { ColorLS::Flags.new('--long', FIXTURES).process }.to output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout
|
||||
end
|
||||
|
||||
it 'does not list hidden files without --all option' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(/\.hidden-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'lists hidden files with --all option' do
|
||||
expect { ColorLS::Flags.new('--all', FIXTURES).process }.to output(/\.hidden-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'does not show a report without --report option' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(/Found \d+ contents/).to_stdout
|
||||
end
|
||||
|
||||
it 'sorts all results alphabetically without --sort-dirs or --sort-files' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to output(/a-file.+symlinks.+z-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'sorts results alphabetically, directories first with --sort-dirs' do
|
||||
expect { ColorLS::Flags.new('--sort-dirs', FIXTURES).process }.to output(/symlinks.+a-file.+z-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'sorts results alphabetically, files first with --sort-files' do
|
||||
expect { ColorLS::Flags.new('--sort-files', FIXTURES).process }.to output(/a-file.+z-file.+symlinks/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays dirs & files without --dirs or --files' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to output(/a-file.+symlinks/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays dirs only with --dirs' do
|
||||
expect { ColorLS::Flags.new('--dirs', FIXTURES).process }.to_not output(/a-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays files only with --files' do
|
||||
expect { ColorLS::Flags.new('--files', FIXTURES).process }.to_not output(/symlinks/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays multiple files per line without -1' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(/(.*\n){3}/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays one file per line with -1' do
|
||||
expect { ColorLS::Flags.new('-1', FIXTURES).process }.to output(/(.*\n){3}/).to_stdout
|
||||
end
|
||||
|
||||
it 'does not display hidden files without --almost-all' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(/\.hidden-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays hidden files with --almost-all' do
|
||||
expect { ColorLS::Flags.new('--almost-all', FIXTURES).process }.to output(/\.hidden-file/).to_stdout
|
||||
end
|
||||
|
||||
it 'does not display ./ or ../ with --almost-all' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(%r(\.{1,2}/)).to_stdout
|
||||
end
|
||||
|
||||
it 'does not display file hierarchy without --tree' do
|
||||
expect { ColorLS::Flags.new(FIXTURES).process }.to_not output(/├──/).to_stdout
|
||||
end
|
||||
|
||||
it 'displays file hierarchy with --tree' do
|
||||
expect { ColorLS::Flags.new('--tree', FIXTURES).process }.to output(/├──/).to_stdout
|
||||
end
|
||||
end
|
||||
|
|
81
spec/flags_spec.rb
Normal file
81
spec/flags_spec.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe ColorLS::Flags do
|
||||
FIXTURES = 'spec/fixtures'.freeze
|
||||
|
||||
subject { ColorLS::Flags.new(*args).process }
|
||||
|
||||
context 'with no flags' do
|
||||
let(:args) { [FIXTURES] }
|
||||
|
||||
it { is_expected.to_not output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout } # does not list file info
|
||||
it { is_expected.to_not output(/\.hidden-file/).to_stdout } # does not list hidden files
|
||||
it { is_expected.to_not output(/Found \d+ contents/).to_stdout } # does not show a report
|
||||
it { is_expected.to output(/a-file.+symlinks.+z-file/).to_stdout } # sorts all results alphabetically
|
||||
it { is_expected.to output(/a-file.+symlinks/).to_stdout } # displays dirs & files
|
||||
it { is_expected.to_not output(/(.*\n){3}/).to_stdout } # displays multiple files per line
|
||||
it { is_expected.to_not output(/\.hidden-file/).to_stdout } # does not display hidden files
|
||||
it { is_expected.to_not output(%r(\.{1,2}/)).to_stdout } # does not display ./ or ../
|
||||
it { is_expected.to_not output(/├──/).to_stdout } # does not display file hierarchy
|
||||
end
|
||||
|
||||
context 'with --long flag & file path' do
|
||||
let(:args) { ['--long', "#{FIXTURES}/.hidden-file"] }
|
||||
|
||||
it { is_expected.to_not output(/No Info/).to_stdout } # lists info of a hidden file
|
||||
end
|
||||
|
||||
context 'with --long flag' do
|
||||
let(:args) { ['--long', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout } # lists file info
|
||||
end
|
||||
|
||||
context 'with --all flag' do
|
||||
let(:args) { ['--all', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/\.hidden-file/).to_stdout } # lists hidden files
|
||||
end
|
||||
|
||||
context 'with --sort-dirs flag' do
|
||||
let(:args) { ['--sort-dirs', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/symlinks.+a-file.+z-file/).to_stdout } # sorts results alphabetically, directories first
|
||||
end
|
||||
|
||||
context 'with --sort-files flag' do
|
||||
let(:args) { ['--sort-files', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/a-file.+z-file.+symlinks/).to_stdout } # sorts results alphabetically, files first
|
||||
end
|
||||
|
||||
context 'with --dirs flag' do
|
||||
let(:args) { ['--dirs', FIXTURES] }
|
||||
|
||||
it { is_expected.to_not output(/a-file/).to_stdout } # displays dirs only
|
||||
end
|
||||
|
||||
context 'with --files flag' do
|
||||
let(:args) { ['--files', FIXTURES] }
|
||||
|
||||
it { is_expected.to_not output(/symlinks/).to_stdout } # displays files only
|
||||
end
|
||||
|
||||
context 'with -1 flag' do
|
||||
let(:args) { ['-1', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/(.*\n){3}/).to_stdout } # displays one file per line
|
||||
end
|
||||
|
||||
context 'with --almost-all flag' do
|
||||
let(:args) { ['--almost-all', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/\.hidden-file/).to_stdout } # displays hidden files
|
||||
end
|
||||
|
||||
context 'with --tree flag' do
|
||||
let(:args) { ['--tree', FIXTURES] }
|
||||
|
||||
it { is_expected.to output(/├──/).to_stdout } # displays file hierarchy
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue