Class: Providence::RspecWatchr

Inherits:
BaseWatchr show all
Defined in:
lib/providence/rspec_watchr.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseWatchr

alert_message, fail_message, pass_message, pending_message, run, run_command

Class Method Details

.commandObject



32
33
34
35
36
37
38
# File 'lib/providence/rspec_watchr.rb', line 32

def command
  if Gem.searcher.find('rspec').nil?
    "env RSPEC_COLOR=true spec --drb --colour --format nested"
  else
    "rspec --tty --drb --colour --format nested"
  end
end

.parse_test_status(status) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/providence/rspec_watchr.rb', line 12

def parse_test_status(status)
  status = status.join('').gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/, '')

  if status.match(/\s0\s(errors|failures)/)
    status.match(/pending/) ? :pending : :pass
  elsif status.match(/(error|failure)/)
    :fail
  else
    :alert
  end
end


28
29
30
# File 'lib/providence/rspec_watchr.rb', line 28

def related(path)
  Dir['spec/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_spec.rb/ }
end

.run_allObject



24
25
26
# File 'lib/providence/rspec_watchr.rb', line 24

def run_all
  run 'spec'
end

Instance Method Details

#watch(ec) ⇒ Object

order matters here, top is last to match, bottom is first



4
5
6
7
8
9
# File 'lib/providence/rspec_watchr.rb', line 4

def watch(ec)
  ec.watch('app/.*\.rb')        { |m| Providence::RspecWatchr.related(m[0]).map {|tf| Providence::RspecWatchr.run tf } }
  ec.watch('lib/.*\.rb')        { |m| Providence::RspecWatchr.related(m[0]).map {|tf| Providence::RspecWatchr.run tf } }
  ec.watch('spec/support/.*')   { Providence::RspecWatchr.run_all }
  ec.watch('spec/.*_spec\.rb')  { |m| Providence::RspecWatchr.run m[0] }
end