diff options
| author | Mike McQuaid | 2017-05-15 10:02:47 +0100 |
|---|---|---|
| committer | GitHub | 2017-05-15 10:02:47 +0100 |
| commit | ea8be174f6009bc9bdec67b13ca501b5b83fc4b8 (patch) | |
| tree | 0b2a1adeabd135d35c6f0a7d3c53df4d8797c907 /Library/Homebrew/test/rubocops | |
| parent | 9889b42ec4396dca190fb0823453e259344ee015 (diff) | |
| parent | 91efcb045e687301a8440d91e55ddbc1c053b757 (diff) | |
| download | brew-ea8be174f6009bc9bdec67b13ca501b5b83fc4b8.tar.bz2 | |
Merge pull request #2631 from GauthamGoli/audit_homepage_rubocop1.2.1
audit: Port audit_homepage method to rubocop and add tests
Diffstat (limited to 'Library/Homebrew/test/rubocops')
| -rw-r--r-- | Library/Homebrew/test/rubocops/homepage_cop_spec.rb | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb new file mode 100644 index 000000000..c03efd825 --- /dev/null +++ b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb @@ -0,0 +1,124 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/homepage_cop" + +describe RuboCop::Cop::FormulaAudit::Homepage do + subject(:cop) { described_class.new } + + context "When auditing homepage" do + it "When there is no homepage" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "Formula should have a homepage.", + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "Homepage with ftp" do + source = <<-EOS.undent + class Foo < Formula + homepage "ftp://example.com/foo" + url "http://example.com/foo-1.0.tgz" + end + EOS + + expected_offenses = [{ message: "The homepage should start with http or https (URL is ftp://example.com/foo).", + severity: :convention, + line: 2, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "Homepage URLs" do + formula_homepages = { + "bar" => "http://www.freedesktop.org/wiki/bar", + "baz" => "http://www.freedesktop.org/wiki/Software/baz", + "qux" => "https://code.google.com/p/qux", + "quux" => "http://github.com/quux", + "corge" => "http://savannah.nongnu.org/corge", + "grault" => "http://grault.github.io/", + "garply" => "http://www.gnome.org/garply", + "sf1" => "http://foo.sourceforge.net/", + "sf2" => "http://foo.sourceforge.net", + "sf3" => "http://foo.sf.net/", + "sf4" => "http://foo.sourceforge.io/", + "waldo" => "http://www.gnu.org/waldo", + } + + formula_homepages.each do |name, homepage| + source = <<-EOS.undent + class #{name.capitalize} < Formula + homepage "#{homepage}" + url "http://example.com/#{name}-1.0.tgz" + end + EOS + + inspect_source(cop, source) + if homepage =~ %r{http:\/\/www\.freedesktop\.org} + if homepage =~ /Software/ + expected_offenses = [{ message: "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/www/Software/project_name`", + severity: :convention, + line: 2, + column: 2, + source: source }] + else + expected_offenses = [{ message: "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/project_name`", + severity: :convention, + line: 2, + column: 2, + source: source }] + end + elsif homepage =~ %r{https:\/\/code\.google\.com} + expected_offenses = [{ message: "#{homepage} should end with a slash", + severity: :convention, + line: 2, + column: 2, + source: source }] + elsif homepage =~ /foo\.(sf|sourceforge)\.net/ + expected_offenses = [{ message: "#{homepage} should be `https://foo.sourceforge.io/`", + severity: :convention, + line: 2, + column: 2, + source: source }] + else + expected_offenses = [{ message: "Please use https:// for #{homepage}", + severity: :convention, + line: 2, + column: 2, + source: source }] + end + expected_offenses.zip([cop.offenses.last]).each do |expected, actual| + expect_offense(expected, actual) + end + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end +end |
