mirror of https://github.com/licensee/licensee.git
test bin
This commit is contained in:
parent
f93bdaabe3
commit
df0737334c
|
@ -22,13 +22,16 @@ class LicenseeCLI < Thor
|
|||
rows = []
|
||||
rows << if project.license
|
||||
['License:', project.license.name]
|
||||
elsif project.licenses
|
||||
['Licenses:', project.licenses.map(&:name)]
|
||||
elsif !project.licenses.empty?
|
||||
["Licenses:", project.licenses.map(&:name)]
|
||||
else
|
||||
['License:', set_color('None', :red)]
|
||||
end
|
||||
|
||||
rows << ['Matched files:', project.matched_files.map(&:filename).join(', ')]
|
||||
unless project.matched_files.empty?
|
||||
rows << ['Matched files:', project.matched_files.map(&:filename).join(', ')]
|
||||
end
|
||||
|
||||
print_table rows
|
||||
|
||||
project.matched_files.each do |matched_file|
|
||||
|
|
|
@ -52,10 +52,15 @@ class LicenseeCLI < Thor
|
|||
end
|
||||
|
||||
def expected_license
|
||||
@expected_license ||= Licensee::License.find options[:license]
|
||||
@expected_license ||= Licensee::License.find options[:license] if options[:license]
|
||||
return @expected_license if @expected_license
|
||||
|
||||
error "#{options[:license]} is not a valid license"
|
||||
if options[:license]
|
||||
error "#{options[:license]} is not a valid license"
|
||||
else
|
||||
error "You must provide an expected license"
|
||||
end
|
||||
|
||||
error "Valid licenses: #{Licensee::License.all(hidden: true).map(&:key).join(', ')}"
|
||||
exit 1
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
RSpec.describe 'command line invocation' do
|
||||
let(:command) { ['bundle', 'exec', 'bin/licensee'] }
|
||||
let(:command) { ['bundle', 'exec', 'bin/licensee'].push(subcommand) }
|
||||
let(:arguments) { [] }
|
||||
let(:output) do
|
||||
Dir.chdir project_root do
|
||||
puts [command, arguments].flatten.inspect
|
||||
Open3.capture3(*[command, arguments].flatten)
|
||||
end
|
||||
end
|
||||
|
@ -11,41 +11,77 @@ RSpec.describe 'command line invocation' do
|
|||
let(:stderr) { output[1] }
|
||||
let(:status) { output[2] }
|
||||
let(:hash) { '46cdc03462b9af57968df67b450cc4372ac41f53' }
|
||||
let(:expected) {
|
||||
{
|
||||
"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"
|
||||
|
||||
context "detection" do
|
||||
let(:subcommand) { 'detect' }
|
||||
|
||||
let(:expected) {
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"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 }
|
||||
{
|
||||
"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 a zero exit code' do
|
||||
expect(status.exitstatus).to eql(0)
|
||||
end
|
||||
|
||||
it "returns the exected values" do
|
||||
puts stdout
|
||||
expect(parsed_output).to eql(expected), stdout + stderr
|
||||
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
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue