Class: Guard::Motion::Runner
- Inherits:
-
Object
- Object
- Guard::Motion::Runner
- Defined in:
- lib/guard/motion/runner.rb
Instance Method Summary collapse
- #all_spec_paths ⇒ Object
- #binstubs ⇒ Object
- #binstubs? ⇒ Boolean
- #bundle_exec? ⇒ Boolean
- #bundler? ⇒ Boolean
- #bundler_allowed? ⇒ Boolean
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #notify(output) ⇒ Object
- #rake_command(paths) ⇒ Object
- #rake_executable ⇒ Object
- #run(paths = nil, options = {}) ⇒ Object
- #run_via_pty(command) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 10 11 12 |
# File 'lib/guard/motion/runner.rb', line 6 def initialize( = {}) @options = { :bundler => true, :binstubs => false, :notification => true, }.merge() end |
Instance Method Details
#all_spec_paths ⇒ Object
83 84 85 86 87 |
# File 'lib/guard/motion/runner.rb', line 83 def all_spec_paths @options[:spec_paths].map { |spec_path| Dir.glob("#{spec_path}/**/*_spec.rb") }.flatten end |
#binstubs ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/guard/motion/runner.rb', line 113 def binstubs if @options[:binstubs] == true "bin" else @options[:binstubs] end end |
#binstubs? ⇒ Boolean
105 106 107 108 109 110 111 |
# File 'lib/guard/motion/runner.rb', line 105 def binstubs? if @binstubs.nil? @binstubs = !!@options[:binstubs] else @binstubs end end |
#bundle_exec? ⇒ Boolean
121 122 123 |
# File 'lib/guard/motion/runner.rb', line 121 def bundle_exec? bundler? && !binstubs? end |
#bundler? ⇒ Boolean
97 98 99 100 101 102 103 |
# File 'lib/guard/motion/runner.rb', line 97 def bundler? if @bundler.nil? @bundler = bundler_allowed? && @options[:bundler] else @bundler end end |
#bundler_allowed? ⇒ Boolean
89 90 91 92 93 94 95 |
# File 'lib/guard/motion/runner.rb', line 89 def bundler_allowed? if @bundler_allowed.nil? @bundler_allowed = File.exist?("#{Dir.pwd}/Gemfile") else @bundler_allowed end end |
#notify(output) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/guard/motion/runner.rb', line 33 def notify(output) = "Failed" type = :failed parser = ResultsParser.new if parser.parse(output) = "#{parser.specs} specs, #{parser.failures} failures, #{parser.errors} errors" end if parser.success? type = :success end Notifier.notify(, :type => type, :image => type, :title => 'RubyMotion Spec Results', :priority => 2) end |
#rake_command(paths) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/guard/motion/runner.rb', line 55 def rake_command(paths) cmd_parts = [] cmd_parts << "bundle exec" if bundle_exec? cmd_parts << rake_executable cmd_parts << "spec:specific[\"#{paths.join(';')}\"]" cmd_parts.compact.join(' ') end |
#rake_executable ⇒ Object
49 50 51 52 53 |
# File 'lib/guard/motion/runner.rb', line 49 def rake_executable @rake_executable ||= begin binstubs? ? "#{binstubs}/rake" : 'rake' end end |
#run(paths = nil, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/guard/motion/runner.rb', line 14 def run(paths = nil, = {}) if paths.nil? paths = all_spec_paths = [:message] || "Running all specs" else = [:message] || "Running: #{paths.join(' ')}" end return false if paths.empty? UI.info(, :reset => true) output = run_via_pty rake_command(paths) if @options[:notification] notify(output) end end |
#run_via_pty(command) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/guard/motion/runner.rb', line 63 def run_via_pty(command) output = "" PTY.spawn(command) do |r, w, pid| begin loop do chunk = r.readpartial(1024) output += chunk print chunk end rescue EOFError end Process.wait(pid) end output end |