Module: SpecWatchr::Specs

Included in:
SpecWatchr
Defined in:
lib/rspec-rails-watchr.rb

Instance Method Summary collapse

Instance Method Details

#default_rails_matcher(path, specs) ⇒ Object



65
66
67
# File 'lib/rspec-rails-watchr.rb', line 65

def default_rails_matcher path, specs
  specs.grep(/\b#{path}((_spec)?\.rb)?$/)
end

#match_specs(path, specs) ⇒ Object



69
70
71
72
# File 'lib/rspec-rails-watchr.rb', line 69

def match_specs path, specs
  matched_specs = @custom_matcher.call(path, specs) if @custom_matcher
  matched_specs = default_rails_matcher(path, specs) if matched_specs.nil?
end

#notify(message) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/rspec-rails-watchr.rb', line 28

def notify message
  Thread.new do
    begin
      require 'notify'
      Notify.notify 'RSpec Result:', message
    rescue
      nil
    end
  end
end

#rspec(options) ⇒ Object



43
44
45
46
47
48
# File 'lib/rspec-rails-watchr.rb', line 43

def rspec options
  unless options.empty?
    success = run("bundle exec #{rspec_command} #{options}")
    notify( success ? '♥♥ SUCCESS :) ♥♥' : '♠♠ FAILED >:( ♠♠' )
  end
end

#rspec_allObject



50
51
52
# File 'lib/rspec-rails-watchr.rb', line 50

def rspec_all
  rspec 'spec'
end

#rspec_commandObject



39
40
41
# File 'lib/rspec-rails-watchr.rb', line 39

def rspec_command
  @rspec_command ||= File.exist?('./.rspec') ? 'rspec' : 'spec'
end

#rspec_files(*files) ⇒ Object



54
55
56
# File 'lib/rspec-rails-watchr.rb', line 54

def rspec_files *files
  rspec files.join(' ')
end

#specs_for(path) ⇒ Object



58
59
60
61
62
63
# File 'lib/rspec-rails-watchr.rb', line 58

def specs_for(path)
  print "--- Searching specs for #{path.inspect}...".yellow
  specs = match_specs path, Dir['spec/**/*_spec.rb']
  puts specs.empty? ? ' nothing found.'.red : " #{specs.size} matched.".green
  specs
end