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 13 |
# File 'lib/guard/motion/runner.rb', line 6 def initialize( = {}) @options = { :bundler => true, :binstubs => false, :env => {}, :notification => true, }.merge() end |
Instance Method Details
#all_spec_paths ⇒ Object
89 90 91 92 93 |
# File 'lib/guard/motion/runner.rb', line 89 def all_spec_paths @options[:spec_paths].map { |spec_path| Dir.glob("#{spec_path}/**/*_spec.rb") }.flatten end |
#binstubs ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/guard/motion/runner.rb', line 119 def binstubs if @options[:binstubs] == true "bin" else @options[:binstubs] end end |
#binstubs? ⇒ Boolean
111 112 113 114 115 116 117 |
# File 'lib/guard/motion/runner.rb', line 111 def binstubs? if @binstubs.nil? @binstubs = !!@options[:binstubs] else @binstubs end end |
#bundle_exec? ⇒ Boolean
127 128 129 |
# File 'lib/guard/motion/runner.rb', line 127 def bundle_exec? bundler? && !binstubs? end |
#bundler? ⇒ Boolean
103 104 105 106 107 108 109 |
# File 'lib/guard/motion/runner.rb', line 103 def bundler? if @bundler.nil? @bundler = bundler_allowed? && @options[:bundler] else @bundler end end |
#bundler_allowed? ⇒ Boolean
95 96 97 98 99 100 101 |
# File 'lib/guard/motion/runner.rb', line 95 def bundler_allowed? if @bundler_allowed.nil? @bundler_allowed = File.exist?("#{Dir.pwd}/Gemfile") else @bundler_allowed end end |
#notify(output) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/guard/motion/runner.rb', line 34 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(, :image => type, :title => 'RubyMotion Spec Results', :priority => 2) end |
#rake_command(paths) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/guard/motion/runner.rb', line 56 def rake_command(paths) cmd_parts = [] @options[:env].each do |var, value| cmd_parts << "#{var}=#{value}" end 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
50 51 52 53 54 |
# File 'lib/guard/motion/runner.rb', line 50 def rake_executable @rake_executable ||= begin binstubs? ? "#{binstubs}/rake" : 'rake' end end |
#run(paths = nil, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/guard/motion/runner.rb', line 15 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/guard/motion/runner.rb', line 69 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 |