2020-03-09 15:07:45 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2020-03-09 15:07:45 +00:00
|
|
|
|
|
|
|
require_relative '../../../rubocop/cop/ban_catch_throw'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::BanCatchThrow do
|
2020-03-09 15:07:45 +00:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'registers an offense when `catch` or `throw` are used' do
|
2021-01-26 18:09:30 +00:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
catch(:foo) {
|
|
|
|
^^^^^^^^^^^ Do not use catch or throw unless a gem's API demands it.
|
|
|
|
throw(:foo)
|
|
|
|
^^^^^^^^^^^ Do not use catch or throw unless a gem's API demands it.
|
|
|
|
}
|
|
|
|
CODE
|
2020-03-09 15:07:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense for a method called catch or throw' do
|
2021-01-26 18:09:30 +00:00
|
|
|
expect_no_offenses(<<~CODE)
|
|
|
|
foo.catch(:foo) {
|
|
|
|
foo.throw(:foo)
|
|
|
|
}
|
|
|
|
CODE
|
2020-03-09 15:07:45 +00:00
|
|
|
end
|
|
|
|
end
|