summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-09 15:07:45 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-09 15:07:45 +0000
commitf1a40d0db939dfe8ff95d385e652ff72566be765 (patch)
treecdca36cb171cdffff2739c37c23e74914e57a836 /spec
parentac1dca43baa7b3b1ac7d60d89ad60fdeefed0b80 (diff)
downloadgitlab-ce-f1a40d0db939dfe8ff95d385e652ff72566be765.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/encoding_helper_spec.rb6
-rw-r--r--spec/rubocop/cop/ban_catch_throw_spec.rb30
2 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/encoding_helper_spec.rb b/spec/lib/gitlab/encoding_helper_spec.rb
index d091b6c1601..e6dfd8728aa 100644
--- a/spec/lib/gitlab/encoding_helper_spec.rb
+++ b/spec/lib/gitlab/encoding_helper_spec.rb
@@ -128,6 +128,12 @@ describe Gitlab::EncodingHelper do
expect { ext_class.encode_utf8('') }.not_to raise_error
end
+ it 'replaces invalid and undefined chars with the replace argument' do
+ str = 'hællo'.encode(Encoding::UTF_16LE).force_encoding(Encoding::ASCII_8BIT)
+
+ expect(ext_class.encode_utf8(str, replace: "\u{FFFD}")).to eq("h�llo")
+ end
+
context 'with strings that can be forcefully encoded into utf8' do
let(:test_string) do
"refs/heads/FixSymbolsTitleDropdown".encode("ASCII-8BIT")
diff --git a/spec/rubocop/cop/ban_catch_throw_spec.rb b/spec/rubocop/cop/ban_catch_throw_spec.rb
new file mode 100644
index 00000000000..b4c277fc429
--- /dev/null
+++ b/spec/rubocop/cop/ban_catch_throw_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../rubocop/cop/ban_catch_throw'
+
+describe RuboCop::Cop::BanCatchThrow do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ it 'registers an offense when `catch` or `throw` are used' do
+ inspect_source("catch(:foo) {\n throw(:foo)\n}")
+
+ aggregate_failures do
+ expect(cop.offenses.size).to eq(2)
+ expect(cop.offenses.map(&:line)).to eq([1, 2])
+ expect(cop.highlights).to eq(['catch(:foo)', 'throw(:foo)'])
+ end
+ end
+
+ it 'does not register an offense for a method called catch or throw' do
+ inspect_source("foo.catch(:foo) {\n foo.throw(:foo)\n}")
+
+ expect(cop.offenses).to be_empty
+ end
+end