moduleRspecmoduleCoreclassConfiguration# Regex patterns to scrub backtrace withattr_reader:backtrace_clean_patterns# All of the defined before/after blocks setup in the configurationattr_reader:before_and_afters# Allows you to control what examples are ran by filtering attr_reader:filterattr_reader:exclusion_filter# Modules that will be included or extended based on given filtersattr_reader:include_or_extend_modules# Run all examples if the run is filtered, and no examples were found. Normally this is what you want -# when using focused examples for instance. Defaults to trueattr_accessor:run_all_when_everything_filtered# Enable verbose interal logging of the framework - defaults to falseattr_accessor:traceattr_reader:optionsdefinitialize@run_all_when_everything_filtered=true@before_and_afters={:before=>{:each=>[],:all=>[],:suite=>[]},:after=>{:each=>[],:all=>[],:suite=>[]}}@include_or_extend_modules=[]@filter,@exclusion_filter=nil,nil@options=default_options@backtrace_clean_patterns=[]enddefdefault_options{:color_enabled=>false,:mock_framework=>nil,:profile_examples=>false,:files_to_run=>[],:filename_pattern=>'**/*_spec.rb',:formatter_class=>Rspec::Core::Formatters::ProgressFormatter,:backtrace_clean_patterns=>[/\/lib\/ruby\//,/bin\/rcov:/,/vendor\/rails/,/bin\/rspec/,/bin\/spec/,/lib\/rspec\/core/,/lib\/rspec\/expectations/,/lib\/rspec\/mocks/]}enddefcleaned_from_backtrace?(line)options[:backtrace_clean_patterns].any?{|regex|line=~regex}enddefmock_framework=(use_me_to_mock)options[:mock_framework]=use_me_to_mockmock_framework_class=caseuse_me_to_mock.to_swhen/rspec/irequire'rspec/core/mocking/with_rspec'Rspec::Core::Mocking::WithRspecwhen/mocha/irequire'rspec/core/mocking/with_mocha'Rspec::Core::Mocking::WithMochawhen/rr/irequire'rspec/core/mocking/with_rr'Rspec::Core::Mocking::WithRRwhen/flexmock/irequire'rspec/core/mocking/with_flexmock'Rspec::Core::Mocking::WithFlexmockelserequire'rspec/core/mocking/with_absolutely_nothing'Rspec::Core::Mocking::WithAbsolutelyNothingendoptions[:mock_framework_class]=mock_framework_classRspec::Core::ExampleGroup.send(:include,mock_framework_class)enddefmock_frameworkoptions[:mock_framework]enddeffilename_patternoptions[:filename_pattern]enddeffilename_pattern=(new_pattern)options[:filename_pattern]=new_patternenddefcolor_enabled=(on_or_off)options[:color_enabled]=on_or_offenddefcolor_enabled?options[:color_enabled]end# Enable profiling of example run - defaults to falsedefprofile_examplesoptions[:profile_examples]enddefprofile_examples=(profile)options[:profile_examples]=on_or_offenddefformatter_classoptions[:formatter_class]enddefformatter=(formatter_to_use)formatter_class=caseformatter_to_use.to_swhen/doc/,'s'Rspec::Core::Formatters::DocumentationFormatterwhen'progress'Rspec::Core::Formatters::ProgressFormatterelseraiseArgumentError,"Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?."endoptions[:formatter_class]=formatter_classenddefformatter@formatter||=formatter_class.newenddeffiles_to_runoptions[:files_to_run]enddeffiles_to_run=(*files)files.flatten!result=[]files.eachdo|file|ifFile.directory?(file)filename_pattern.split(",").eachdo|pattern|result+=Dir[File.expand_path("#{file}/#{pattern.strip}")]endelsifFile.file?(file)result<<fileelseraise"File or directory not found: #{file}"endendoptions[:files_to_run]=resultend# E.g. alias_example_to :crazy_slow, :speed => 'crazy_slow' defines# crazy_slow as an example variant that has the crazy_slow speed optiondefalias_example_to(new_name,extra_options={})Rspec::Core::ExampleGroup.alias_example_to(new_name,extra_options)enddefautorun!Rspec::Core::Runner.autorunenddeffilter_run(options={})@filter=optionsenddefrun_all_when_everything_filtered?@run_all_when_everything_filteredend# Where does output go? For now $stdoutdefoutput$stdoutenddefputs(msg='')output.puts(msg)enddefparse_command_line_args(args)@command_line_options=Rspec::Core::CommandLineOptions.parse(args)enddefinclude(mod,options={})include_or_extend_modules<<[:include,mod,options]enddefextend(mod,options={})include_or_extend_modules<<[:extend,mod,options]enddeffind_modules(group)include_or_extend_modules.selectdo|include_or_extend,mod,options|options.all?do|filter_on,filter|Rspec::Core.world.apply_condition(filter_on,filter,group.metadata)endendenddefbefore(each_or_all=:each,options={},&block)before_and_afters[:before][each_or_all]<<[options,block]enddefafter(each_or_all=:each,options={},&block)before_and_afters[:after][each_or_all]<<[options,block]enddeffind_before_or_after(desired_before_or_after,desired_each_or_all,group)before_and_afters[desired_before_or_after][desired_each_or_all].selectdo|options,block|options.all?do|filter_on,filter|Rspec::Core.world.apply_condition(filter_on,filter,group.metadata)endend.map{|options,block|block}endendendend