Module: Spectator::Specs

Included in:
Runner
Defined in:
lib/spectator/specs.rb

Instance Method Summary collapse

Instance Method Details

#default_rails_matcher(path, specs) ⇒ Object



60
61
62
# File 'lib/spectator/specs.rb', line 60

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

#failed_messageObject



36
37
38
39
# File 'lib/spectator/specs.rb', line 36

def failed_message
  @failed_message ||= osx? ? '💔 FAILED'.freeze :
                             'â™ â™  FAILED >:( â™ â™ '.freeze
end

#full_rspec_commandObject



20
21
22
# File 'lib/spectator/specs.rb', line 20

def full_rspec_command
  @full_rspec_command ||= ENV['RSPEC_COMMAND'] || "bundle exec #{rspec_command}"
end

#match_specs(path, specs) ⇒ Object



64
65
66
67
# File 'lib/spectator/specs.rb', line 64

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



5
6
7
8
9
10
11
12
13
14
# File 'lib/spectator/specs.rb', line 5

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

#osx?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/spectator/specs.rb', line 41

def osx?
  @osx ||= RUBY_PLATFORM.include? 'darwin'
end

#rspec(options) ⇒ Object



24
25
26
27
28
29
# File 'lib/spectator/specs.rb', line 24

def rspec options
  unless options.empty?
    success = run("#{full_rspec_command} #{options}")
    notify( success ? success_message : failed_message )
  end
end

#rspec_allObject



45
46
47
# File 'lib/spectator/specs.rb', line 45

def rspec_all
  rspec ENV['SPEC_DIR_GLOB'] || 'spec'
end

#rspec_commandObject



16
17
18
# File 'lib/spectator/specs.rb', line 16

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

#rspec_files(*files) ⇒ Object



49
50
51
# File 'lib/spectator/specs.rb', line 49

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

#specs_for_file(path) ⇒ Object



53
54
55
56
57
58
# File 'lib/spectator/specs.rb', line 53

def specs_for_file(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

#success_messageObject



31
32
33
34
# File 'lib/spectator/specs.rb', line 31

def success_message
  @success_message ||= osx? ? '🎉 SUCCESS'.freeze :
                              '♥♥ SUCCESS :) ♥♥'.freeze
end