test JSON output

This commit is contained in:
Ben Balter 2018-02-06 10:54:59 -05:00
parent 1981678146
commit 93bbe384c8
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 129 additions and 0 deletions

View File

@ -84,4 +84,22 @@ RSpec.describe 'command line invocation' 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
end
end

111
spec/fixtures/detect.json vendored Normal file
View File

@ -0,0 +1,111 @@
{
"licenses": [
{
"key": "mit",
"spdx_id": "MIT",
"meta": {
"title": "MIT License",
"source": "https://opensource.org/licenses/MIT",
"description": "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.",
"how": "Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders.",
"using": [
{
"Babel": "https://github.com/babel/babel/blob/master/LICENSE"
},
{
".NET Core": "https://github.com/dotnet/corefx/blob/master/LICENSE.TXT"
},
{
"Rails": "https://github.com/rails/rails/blob/master/MIT-LICENSE"
}
],
"featured": true,
"hidden": false,
"nickname": null,
"note": null
},
"url": "http://choosealicense.com/licenses/mit/",
"rules": {
"permissions": [
{
"tag": "commercial-use",
"label": "Commercial use",
"description": "This software and derivatives may be used for commercial purposes."
},
{
"tag": "modifications",
"label": "Modification",
"description": "This software may be modified."
},
{
"tag": "distribution",
"label": "Distribution",
"description": "This software may be distributed."
},
{
"tag": "private-use",
"label": "Private use",
"description": "This software may be used and modified in private."
}
],
"conditions": [
{
"tag": "include-copyright",
"label": "License and copyright notice",
"description": "A copy of the license and copyright notice must be included with the software."
}
],
"limitations": [
{
"tag": "liability",
"label": "Liability",
"description": "This license includes a limitation of liability."
},
{
"tag": "warranty",
"label": "Warranty",
"description": "The license explicitly states that it does NOT provide any warranty."
}
]
},
"fields": [
{
"name": "year",
"description": "The current year"
},
{
"name": "fullname",
"description": "The full name or username of the repository owner"
}
],
"other": false,
"gpl": false,
"lgpl": false,
"cc": false
}
],
"matched_files": [
{
"filename": "LICENSE.md",
"content": "MIT License\n\nCopyright (c) 2014-2017 Ben Balter\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"content_hash": "46cdc03462b9af57968df67b450cc4372ac41f53",
"content_normalized": "permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files the \"software\" , to deal in the software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the software. the software is provided \"as is\", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.",
"matcher": {
"name": "Exact",
"confidence": 100
},
"matched_license": "mit"
},
{
"filename": "licensee.gemspec",
"content": "require File.expand_path('../lib/licensee/version', __FILE__)\n\nGem::Specification.new do |gem|\n gem.name = 'licensee'\n gem.version = Licensee::VERSION\n\n gem.summary = 'A Ruby Gem to detect open source project licenses'\n gem.description = <<-DESC\n Licensee automates the process of reading LICENSE files and\n compares their contents to known licenses using a fancy maths.\n DESC\n\n gem.authors = ['Ben Balter']\n gem.email = 'ben.balter@github.com'\n gem.homepage = 'https://github.com/benbalter/licensee'\n gem.license = 'MIT'\n\n gem.bindir = 'bin'\n gem.executables << 'licensee'\n\n gem.add_dependency('dotenv', '~> 2.0')\n gem.add_dependency('octokit', '~> 4.8.0')\n gem.add_dependency('rugged', '~> 0.24')\n gem.add_dependency('thor', '~> 0.19')\n\n gem.add_development_dependency('coveralls', '~> 0.8')\n gem.add_development_dependency('mustache', '>= 0.9', '< 2.0')\n gem.add_development_dependency('pry', '~> 0.9')\n gem.add_development_dependency('rake', '~> 10.3')\n gem.add_development_dependency('rspec', '~> 3.5')\n gem.add_development_dependency('rubocop', '~> 0.49')\n gem.add_development_dependency('webmock', '~> 3.1')\n\n gem.required_ruby_version = '>= 2.1'\n\n # ensure the gem is built out of versioned files\n gem.files = Dir[\n 'Rakefile',\n '{bin,lib,man,test,vendor,spec}/**/*',\n 'README*', 'LICENSE*'\n ] & `git ls-files -z`.split(\"\\0\")\nend\n",
"content_hash": null,
"content_normalized": null,
"matcher": {
"name": "Gemspec",
"confidence": 90
},
"matched_license": "mit"
}
]
}