Module: Spectator::Specs
- Included in:
- Runner
- Defined in:
- lib/spectator/specs.rb
Instance Method Summary collapse
- #default_rails_matcher(path, specs) ⇒ Object
- #failed_message ⇒ Object
- #full_rspec_command ⇒ Object
- #match_specs(path, specs) ⇒ Object
- #notify(message) ⇒ Object
- #osx? ⇒ Boolean
- #rspec(options) ⇒ Object
- #rspec_all ⇒ Object
- #rspec_command ⇒ Object
- #rspec_files(*files) ⇒ Object
- #specs_for_file(path) ⇒ Object
- #success_message ⇒ Object
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_message ⇒ Object
36 37 38 39 |
# File 'lib/spectator/specs.rb', line 36 def @failed_message ||= osx? ? '💔 FAILED'.freeze : '♠♠FAILED >:( ♠♠'.freeze end |
#full_rspec_command ⇒ Object
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 Thread.new do begin require 'notify' Notify.notify 'RSpec Result:', rescue nil end end end |
#osx? ⇒ 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 unless .empty? success = run("#{full_rspec_command} #{}") notify( success ? : ) end end |
#rspec_all ⇒ Object
45 46 47 |
# File 'lib/spectator/specs.rb', line 45 def rspec_all rspec ENV['SPEC_DIR_GLOB'] || 'spec' end |
#rspec_command ⇒ Object
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_message ⇒ Object
31 32 33 34 |
# File 'lib/spectator/specs.rb', line 31 def @success_message ||= osx? ? '🎉 SUCCESS'.freeze : '♥♥ SUCCESS :) ♥♥'.freeze end |