Skip to content
Snippets Groups Projects
Commit 4e57f427 authored by Gautham Goli's avatar Gautham Goli
Browse files

Add RSpec tests for bottle_block and formula_desc cops

parent d32978b8
No related branches found
No related tags found
No related merge requests found
---
BUNDLE_PATH: "../vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_DISABLE_SHARED_GEMS: "true"
......@@ -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
......
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
......
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment