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.
- #rake_command(paths) ⇒ Object
- #rake_executable ⇒ Object
- #run(paths = nil, options = {}) ⇒ Object
- #run_via_shell(command) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 11 |
# File 'lib/guard/motion/runner.rb', line 5 def initialize( = {}) @options = { :bundler => true, :binstubs => false, :notification => true, }.merge() end |
Instance Method Details
#all_spec_paths ⇒ Object
52 53 54 55 56 |
# File 'lib/guard/motion/runner.rb', line 52 def all_spec_paths @options[:spec_paths].map { |spec_path| Dir.glob("#{spec_path}/**/*_spec.rb") }.flatten end |
#binstubs ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/guard/motion/runner.rb', line 82 def binstubs if @options[:binstubs] == true "bin" else @options[:binstubs] end end |
#binstubs? ⇒ Boolean
74 75 76 77 78 79 80 |
# File 'lib/guard/motion/runner.rb', line 74 def binstubs? if @binstubs.nil? @binstubs = !!@options[:binstubs] else @binstubs end end |
#bundle_exec? ⇒ Boolean
90 91 92 |
# File 'lib/guard/motion/runner.rb', line 90 def bundle_exec? bundler? && !binstubs? end |
#bundler? ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/guard/motion/runner.rb', line 66 def bundler? if @bundler.nil? @bundler = bundler_allowed? && @options[:bundler] else @bundler end end |
#bundler_allowed? ⇒ Boolean
58 59 60 61 62 63 64 |
# File 'lib/guard/motion/runner.rb', line 58 def bundler_allowed? if @bundler_allowed.nil? @bundler_allowed = File.exist?("#{Dir.pwd}/Gemfile") else @bundler_allowed end end |
#rake_command(paths) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/guard/motion/runner.rb', line 34 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
28 29 30 31 32 |
# File 'lib/guard/motion/runner.rb', line 28 def rake_executable @rake_executable ||= begin binstubs? ? "#{binstubs}/rake" : 'rake' end end |
#run(paths = nil, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/guard/motion/runner.rb', line 13 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) run_via_shell rake_command(paths) end |
#run_via_shell(command) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/guard/motion/runner.rb', line 42 def run_via_shell(command) success = system(command) if @options[:notification] && !success Notifier.notify("Failed", :title => "Motion spec results", :image => :failed, :priority => 2) end success end |