aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGautham Goli2017-03-08 13:51:35 +0530
committerGautham Goli2017-03-26 15:26:41 +0530
commit4e57f4279aaf32855c6cc0ebc96bf9352feb1e17 (patch)
tree2dcb070eef5340da75d2acdb64fc937aa95a002e
parentd32978b859d18c68bad20614287f3485c52ad98f (diff)
downloadbrew-4e57f4279aaf32855c6cc0ebc96bf9352feb1e17.tar.bz2
Add RSpec tests for bottle_block and formula_desc cops
-rw-r--r--Library/Homebrew/test/.bundle/config2
-rw-r--r--Library/Homebrew/test/Gemfile1
-rw-r--r--Library/Homebrew/test/Gemfile.lock14
-rw-r--r--Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb67
-rw-r--r--Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb121
5 files changed, 204 insertions, 1 deletions
diff --git a/Library/Homebrew/test/.bundle/config b/Library/Homebrew/test/.bundle/config
index dcf3d1c4c..e451829e9 100644
--- a/Library/Homebrew/test/.bundle/config
+++ b/Library/Homebrew/test/.bundle/config
@@ -1,3 +1,3 @@
---
BUNDLE_PATH: "../vendor/bundle"
-BUNDLE_DISABLE_SHARED_GEMS: '1'
+BUNDLE_DISABLE_SHARED_GEMS: "true"
diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile
index bc9bccfbc..f3c16c710 100644
--- a/Library/Homebrew/test/Gemfile
+++ b/Library/Homebrew/test/Gemfile
@@ -2,6 +2,7 @@ source "https://rubygems.org"
gem "parallel_tests"
gem "rspec"
+gem "rubocop"
gem "rspec-its", require: false
gem "rspec-wait", require: false
diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock
index 64561be71..4d4eefd7d 100644
--- a/Library/Homebrew/test/Gemfile.lock
+++ b/Library/Homebrew/test/Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
+ ast (2.3.0)
codecov (0.1.9)
json
simplecov
@@ -11,6 +12,10 @@ GEM
parallel (1.10.0)
parallel_tests (2.13.0)
parallel
+ parser (2.4.0.0)
+ ast (~> 2.2)
+ powerpack (0.1.1)
+ rainbow (2.2.1)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
@@ -29,11 +34,19 @@ GEM
rspec-support (3.5.0)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
+ rubocop (0.47.1)
+ parser (>= 2.3.3.1, < 3.0)
+ powerpack (~> 0.1)
+ rainbow (>= 1.99.1, < 3.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (~> 1.0, >= 1.0.1)
+ ruby-progressbar (1.8.1)
simplecov (0.13.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
+ unicode-display_width (1.1.3)
url (0.3.2)
PLATFORMS
@@ -45,6 +58,7 @@ DEPENDENCIES
rspec
rspec-its
rspec-wait
+ rubocop
simplecov
BUNDLED WITH
diff --git a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb
new file mode 100644
index 000000000..5be2d6cf5
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb
@@ -0,0 +1,67 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/bottle_block_cop"
+
+describe RuboCop::Cop::Homebrew::CorrectBottleBlock do
+ subject(:cop) { described_class.new }
+
+ context "When auditing Bottle Block" do
+ it "When there is revision in bottle block" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ bottle do
+ cellar :any
+ revision 2
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use rebuild instead of revision in bottle block",
+ severity: :convention,
+ line: 5,
+ column: 4,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ 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
+
+ context "When auditing Bottle Block with auto correct" do
+ it "When there is revision in bottle block" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ bottle do
+ cellar :any
+ revision 2
+ end
+ end
+ EOS
+ corrected_source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ bottle do
+ cellar :any
+ rebuild 2
+ end
+ end
+ EOS
+
+ new_source = autocorrect_source(cop, source)
+ expect(new_source).to eq(corrected_source)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
new file mode 100644
index 000000000..cd506623f
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
@@ -0,0 +1,121 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/formula_desc_cop"
+
+describe RuboCop::Cop::Homebrew::FormulaDesc do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula desc" do
+ it "When there is no desc" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Formula should have a desc (Description).",
+ 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 "When desc is too long" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ desc '#{"bar"*30}'
+ end
+ EOS
+
+ msg = <<-EOS.undent
+ Description is too long. "name: desc" should be less than 80 characters.
+ Length is calculated as Foo + desc. (currently 95)
+ EOS
+ expected_offenses = [{ message: msg,
+ severity: :convention,
+ line: 3,
+ column: 7,
+ source: source }]
+
+ inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When wrong \"command-line\" usage in desc" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ desc 'command line'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Description should use \"command-line\" instead of \"command line\"",
+ severity: :convention,
+ line: 3,
+ column: 8,
+ source: source }]
+
+ inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When an article is used in desc" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ desc 'An '
+ end
+ EOS
+
+ expected_offenses = [{ message: "Description shouldn't start with an indefinite article (An )",
+ severity: :convention,
+ line: 3,
+ column: 8,
+ source: source }]
+
+ inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When formula name is in desc" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ desc 'Foo'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Description shouldn't include the formula name",
+ severity: :convention,
+ line: 3,
+ column: 8,
+ source: source }]
+
+ inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ 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