RSpec.shared_examples "matches lines containing" do |match, example_string, check_index: 0, match_index: 0, ignored: false| context match do context example_string do before(:all) { @scanner = described_class.new(Pluginscan::THE_CHECKS) } let(:file_contents) { example_string } let(:checks_findings) { @scanner.scan(file_contents) } let(:check_findings) { checks_findings[check_index] } let(:finding) do raise "Tried to get findings for the #{check_index}th check matching this line, but only #{checks_findings.count} checks match this line" if check_findings.nil? check_findings.findings[match_index] end it "finds a finding which checks_findings #{match}" do expect(checks_findings).to_not be_empty expect(finding.lineno).to eq 1 expect(finding.line).to eq file_contents expect(finding.match).to eq match expect(finding.ignored).to eq ignored end end end end RSpec.shared_examples "ignores lines containing" do |match, example_string, check_index: 0, match_index: 0| it_behaves_like "matches lines containing", match, example_string, check_index: check_index, match_index: match_index, ignored: true end RSpec.shared_examples "matches a variable assigned to a superglobal" do |superglobal| example_string = "$value = #{superglobal}['foo']" it_behaves_like "matches lines containing", superglobal, example_string end