2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
require 'fast_spec_helper'
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
require_relative '../../../rubocop/cop/ban_catch_throw'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::BanCatchThrow do
|
2020-04-08 14:13:33 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'registers an offense when `catch` or `throw` are used' do
|
2021-03-11 19:13:27 +05:30
|
|
|
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-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense for a method called catch or throw' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_no_offenses(<<~CODE)
|
|
|
|
foo.catch(:foo) {
|
|
|
|
foo.throw(:foo)
|
|
|
|
}
|
|
|
|
CODE
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|