# BEGIN generated by rake update, do not modify# https://raw.githubusercontent.com/grosser/testrbl/master/lib/testrbl.rbmoduleMaxitestmoduleTestrblPATTERNS=[/^(\s+)(should|test|it)(\s+|\s*\(\s*)['"](.*)['"](\s*\))?\s+do\s*(?:#.*)?$/,/^(\s+)(context|describe)(\s+|\s*\(\s*)['"]?(.*?)['"]?(\s*\))?\s+do\s*(?:#.*)?$/,/^(\s+)def(\s+)(test_)([a-z_\d]+)\s*(?:#.*)?$/]OPTION_WITH_ARGUMENT=["-I","-r","-n","--name","-e","--exclude","-s","--seed"]INTERPOLATION=/\\\#\\\{.*?\\\}/class<<selfdefrun_from_cli(argv)files,options=partition_argv(argv)files.concat(changed_files)ifoptions.delete("--changed")files=["test"]iffiles.empty?files=files.map{|f|localize(f)}load_options,options=partition_options(options)iffiles.size==1andfiles.first=~/^(\S+):(\d+)$/file=$1line=$2run(ruby+load_options+line_pattern_option(file,line)+options)elseiffiles.size==1andFile.file?(files.first)run(ruby+load_options+files+options)elsifoptions.none?{|arg|arg=~/^-n/}seed=ifseed=options.index("--seed")["--"]+options.slice!(seed,2)else[]endfiles=files.map{|f|File.directory?(f)?all_test_files_in(f):f}.flattenrun(ruby+load_options+files.map{|f|"-r#{f}"}+options+["-e",""]+seed)else# pass though# no bundle exec: projects with mini and unit-test do not run well via bundle exec testrbrun["testrb"]+argvendendend# overwritten by maxitest to just return linedefline_pattern_option(file,line)[file,"-n","/#{pattern_from_file(File.readlines(file),line)}/"]end# usable via external tools like zeusdefpattern_from_file(lines,line)possible_lines=lines[0..(line.to_i-1)].reversefound=possible_lines.map{|line|test_pattern_from_line(line)||block_start_from_line(line)}.compact# pattern and the groups it is nested under (like describe - describe - it)last_spaces=" "*100patterns=found.selectdo|spaces,name|last_spaces=spacesifspaces.size<last_spaces.sizeend.map(&:last).compactreturnfilter_duplicate_final(patterns).reverse.join(".*")iffound.size>0raise"no test found before line #{line}"end# only keep 1 pattern that stops matching via $deffilter_duplicate_final(patterns)found_final=0patterns.reject{|p|p.end_with?("$")and(found_final+=1)>1}endprivatedefall_test_files_in(folder)Dir[File.join(folder,"{**/,}*_{test,spec}.rb")].uniqenddefpartition_options(options)next_is_before=falseoptions.partitiondo|option|ifnext_is_beforenext_is_before=falsetrueelseifoption=~/^-(r|I)/next_is_before=(option.size==2)trueelsefalseendendendend# fix 1.9 not being able to load local filesdeflocalize(file)file=~/^[-a-z\d_]/?"./#{file}":fileenddefpartition_argv(argv)next_is_option=falseargv.partitiondo|arg|ifnext_is_optionnext_is_option=falseelseifarg=~/^-.$/orarg=~/^--/# single letter option followed by argument like -I test or long options like --verbosenext_is_option=trueifOPTION_WITH_ARGUMENT.include?(arg)falseelsifarg=~/^-/# multi letter option like -Itestfalseelsetrueendendendenddefchanged_fileschanged_files=sh("git status -s").split("\n").map{|l|l.strip.split(/\s+/,2)[1]}ifchanged_files.empty?# user wants to test last commit and not current diffchanged_files=sh("git show --name-only").split("\n\n").last.split("\n")end# we only want test files that were added or changed (not deleted)changed_files.select{|f|f=~/_(test|spec)\.rb$/&&File.exist?(f)}enddefsh(command)result=`#{command}`raise"Failed: #{command} -> #{result}"unless$?.success?resultenddefrubyifFile.file?("Gemfile")["ruby","-rbundler/setup"]# faster then bundle exec rubyelse["ruby"]endenddefrun(command)putscommand.join(" ")STDOUT.flush# if exec fails horribly we at least see some outputKernel.exec*commandenddefblock_start_from_line(line)ifline=~/^(\s*).* do( \|.*\|)?$/[$1,nil]endenddeftest_pattern_from_line(line)PATTERNS.eachdo|r|nextunlessline=~rwhitespace,method,test_name=$1,$2,$4return[whitespace,test_pattern_from_match(method,test_name)]endnilenddeftest_pattern_from_match(method,test_name)regex=Regexp.escape(test_name).gsub("\\ "," ").gsub(INTERPOLATION,".*")regex=ifmethod=="test"# test "xxx -_ yyy"# test-unit: "test: xxx -_ yyy"# activesupport: "test_xxx_-__yyy""^test(: |_)#{regex.gsub(" ",".")}$"elsifmethod=="describe"||(method=="context"&&!via_shoulda?)"#{regex}(::)?"elsifmethod=="should"&&via_shoulda?optional_test_name="(?:\(.*\))?""#{method}#{regex}\.#{optional_test_name}$"elsif["it","should"].include?(method)# minitest aliases for shoulda"#test_\\d+_#{regex}$"elseregexendregex.gsub("'",".")enddefvia_shoulda?return@via_shouldaifdefined?(@via_shoulda)@via_shoulda=!File.exist?("Gemfile.lock")||File.read("Gemfile.lock").include?(" shoulda-context ")endendendend# END generated by rake update, do not modify