2017-03-08 13:51:35 +05:30
|
|
|
require "rubocop"
|
|
|
|
require "rubocop/rspec/support"
|
|
|
|
require_relative "../../extend/string"
|
|
|
|
require_relative "../../rubocops/bottle_block_cop"
|
|
|
|
|
2017-05-03 11:33:00 +05:30
|
|
|
describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do
|
2017-03-08 13:51:35 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context "When auditing Bottle Block" do
|
|
|
|
it "When there is revision in bottle block" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-03-08 13:51:35 +05:30
|
|
|
class Foo < Formula
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
bottle do
|
|
|
|
cellar :any
|
|
|
|
revision 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-07-13 12:43:01 +05:30
|
|
|
expected_offenses = [{ message: described_class::MSG,
|
2017-03-08 13:51:35 +05:30
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 4,
|
|
|
|
source: source }]
|
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
inspect_source(source)
|
2017-03-08 13:51:35 +05:30
|
|
|
|
|
|
|
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
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-03-08 13:51:35 +05:30
|
|
|
class Foo < Formula
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
bottle do
|
|
|
|
cellar :any
|
|
|
|
revision 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
2017-10-15 02:28:32 +02:00
|
|
|
corrected_source = <<~EOS
|
2017-03-08 13:51:35 +05:30
|
|
|
class Foo < Formula
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
bottle do
|
|
|
|
cellar :any
|
|
|
|
rebuild 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
new_source = autocorrect_source(source)
|
2017-03-08 13:51:35 +05:30
|
|
|
expect(new_source).to eq(corrected_source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|