2020-03-09 11:07:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 02:08:43 -04:00
|
|
|
require 'fast_spec_helper'
|
2020-03-09 11:07:45 -04:00
|
|
|
|
|
|
|
require_relative '../../../rubocop/cop/ban_catch_throw'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::BanCatchThrow do
|
2020-03-09 11:07:45 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'registers an offense when `catch` or `throw` are used' do
|
2021-01-26 13:09:30 -05: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 11:07:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense for a method called catch or throw' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_no_offenses(<<~CODE)
|
|
|
|
foo.catch(:foo) {
|
|
|
|
foo.throw(:foo)
|
|
|
|
}
|
|
|
|
CODE
|
2020-03-09 11:07:45 -04:00
|
|
|
end
|
|
|
|
end
|