break command tests out into individual files

This commit is contained in:
Ben Balter 2018-02-06 11:09:18 -05:00
parent 134e8e7716
commit 3fad55bf5e
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
4 changed files with 133 additions and 89 deletions

View File

@ -1,5 +1,5 @@
RSpec.describe 'command line invocation' do
let(:command) { ['bundle', 'exec', 'bin/licensee'].push(subcommand) }
let(:command) { ['bundle', 'exec', 'bin/licensee', 'help'] }
let(:arguments) { [] }
let(:output) do
Dir.chdir project_root do
@ -10,96 +10,12 @@ RSpec.describe 'command line invocation' do
let(:stdout) { output[0] }
let(:stderr) { output[1] }
let(:status) { output[2] }
let(:hash) { '46cdc03462b9af57968df67b450cc4372ac41f53' }
context 'detection' do
let(:subcommand) { 'detect' }
let(:expected) do
{
'License' => 'MIT License',
'Matched files' => 'LICENSE.md, licensee.gemspec',
'LICENSE.md' => {
'Content hash' => hash,
'Attribution' => 'Copyright (c) 2014-2017 Ben Balter',
'Confidence' => '100.00%',
'Matcher' => 'Licensee::Matchers::Exact',
'License' => 'MIT License'
},
'licensee.gemspec' => {
'Confidence' => '90.00%',
'Matcher' => 'Licensee::Matchers::Gemspec',
'License' => 'MIT License'
}
}
end
{
'No arguments' => [],
'Project root' => [project_root],
'License path' => [File.expand_path('LICENSE.md', project_root)]
}.each do |name, args|
context "When given #{name}" do
let(:arguments) { args }
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
it 'returns the exected values' do
hash = expected.dup
if name == 'License path'
hash.delete('licensee.gemspec')
hash['Matched files'] = 'LICENSE.md'
end
expect(parsed_output).to eql(hash)
end
end
end
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
context 'version' do
let(:subcommand) { 'version' }
it 'returns the version' do
expect(stdout).to include(Licensee::VERSION)
end
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
end
context 'license-path' do
let(:subcommand) { 'license-path' }
let(:arguments) { [project_root] }
it 'returns the license path' do
expect(stdout).to match(File.join(project_root, 'LICENSE.md'))
end
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
end
context 'json' do
let(:subcommand) { 'detect' }
let(:arguments) { ['--json'] }
let(:expected) { JSON.parse fixture_contents('detect.json') }
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
it 'returns valid JSON' do
expect { JSON.parse(stdout) }.to_not raise_error
end
it 'returns the expected output' do
expect(JSON.parse(stdout)).to eql(expected)
end
it 'returns the help text' do
expect(stdout).to include('Licensee commands:')
end
end

View File

@ -0,0 +1,86 @@
RSpec.describe 'detect command' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'detect'] }
let(:arguments) { [] }
let(:output) do
Dir.chdir project_root do
Open3.capture3(*[command, arguments].flatten)
end
end
let(:parsed_output) { YAML.safe_load(stdout) }
let(:stdout) { output[0] }
let(:stderr) { output[1] }
let(:status) { output[2] }
let(:hash) { '46cdc03462b9af57968df67b450cc4372ac41f53' }
let(:expected) do
{
'License' => 'MIT License',
'Matched files' => 'LICENSE.md, licensee.gemspec',
'LICENSE.md' => {
'Content hash' => hash,
'Attribution' => 'Copyright (c) 2014-2017 Ben Balter',
'Confidence' => '100.00%',
'Matcher' => 'Licensee::Matchers::Exact',
'License' => 'MIT License'
},
'licensee.gemspec' => {
'Confidence' => '90.00%',
'Matcher' => 'Licensee::Matchers::Gemspec',
'License' => 'MIT License'
}
}
end
{
'No arguments' => [],
'Project root' => [project_root],
'License path' => [File.expand_path('LICENSE.md', project_root)]
}.each do |name, args|
context "When given #{name}" do
let(:arguments) { args }
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
it 'returns the exected values' do
hash = expected.dup
if name == 'License path'
hash.delete('licensee.gemspec')
hash['Matched files'] = 'LICENSE.md'
end
expect(parsed_output).to eql(hash)
end
end
end
context 'json' do
let(:arguments) { ['--json'] }
let(:expected) { JSON.parse fixture_contents('detect.json') }
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
it 'returns valid JSON' do
expect { JSON.parse(stdout) }.to_not raise_error
end
it 'returns the expected output' do
expect(JSON.parse(stdout)).to eql(expected)
end
end
context 'the default command' do
let(:command) { ['bundle', 'exec', 'bin/licensee'] }
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
it 'returns the exected values' do
expect(parsed_output).to eql(expected)
end
end
end

View File

@ -0,0 +1,21 @@
RSpec.describe 'license-path command' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'license-path'] }
let(:arguments) { [project_root] }
let(:output) do
Dir.chdir project_root do
Open3.capture3(*[command, arguments].flatten)
end
end
let(:parsed_output) { YAML.safe_load(stdout) }
let(:stdout) { output[0] }
let(:stderr) { output[1] }
let(:status) { output[2] }
it 'returns the license path' do
expect(stdout).to match(File.join(project_root, 'LICENSE.md'))
end
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
end

View File

@ -0,0 +1,21 @@
RSpec.describe 'version command' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'version'] }
let(:arguments) { [] }
let(:output) do
Dir.chdir project_root do
Open3.capture3(*[command, arguments].flatten)
end
end
let(:parsed_output) { YAML.safe_load(stdout) }
let(:stdout) { output[0] }
let(:stderr) { output[1] }
let(:status) { output[2] }
it 'returns the version' do
expect(stdout).to include(Licensee::VERSION)
end
it 'Returns a zero exit code' do
expect(status.exitstatus).to eql(0)
end
end