<NME> configuration_spec.rb
<BEF> # frozen_string_literal: true

require 'spec_helper'
require 'yaml'

module Cucumber
  module Cli
      attr_reader :options
    end

    def convert_hash_to_yaml_erb(hash)
      ["---", *hash.map { |k,v| "#{k}: #{v}" }].join "\n"
    end

    def given_cucumber_yml_defined_as(hash_or_string)
      File.stub!(:exist?).and_return(true)
      cucumber_yml = hash_or_string.is_a?(Hash) ? convert_hash_to_yaml_erb(hash_or_string) : hash_or_string
      IO.stub!(:read).with('cucumber.yml').and_return(cucumber_yml)
    end


        allow(IO).to receive(:read).with('cucumber.yml') { cucumber_yml }
      end

      def given_the_following_files(*files)
        allow(File).to receive(:directory?) { true }
        allow(File).to receive(:file?) { true }
        allow(Dir).to receive(:[]) { files }
      end

      before(:each) do
        allow(File).to receive(:exist?) { false } # Meaning, no cucumber.yml exists
        allow(Kernel).to receive(:exit)
      end

      def config
        @config ||= Configuration.new(@out = StringIO.new, @error = StringIO.new).extend(ExposesOptions)
      end

      def reset_config
        @config = nil
      end

      attr_reader :out, :error

      it 'uses the default profile when no profile is defined' do
        given_cucumber_yml_defined_as('default' => '--require some_file')

        config.parse!(%w[--format progress])

        expect(config.options[:require]).to include('some_file')
      end

      context '--profile' do
        include RSpec::WorkInProgress

        it 'expands args from profiles in the cucumber.yml file' do
          given_cucumber_yml_defined_as('bongo' => '--require from/yml')

          config.parse!(%w[--format progress --profile bongo])

          expect(config.options[:formats]).to eq [['progress', {}, out]]
          expect(config.options[:require]).to eq ['from/yml']
        end

        it 'expands args from the default profile when no flags are provided' do
          given_cucumber_yml_defined_as('default' => '--require from/yml')

          config.parse!([])

          expect(config.options[:require]).to eq ['from/yml']
        end

        it 'allows --strict to be set by a profile' do
          given_cucumber_yml_defined_as('bongo' => '--strict')

          config.parse!(%w[--profile bongo])

          expect(config.options[:strict].strict?(:undefined)).to be true
          expect(config.options[:strict].strict?(:pending)).to be true
          expect(config.options[:strict].strict?(:flaky)).to be true
        end

        it 'allows --strict from a profile to be selectively overridden' do
          given_cucumber_yml_defined_as('bongo' => '--strict')

          config.parse!(%w[--profile bongo --no-strict-flaky])

          expect(config.options[:strict].strict?(:undefined)).to be true
          expect(config.options[:strict].strict?(:pending)).to be true
          expect(config.options[:strict].strict?(:flaky)).to be false
        end

        it 'parses ERB syntax in the cucumber.yml file' do
          given_cucumber_yml_defined_as("---\ndefault: \"<%=\"--require some_file\"%>\"\n")

          config.parse!([])

          expect(config.options[:require]).to include('some_file')
        end

        it 'parses ERB in cucumber.yml that makes uses nested ERB sessions' do
          given_cucumber_yml_defined_as(<<ERB_YML)
<%= ERB.new({'standard' => '--require some_file'}.to_yaml).result %>
<%= ERB.new({'enhanced' => '--require other_file'}.to_yaml).result %>
ERB_YML

          config.parse!(%w[-p standard])

          expect(config.options[:require]).to include('some_file')
        end

        it 'provides a helpful error message when a specified profile does not exists in cucumber.yml' do
          given_cucumber_yml_defined_as('default' => '--require from/yml', 'json_report' => '--format json')

          expected_message = <<-END_OF_MESSAGE
Could not find profile: 'i_do_not_exist'

Defined profiles in cucumber.yml:
  * default
  * json_report
          END_OF_MESSAGE

          expect { config.parse!(%w[--profile i_do_not_exist]) }.to raise_error(ProfileNotFound, expected_message)
        end

        it 'allows profiles to be defined in arrays' do
          given_cucumber_yml_defined_as('foo' => ['-f', 'progress'])

          config.parse!(%w[--profile foo])

          expect(config.options[:formats]).to eq [['progress', {}, out]]
        end

        it 'disregards default STDOUT formatter defined in profile when another is passed in (via cmd line)' do
          given_cucumber_yml_defined_as('foo' => %w[--format pretty])
          config.parse!(%w[--format progress --profile foo])

          expect(config.options[:formats]).to eq [['progress', {}, out]]
        end

        ['--no-profile', '-P'].each do |flag|
          context 'when none is specified with #{flag}' do # rubocop:disable Lint/InterpolationCheck
            it 'disables profiles' do
              given_cucumber_yml_defined_as('default' => '-v --require file_specified_in_default_profile.rb')

              config.parse!("#{flag} --require some_file.rb".split(' '))

              expect(config.options[:require]).to eq ['some_file.rb']
            end

            it 'notifies the user that the profiles are being disabled' do
              given_cucumber_yml_defined_as('default' => '-v')

              config.parse!("#{flag} --require some_file.rb".split(' '))

              expect(out.string).to match(/Disabling profiles.../)
            end
          end
        end

        it 'issues a helpful error message when a specified profile exists but is nil or blank' do
          [nil, '   '].each do |bad_input|
            given_cucumber_yml_defined_as('foo' => bad_input)

            expected_error = /The 'foo' profile in cucumber.yml was blank.  Please define the command line arguments for the 'foo' profile in cucumber.yml./

            expect { config.parse!(%w[--profile foo]) }.to raise_error(expected_error)
          end
        end

        it 'issues a helpful error message when no YAML file exists and a profile is specified' do
          expect(File).to receive(:exist?).with('cucumber.yml') { false }

          expected_error = /cucumber\.yml was not found/

          expect { config.parse!(%w[--profile i_do_not_exist]) }.to raise_error(expected_error)
        end

        it 'issues a helpful error message when cucumber.yml is blank or malformed' do
          expected_error_message = /cucumber\.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./

          ['', 'sfsadfs', "--- \n- an\n- array\n", '---dddfd'].each do |bad_input|
            given_cucumber_yml_defined_as(bad_input)

            expect { config.parse!([]) }.to raise_error(expected_error_message)

            reset_config
          end
        end

        it 'issues a helpful error message when cucumber.yml can not be parsed' do
          expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage./

          given_cucumber_yml_defined_as('input that causes an exception in YAML loading')

          expect(YAML).to receive(:load).and_raise(ArgumentError)
          expect { config.parse!([]) }.to raise_error(expected_error_message)
        end

        it 'issues a helpful error message when cucumber.yml can not be parsed by ERB' do
          expected_error_message = /cucumber.yml was found, but could not be parsed with ERB.  Please refer to cucumber's documentation on correct profile usage./
          given_cucumber_yml_defined_as('<% this_fails %>')

          expect { config.parse!([]) }.to raise_error(expected_error_message)
        end
      end

      it 'accepts --dry-run option' do
        config.parse!(%w[--dry-run])

        expect(config.options[:dry_run]).to be true
      end

      it 'implies --no-duration with --dry-run option' do
        config.parse!(%w[--dry-run])

        expect(config.options[:duration]).to be false
      end

      it 'accepts --no-source option' do
        config.parse!(%w[--no-source])

        expect(config.options[:source]).to be false
      end

      it 'accepts --no-snippets option' do
        config.parse!(%w[--no-snippets])

        expect(config.options[:snippets]).to be false
      end

      it 'sets snippets and source and duration to false with --quiet option' do
        config.parse!(%w[--quiet])

        expect(config.options[:snippets]).to be false
        expect(config.options[:source]).to be false
        expect(config.options[:duration]).to be false
      end

      it 'sets duration to false with --no-duration' do
        config.parse!(%w[--no-duration])

        expect(config.options[:duration]).to be false
      end

      it 'accepts --verbose option' do
        config.parse!(%w[--verbose])

        expect(config.options[:verbose]).to be true
      end

      it 'uses the pretty formatter to stdout when no formatter is defined' do
        config.parse!([])

        expect(config.formats).to eq [['pretty', {}, out]]
      end

      it 'adds the default formatter when no other formatter is defined with --publish' do
        config.parse!(['--publish'])

        expect(config.formats).to eq [
          ['pretty', {}, out],
          ['message', {}, 'https://messages.cucumber.io/api/reports -X GET']
        ]
      end

      it 'does not add the default formatter when a formatter is defined with --publish' do
        config.parse!(['--publish', '--format', 'progress'])

        expect(config.formats).to eq [
          ['progress', {}, out],
          ['message', {}, 'https://messages.cucumber.io/api/reports -X GET']
        ]
      end

      it 'does not add the default formatter with --format message' do
        config.parse!(['--format', 'message'])

        expect(config.formats).to eq [
          ['message', {}, out]
        ]
      end

      it 'accepts --out option' do
        config.parse!(%w[--out jalla.txt])

        expect(config.formats).to eq [['pretty', {}, 'jalla.txt']]
      end

      it 'accepts multiple --out options' do
        config.parse!(%w[--format progress --out file1 --out file2])

        expect(config.formats).to eq [['progress', {}, 'file2']]
      end

      it 'accepts multiple --format options and put the STDOUT one first so progress is seen' do
        config.parse!(%w[--format pretty --out pretty.txt --format progress])

        expect(config.formats).to eq [['progress', {}, out], ['pretty', {}, 'pretty.txt']]
      end

      it 'does not accept multiple --format options when both use implicit STDOUT' do
        expect { config.parse!(%w[--format pretty --format progress]) }.to raise_error('All but one formatter must use --out, only one can print to each stream (or STDOUT)')
      end

      it 'does not accept multiple --format options when both use implicit STDOUT (using profile with no formatters)' do
        given_cucumber_yml_defined_as('default' => ['-q'])
        expect { config.parse!(%w[--format pretty --format progress]) }.to raise_error('All but one formatter must use --out, only one can print to each stream (or STDOUT)')
      end

      it 'accepts same --format options with implicit STDOUT, and keep only one' do
        config.parse!(%w[--format pretty --format pretty])

        expect(config.formats).to eq [['pretty', {}, out]]
      end

      it 'does not accept multiple --out streams pointing to the same place' do
        expected_error = 'All but one formatter must use --out, only one can print to each stream (or STDOUT)'
        expect { config.parse!(%w[--format pretty --out file1 --format progress --out file1]) }.to raise_error(expected_error)
      end

      it 'does not accept multiple --out streams pointing to the same place (one from profile, one from command line)' do
        given_cucumber_yml_defined_as('default' => ['-f', 'progress', '--out', 'file1'])
        expect { config.parse!(%w[--format pretty --out file1]) }.to raise_error('All but one formatter must use --out, only one can print to each stream (or STDOUT)')
      end

      it 'associates --out to previous --format' do
        config.parse!(%w[--format progress --out file1 --format profile --out file2])

        expect(config.formats).to match_array([['progress', {}, 'file1'], ['profile', {}, 'file2']])
      end

      it 'accepts same --format options with same --out streams and keep only one' do
        config.parse!(%w[--format json --out file --format pretty --format json --out file])

        expect(config.formats).to eq [['pretty', {}, out], ['json', {}, 'file']]
      end

      it 'accepts same --format options with different --out streams' do
        config.parse!(%w[--format json --out file1 --format json --out file2])

        expect(config.formats).to match_array([['json', {}, 'file1'], ['json', {}, 'file2']])
      end

      it 'accepts --color option' do
        expect(Cucumber::Term::ANSIColor).to receive(:coloring=).with(true)

        config.parse!(['--color'])
      end

      it 'accepts --no-color option' do
        expect(Cucumber::Term::ANSIColor).to receive(:coloring=).with(false)

        config = Configuration.new(StringIO.new)
        config.parse!(['--no-color'])
      end

      describe '--backtrace' do
        before do
          Cucumber.use_full_backtrace = false
        end

        it 'shows full backtrace when --backtrace is present' do
          Main.new(['--backtrace'])
          begin
            expect('x').to eq 'y'
          rescue RSpec::Expectations::ExpectationNotMetError => e
            expect(e.backtrace[0]).not_to eq "#{__FILE__}:#{__LINE__ - 2}"
          end
        end

        after do
          Cucumber.use_full_backtrace = false
        end
      end

      it 'accepts multiple --name options' do
        config.parse!(['--name', 'User logs in', '--name', 'User signs up'])

        expect(config.options[:name_regexps]).to include(/User logs in/)
        expect(config.options[:name_regexps]).to include(/User signs up/)
      end

      it 'accepts multiple -n options' do
        config.parse!(['-n', 'User logs in', '-n', 'User signs up'])

        expect(config.options[:name_regexps]).to include(/User logs in/)
        expect(config.options[:name_regexps]).to include(/User signs up/)
      end

      it 'should allow specifying environment variables on the command line' do
        config.parse!(['foo=bar'])

        expect(ENV['foo']).to eq 'bar'
        expect(config.paths).not_to include('foo=bar')
      end

      it 'allows specifying environment variables in profiles' do
        given_cucumber_yml_defined_as('selenium' => 'RAILS_ENV=selenium')
        config.parse!(['--profile', 'selenium'])

        expect(ENV['RAILS_ENV']).to eq 'selenium'
        expect(config.paths).not_to include('RAILS_ENV=selenium')
      end

      describe '#tag_expressions' do
        it 'returns an empty expression when no tags are specified' do
          config.parse!([])

          expect(config.tag_expressions).to be_empty
        end

        it 'returns an expression when tags are specified' do
          config.parse!(['--tags', '@foo'])

          expect(config.tag_expressions).not_to be_empty
        end
      end

      describe '#tag_limits' do
        it 'returns an empty hash when no limits are specified' do
          config.parse!([])

          expect(config.tag_limits).to eq({})
        end

        it 'returns a hash of limits when limits are specified' do
          config.parse!(['--tags', '@foo:1'])

          expect(config.tag_limits).to eq('@foo' => 1)
        end
      end

      describe '#dry_run?' do
        it 'returns true when --dry-run was specified on in the arguments' do
          config.parse!(['--dry-run'])

          expect(config.dry_run?).to be true
        end

        it 'returns true when --dry-run was specified in yaml file' do
          given_cucumber_yml_defined_as('default' => '--dry-run')
          config.parse!([])

          expect(config.dry_run?).to be true
        end

        it 'returns false by default' do
          config.parse!([])

          expect(config.dry_run?).to be false
        end
      end

      describe '#snippet_type' do
        it 'returns the snippet type when it was set' do
          config.parse!(['--snippet-type', 'classic'])

          expect(config.snippet_type).to eq :classic
        end

        it 'returns the snippet type when it was set with shorthand option' do
          config.parse!(['-I', 'classic'])

          expect(config.snippet_type).to eq :classic
        end

        it 'returns the default snippet type if it was not set' do
          config.parse!([])

          expect(config.snippet_type).to eq :cucumber_expression
        end
      end

      describe '#retry_attempts' do
        it 'returns the specified number of retries' do
          config.parse!(['--retry=3'])
          expect(config.retry_attempts).to eql 3
        end
      end
    end
  end
end

<MSG> Fix spec

<DFF> @@ -8,13 +8,9 @@ module Cli
       attr_reader :options
     end
 
-    def convert_hash_to_yaml_erb(hash)
-      ["---", *hash.map { |k,v| "#{k}: #{v}" }].join "\n"
-    end
-
     def given_cucumber_yml_defined_as(hash_or_string)
       File.stub!(:exist?).and_return(true)
-      cucumber_yml = hash_or_string.is_a?(Hash) ? convert_hash_to_yaml_erb(hash_or_string) : hash_or_string
+      cucumber_yml = hash_or_string.is_a?(Hash) ? hash_or_string.to_yaml : hash_or_string
       IO.stub!(:read).with('cucumber.yml').and_return(cucumber_yml)
     end
 

{'commit': 'diff --git a/spec/cucumber/cli/configuration_spec.rb b/spec/cucumber/cli/configuration_spec.rb\nindex 710c463a..55b27bb6 100644\n--- a/spec/cucumber/cli/configuration_spec.rb\n+++ b/spec/cucumber/cli/configuration_spec.rb\n@@ -8,13 +8,9 @@ module Cli\n       attr_reader :options\n     end\n \n-    def convert_hash_to_yaml_erb(hash)\n-      ["---", *hash.map { |k,v| "#{k}: #{v}" }].join "\\n"\n-    end\n-\n     def given_cucumber_yml_defined_as(hash_or_string)\n       File.stub!(:exist?).and_return(true)\n-      cucumber_yml = hash_or_string.is_a?(Hash) ? convert_hash_to_yaml_erb(hash_or_string) : hash_or_string\n+      cucumber_yml = hash_or_string.is_a?(Hash) ? hash_or_string.to_yaml : hash_or_string\n       IO.stub!(:read).with(\'cucumber.yml\').and_return(cucumber_yml)\n     end\n \n', 'commit_subject': 'Fix spec', 'repo_name': 'cucumber/cucumber-ruby', 'committer': {'name': 'Matt Wynne', 'email': '1fa2ef4755a9226cb9a0a4840bd89b158ac71391@mattwynne.net', 'time_sec': '1361906475', 'tz_offset': '0', 'date': {'seconds': '1361906475'}}, 'commit_tree': '8dc597c7c505036e57b0be64892f4630441c8fd5', 'commit_message': 'Fix spec\n', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': '@@ -8,13 +8,9 @@ module Cli\n       attr_reader :options\n     end\n \n-    def convert_hash_to_yaml_erb(hash)\n-      ["---", *hash.map { |k,v| "#{k}: #{v}" }].join "\\n"\n-    end\n-\n     def given_cucumber_yml_defined_as(hash_or_string)\n       File.stub!(:exist?).and_return(true)\n-      cucumber_yml = hash_or_string.is_a?(Hash) ? convert_hash_to_yaml_erb(hash_or_string) : hash_or_string\n+      cucumber_yml = hash_or_string.is_a?(Hash) ? hash_or_string.to_yaml : hash_or_string\n       IO.stub!(:read).with(\'cucumber.yml\').and_return(cucumber_yml)\n     end\n \n', 'addition_count': 1, 'deletion_count': 5, 'src_file': 'a/spec/cucumber/cli/configuration_spec.rb', 'tgt_file': 'b/spec/cucumber/cli/configuration_spec.rb', 'file_extension': '.rb', 'before_file': '# frozen_string_literal: true\n\nrequire \'spec_helper\'\nrequire \'yaml\'\n\nmodule Cucumber\n  module Cli\n      attr_reader :options\n    end\n\n    def convert_hash_to_yaml_erb(hash)\n      ["---", *hash.map { |k,v| "#{k}: #{v}" }].join "\\n"\n    end\n\n    def given_cucumber_yml_defined_as(hash_or_string)\n      File.stub!(:exist?).and_return(true)\n      cucumber_yml = hash_or_string.is_a?(Hash) ? convert_hash_to_yaml_erb(hash_or_string) : hash_or_string\n      IO.stub!(:read).with(\'cucumber.yml\').and_return(cucumber_yml)\n    end\n\n\n        allow(IO).to receive(:read).with(\'cucumber.yml\') { cucumber_yml }\n      end\n\n      def given_the_following_files(*files)\n        allow(File).to receive(:directory?) { true }\n        allow(File).to receive(:file?) { true }\n        allow(Dir).to receive(:[]) { files }\n      end\n\n      before(:each) do\n        allow(File).to receive(:exist?) { false } # Meaning, no cucumber.yml exists\n        allow(Kernel).to receive(:exit)\n      end\n\n      def config\n        @config ||= Configuration.new(@out = StringIO.new, @error = StringIO.new).extend(ExposesOptions)\n      end\n\n      def reset_config\n        @config = nil\n      end\n\n      attr_reader :out, :error\n\n      it \'uses the default profile when no profile is defined\' do\n        given_cucumber_yml_defined_as(\'default\' => \'--require some_file\')\n\n        config.parse!(%w[--format progress])\n\n        expect(config.options[:require]).to include(\'some_file\')\n      end\n\n      context \'--profile\' do\n        include RSpec::WorkInProgress\n\n        it \'expands args from profiles in the cucumber.yml file\' do\n          given_cucumber_yml_defined_as(\'bongo\' => \'--require from/yml\')\n\n          config.parse!(%w[--format progress --profile bongo])\n\n          expect(config.options[:formats]).to eq [[\'progress\', {}, out]]\n          expect(config.options[:require]).to eq [\'from/yml\']\n        end\n\n        it \'expands args from the default profile when no flags are provided\' do\n          given_cucumber_yml_defined_as(\'default\' => \'--require from/yml\')\n\n          config.parse!([])\n\n          expect(config.options[:require]).to eq [\'from/yml\']\n        end\n\n        it \'allows --strict to be set by a profile\' do\n          given_cucumber_yml_defined_as(\'bongo\' => \'--strict\')\n\n          config.parse!(%w[--profile bongo])\n\n          expect(config.options[:strict].strict?(:undefined)).to be true\n          expect(config.options[:strict].strict?(:pending)).to be true\n          expect(config.options[:strict].strict?(:flaky)).to be true\n        end\n\n        it \'allows --strict from a profile to be selectively overridden\' do\n          given_cucumber_yml_defined_as(\'bongo\' => \'--strict\')\n\n          config.parse!(%w[--profile bongo --no-strict-flaky])\n\n          expect(config.options[:strict].strict?(:undefined)).to be true\n          expect(config.options[:strict].strict?(:pending)).to be true\n          expect(config.options[:strict].strict?(:flaky)).to be false\n        end\n\n        it \'parses ERB syntax in the cucumber.yml file\' do\n          given_cucumber_yml_defined_as("---\\ndefault: \\"<%=\\"--require some_file\\"%>\\"\\n")\n\n          config.parse!([])\n\n          expect(config.options[:require]).to include(\'some_file\')\n        end\n\n        it \'parses ERB in cucumber.yml that makes uses nested ERB sessions\' do\n          given_cucumber_yml_defined_as(<<ERB_YML)\n<%= ERB.new({\'standard\' => \'--require some_file\'}.to_yaml).result %>\n<%= ERB.new({\'enhanced\' => \'--require other_file\'}.to_yaml).result %>\nERB_YML\n\n          config.parse!(%w[-p standard])\n\n          expect(config.options[:require]).to include(\'some_file\')\n        end\n\n        it \'provides a helpful error message when a specified profile does not exists in cucumber.yml\' do\n          given_cucumber_yml_defined_as(\'default\' => \'--require from/yml\', \'json_report\' => \'--format json\')\n\n          expected_message = <<-END_OF_MESSAGE\nCould not find profile: \'i_do_not_exist\'\n\nDefined profiles in cucumber.yml:\n  * default\n  * json_report\n          END_OF_MESSAGE\n\n          expect { config.parse!(%w[--profile i_do_not_exist]) }.to raise_error(ProfileNotFound, expected_message)\n        end\n\n        it \'allows profiles to be defined in arrays\' do\n          given_cucumber_yml_defined_as(\'foo\' => [\'-f\', \'progress\'])\n\n          config.parse!(%w[--profile foo])\n\n          expect(config.options[:formats]).to eq [[\'progress\', {}, out]]\n        end\n\n        it \'disregards default STDOUT formatter defined in profile when another is passed in (via cmd line)\' do\n          given_cucumber_yml_defined_as(\'foo\' => %w[--format pretty])\n          config.parse!(%w[--format progress --profile foo])\n\n          expect(config.options[:formats]).to eq [[\'progress\', {}, out]]\n        end\n\n        [\'--no-profile\', \'-P\'].each do |flag|\n          context \'when none is specified with #{flag}\' do # rubocop:disable Lint/InterpolationCheck\n            it \'disables profiles\' do\n              given_cucumber_yml_defined_as(\'default\' => \'-v --require file_specified_in_default_profile.rb\')\n\n              config.parse!("#{flag} --require some_file.rb".split(\' \'))\n\n              expect(config.options[:require]).to eq [\'some_file.rb\']\n            end\n\n            it \'notifies the user that the profiles are being disabled\' do\n              given_cucumber_yml_defined_as(\'default\' => \'-v\')\n\n              config.parse!("#{flag} --require some_file.rb".split(\' \'))\n\n              expect(out.string).to match(/Disabling profiles.../)\n            end\n          end\n        end\n\n        it \'issues a helpful error message when a specified profile exists but is nil or blank\' do\n          [nil, \'   \'].each do |bad_input|\n            given_cucumber_yml_defined_as(\'foo\' => bad_input)\n\n            expected_error = /The \'foo\' profile in cucumber.yml was blank.  Please define the command line arguments for the \'foo\' profile in cucumber.yml./\n\n            expect { config.parse!(%w[--profile foo]) }.to raise_error(expected_error)\n          end\n        end\n\n        it \'issues a helpful error message when no YAML file exists and a profile is specified\' do\n          expect(File).to receive(:exist?).with(\'cucumber.yml\') { false }\n\n          expected_error = /cucumber\\.yml was not found/\n\n          expect { config.parse!(%w[--profile i_do_not_exist]) }.to raise_error(expected_error)\n        end\n\n        it \'issues a helpful error message when cucumber.yml is blank or malformed\' do\n          expected_error_message = /cucumber\\.yml was found, but was blank or malformed. Please refer to cucumber\'s documentation on correct profile usage./\n\n          [\'\', \'sfsadfs\', "--- \\n- an\\n- array\\n", \'---dddfd\'].each do |bad_input|\n            given_cucumber_yml_defined_as(bad_input)\n\n            expect { config.parse!([]) }.to raise_error(expected_error_message)\n\n            reset_config\n          end\n        end\n\n        it \'issues a helpful error message when cucumber.yml can not be parsed\' do\n          expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber\'s documentation on correct profile usage./\n\n          given_cucumber_yml_defined_as(\'input that causes an exception in YAML loading\')\n\n          expect(YAML).to receive(:load).and_raise(ArgumentError)\n          expect { config.parse!([]) }.to raise_error(expected_error_message)\n        end\n\n        it \'issues a helpful error message when cucumber.yml can not be parsed by ERB\' do\n          expected_error_message = /cucumber.yml was found, but could not be parsed with ERB.  Please refer to cucumber\'s documentation on correct profile usage./\n          given_cucumber_yml_defined_as(\'<% this_fails %>\')\n\n          expect { config.parse!([]) }.to raise_error(expected_error_message)\n        end\n      end\n\n      it \'accepts --dry-run option\' do\n        config.parse!(%w[--dry-run])\n\n        expect(config.options[:dry_run]).to be true\n      end\n\n      it \'implies --no-duration with --dry-run option\' do\n        config.parse!(%w[--dry-run])\n\n        expect(config.options[:duration]).to be false\n      end\n\n      it \'accepts --no-source option\' do\n        config.parse!(%w[--no-source])\n\n        expect(config.options[:source]).to be false\n      end\n\n      it \'accepts --no-snippets option\' do\n        config.parse!(%w[--no-snippets])\n\n        expect(config.options[:snippets]).to be false\n      end\n\n      it \'sets snippets and source and duration to false with --quiet option\' do\n        config.parse!(%w[--quiet])\n\n        expect(config.options[:snippets]).to be false\n        expect(config.options[:source]).to be false\n        expect(config.options[:duration]).to be false\n      end\n\n      it \'sets duration to false with --no-duration\' do\n        config.parse!(%w[--no-duration])\n\n        expect(config.options[:duration]).to be false\n      end\n\n      it \'accepts --verbose option\' do\n        config.parse!(%w[--verbose])\n\n        expect(config.options[:verbose]).to be true\n      end\n\n      it \'uses the pretty formatter to stdout when no formatter is defined\' do\n        config.parse!([])\n\n        expect(config.formats).to eq [[\'pretty\', {}, out]]\n      end\n\n      it \'adds the default formatter when no other formatter is defined with --publish\' do\n        config.parse!([\'--publish\'])\n\n        expect(config.formats).to eq [\n          [\'pretty\', {}, out],\n          [\'message\', {}, \'https://messages.cucumber.io/api/reports -X GET\']\n        ]\n      end\n\n      it \'does not add the default formatter when a formatter is defined with --publish\' do\n        config.parse!([\'--publish\', \'--format\', \'progress\'])\n\n        expect(config.formats).to eq [\n          [\'progress\', {}, out],\n          [\'message\', {}, \'https://messages.cucumber.io/api/reports -X GET\']\n        ]\n      end\n\n      it \'does not add the default formatter with --format message\' do\n        config.parse!([\'--format\', \'message\'])\n\n        expect(config.formats).to eq [\n          [\'message\', {}, out]\n        ]\n      end\n\n      it \'accepts --out option\' do\n        config.parse!(%w[--out jalla.txt])\n\n        expect(config.formats).to eq [[\'pretty\', {}, \'jalla.txt\']]\n      end\n\n      it \'accepts multiple --out options\' do\n        config.parse!(%w[--format progress --out file1 --out file2])\n\n        expect(config.formats).to eq [[\'progress\', {}, \'file2\']]\n      end\n\n      it \'accepts multiple --format options and put the STDOUT one first so progress is seen\' do\n        config.parse!(%w[--format pretty --out pretty.txt --format progress])\n\n        expect(config.formats).to eq [[\'progress\', {}, out], [\'pretty\', {}, \'pretty.txt\']]\n      end\n\n      it \'does not accept multiple --format options when both use implicit STDOUT\' do\n        expect { config.parse!(%w[--format pretty --format progress]) }.to raise_error(\'All but one formatter must use --out, only one can print to each stream (or STDOUT)\')\n      end\n\n      it \'does not accept multiple --format options when both use implicit STDOUT (using profile with no formatters)\' do\n        given_cucumber_yml_defined_as(\'default\' => [\'-q\'])\n        expect { config.parse!(%w[--format pretty --format progress]) }.to raise_error(\'All but one formatter must use --out, only one can print to each stream (or STDOUT)\')\n      end\n\n      it \'accepts same --format options with implicit STDOUT, and keep only one\' do\n        config.parse!(%w[--format pretty --format pretty])\n\n        expect(config.formats).to eq [[\'pretty\', {}, out]]\n      end\n\n      it \'does not accept multiple --out streams pointing to the same place\' do\n        expected_error = \'All but one formatter must use --out, only one can print to each stream (or STDOUT)\'\n        expect { config.parse!(%w[--format pretty --out file1 --format progress --out file1]) }.to raise_error(expected_error)\n      end\n\n      it \'does not accept multiple --out streams pointing to the same place (one from profile, one from command line)\' do\n        given_cucumber_yml_defined_as(\'default\' => [\'-f\', \'progress\', \'--out\', \'file1\'])\n        expect { config.parse!(%w[--format pretty --out file1]) }.to raise_error(\'All but one formatter must use --out, only one can print to each stream (or STDOUT)\')\n      end\n\n      it \'associates --out to previous --format\' do\n        config.parse!(%w[--format progress --out file1 --format profile --out file2])\n\n        expect(config.formats).to match_array([[\'progress\', {}, \'file1\'], [\'profile\', {}, \'file2\']])\n      end\n\n      it \'accepts same --format options with same --out streams and keep only one\' do\n        config.parse!(%w[--format json --out file --format pretty --format json --out file])\n\n        expect(config.formats).to eq [[\'pretty\', {}, out], [\'json\', {}, \'file\']]\n      end\n\n      it \'accepts same --format options with different --out streams\' do\n        config.parse!(%w[--format json --out file1 --format json --out file2])\n\n        expect(config.formats).to match_array([[\'json\', {}, \'file1\'], [\'json\', {}, \'file2\']])\n      end\n\n      it \'accepts --color option\' do\n        expect(Cucumber::Term::ANSIColor).to receive(:coloring=).with(true)\n\n        config.parse!([\'--color\'])\n      end\n\n      it \'accepts --no-color option\' do\n        expect(Cucumber::Term::ANSIColor).to receive(:coloring=).with(false)\n\n        config = Configuration.new(StringIO.new)\n        config.parse!([\'--no-color\'])\n      end\n\n      describe \'--backtrace\' do\n        before do\n          Cucumber.use_full_backtrace = false\n        end\n\n        it \'shows full backtrace when --backtrace is present\' do\n          Main.new([\'--backtrace\'])\n          begin\n            expect(\'x\').to eq \'y\'\n          rescue RSpec::Expectations::ExpectationNotMetError => e\n            expect(e.backtrace[0]).not_to eq "#{__FILE__}:#{__LINE__ - 2}"\n          end\n        end\n\n        after do\n          Cucumber.use_full_backtrace = false\n        end\n      end\n\n      it \'accepts multiple --name options\' do\n        config.parse!([\'--name\', \'User logs in\', \'--name\', \'User signs up\'])\n\n        expect(config.options[:name_regexps]).to include(/User logs in/)\n        expect(config.options[:name_regexps]).to include(/User signs up/)\n      end\n\n      it \'accepts multiple -n options\' do\n        config.parse!([\'-n\', \'User logs in\', \'-n\', \'User signs up\'])\n\n        expect(config.options[:name_regexps]).to include(/User logs in/)\n        expect(config.options[:name_regexps]).to include(/User signs up/)\n      end\n\n      it \'should allow specifying environment variables on the command line\' do\n        config.parse!([\'foo=bar\'])\n\n        expect(ENV[\'foo\']).to eq \'bar\'\n        expect(config.paths).not_to include(\'foo=bar\')\n      end\n\n      it \'allows specifying environment variables in profiles\' do\n        given_cucumber_yml_defined_as(\'selenium\' => \'RAILS_ENV=selenium\')\n        config.parse!([\'--profile\', \'selenium\'])\n\n        expect(ENV[\'RAILS_ENV\']).to eq \'selenium\'\n        expect(config.paths).not_to include(\'RAILS_ENV=selenium\')\n      end\n\n      describe \'#tag_expressions\' do\n        it \'returns an empty expression when no tags are specified\' do\n          config.parse!([])\n\n          expect(config.tag_expressions).to be_empty\n        end\n\n        it \'returns an expression when tags are specified\' do\n          config.parse!([\'--tags\', \'@foo\'])\n\n          expect(config.tag_expressions).not_to be_empty\n        end\n      end\n\n      describe \'#tag_limits\' do\n        it \'returns an empty hash when no limits are specified\' do\n          config.parse!([])\n\n          expect(config.tag_limits).to eq({})\n        end\n\n        it \'returns a hash of limits when limits are specified\' do\n          config.parse!([\'--tags\', \'@foo:1\'])\n\n          expect(config.tag_limits).to eq(\'@foo\' => 1)\n        end\n      end\n\n      describe \'#dry_run?\' do\n        it \'returns true when --dry-run was specified on in the arguments\' do\n          config.parse!([\'--dry-run\'])\n\n          expect(config.dry_run?).to be true\n        end\n\n        it \'returns true when --dry-run was specified in yaml file\' do\n          given_cucumber_yml_defined_as(\'default\' => \'--dry-run\')\n          config.parse!([])\n\n          expect(config.dry_run?).to be true\n        end\n\n        it \'returns false by default\' do\n          config.parse!([])\n\n          expect(config.dry_run?).to be false\n        end\n      end\n\n      describe \'#snippet_type\' do\n        it \'returns the snippet type when it was set\' do\n          config.parse!([\'--snippet-type\', \'classic\'])\n\n          expect(config.snippet_type).to eq :classic\n        end\n\n        it \'returns the snippet type when it was set with shorthand option\' do\n          config.parse!([\'-I\', \'classic\'])\n\n          expect(config.snippet_type).to eq :classic\n        end\n\n        it \'returns the default snippet type if it was not set\' do\n          config.parse!([])\n\n          expect(config.snippet_type).to eq :cucumber_expression\n        end\n      end\n\n      describe \'#retry_attempts\' do\n        it \'returns the specified number of retries\' do\n          config.parse!([\'--retry=3\'])\n          expect(config.retry_attempts).to eql 3\n        end\n      end\n    end\n  end\nend\n', 'message': 'Fix spec\n', 'author_name': 'Matt Wynne', 'lang': 'rb'}