Commit c3c05892 authored by dcouture's avatar dcouture

Remove usage of allow_any_instance_of

parent 30ffdabf
...@@ -4,14 +4,14 @@ require 'spec_helper' ...@@ -4,14 +4,14 @@ require 'spec_helper'
RSpec.describe GitlabScriptTagHelper do RSpec.describe GitlabScriptTagHelper do
before do before do
allow_any_instance_of(GitlabScriptTagHelper).to receive(:content_security_policy_nonce).and_return('noncevalue') allow(helper).to receive(:content_security_policy_nonce).and_return('noncevalue')
end end
describe 'external script tag' do describe 'external script tag' do
let(:script_url) { 'test.js' } let(:script_url) { 'test.js' }
it 'returns a script tag with defer=true and a nonce' do it 'returns a script tag with defer=true and a nonce' do
expect(javascript_include_tag(script_url).to_s) expect(helper.javascript_include_tag(script_url).to_s)
.to eq "<script src=\"/javascripts/#{script_url}\" defer=\"defer\" nonce=\"noncevalue\"></script>" .to eq "<script src=\"/javascripts/#{script_url}\" defer=\"defer\" nonce=\"noncevalue\"></script>"
end end
end end
...@@ -21,24 +21,24 @@ RSpec.describe GitlabScriptTagHelper do ...@@ -21,24 +21,24 @@ RSpec.describe GitlabScriptTagHelper do
let(:tag_with_nonce_and_type) {"<script type=\"application/javascript\" nonce=\"noncevalue\">\n//<![CDATA[\nalert(1)\n//]]>\n</script>"} let(:tag_with_nonce_and_type) {"<script type=\"application/javascript\" nonce=\"noncevalue\">\n//<![CDATA[\nalert(1)\n//]]>\n</script>"}
it 'returns a script tag with a nonce using block syntax' do it 'returns a script tag with a nonce using block syntax' do
expect(javascript_tag { 'alert(1)' }.to_s).to eq tag_with_nonce expect(helper.javascript_tag { 'alert(1)' }.to_s).to eq tag_with_nonce
end end
it 'returns a script tag with a nonce using block syntax with options' do it 'returns a script tag with a nonce using block syntax with options' do
expect(javascript_tag(type: 'application/javascript') { 'alert(1)' }.to_s).to eq tag_with_nonce_and_type expect(helper.javascript_tag(type: 'application/javascript') { 'alert(1)' }.to_s).to eq tag_with_nonce_and_type
end end
it 'returns a script tag with a nonce using argument syntax' do it 'returns a script tag with a nonce using argument syntax' do
expect(javascript_tag('alert(1)').to_s).to eq tag_with_nonce expect(helper.javascript_tag('alert(1)').to_s).to eq tag_with_nonce
end end
it 'returns a script tag with a nonce using argument syntax with options' do it 'returns a script tag with a nonce using argument syntax with options' do
expect(javascript_tag( 'alert(1)', type: 'application/javascript').to_s).to eq tag_with_nonce_and_type expect(helper.javascript_tag( 'alert(1)', type: 'application/javascript').to_s).to eq tag_with_nonce_and_type
end end
# This scenario does not really make sense, but it's supported so we test it # This scenario does not really make sense, but it's supported so we test it
it 'returns a script tag with a nonce using argument and block syntax with options' do it 'returns a script tag with a nonce using argument and block syntax with options' do
expect(javascript_tag( '// ignored', type: 'application/javascript') { 'alert(1)' }.to_s).to eq tag_with_nonce_and_type expect(helper.javascript_tag( '// ignored', type: 'application/javascript') { 'alert(1)' }.to_s).to eq tag_with_nonce_and_type
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment