Sha256: 748ef003aca9fa485d4a5a997bb9e19c457a4f5a5626225dfd0e2ec9eeb6e523

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby

require 'fssm'

def display value
end

if ARGV.include? '--verbose'
  def display value
    puts value
  end
end

def run_all_specs
  specs = Dir['**/*_spec.rb*'].select { |f| File.file?(f) }.map do |x|
    File.expand_path(x)
  end

  run_these_specs specs
end

def run_these_specs specs
  requires = specs.map { |x| "require '#{x}'" }.join("\n")
  display "Specs to run: #{specs.inspect}"
  puts `ruby -e "#{requires}"`
end


def add_it(file, files)
  return if file.index('.git') == 0
  display "Adding: #{file}"
  files << file
end

def run_it(file, files)
  filename = file.downcase.split('/')[-1].gsub('_spec', '')
  display "File to run is: #{file}"
  display "Filename: #{filename}"
  matches = files.select { |x| x.gsub('_spec.rb', '.rb').include?(filename) && x != file }
  matches << file
  specs = matches.select! { |x| x.include?('_spec') }.map { |x| File.expand_path x }
  display "Matches: #{specs.inspect}"
  run_these_specs specs
end

def delete_it(file, files)
  return if file.index('.git') == 0
  display "Deleting: #{file}"
  files.delete(file)
end

if ARGV.include? '--watch'
  files = Dir['**/*']
  location = File.expand_path(File.dirname(Dir['**/*_spec.rb*'].first))
  FSSM.monitor(location, '**/*') do
    update {|base, relative| run_it relative, files }
    delete {|base, relative| delete_it relative, files }
    create {|base, relative| add_it relative, files }
  end
else
  run_all_specs
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
starting_blocks-0.0.4 bin/sb