Class: RSpactor::Runner
- Inherits:
-
Object
- Object
- RSpactor::Runner
- Defined in:
- lib/rspactor/runner.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#inspector ⇒ Object
readonly
Returns the value of attribute inspector.
-
#interactor ⇒ Object
readonly
Returns the value of attribute interactor.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rspec ⇒ Object
readonly
Returns the value of attribute rspec.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dir, options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #last_run_failed? ⇒ Boolean
- #load_dotfile ⇒ Object
- #run_all_tests ⇒ Object
- #run_spec_command(paths) ⇒ Object
- #run_test_command(paths) ⇒ Object
- #start ⇒ Object
- #start_interactor ⇒ Object
- #start_listener ⇒ Object
Constructor Details
#initialize(dir, options = {}) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 |
# File 'lib/rspactor/runner.rb', line 12 def initialize(dir, = {}) @dir = dir @options = @rspec = File.exists?(File.join(dir, 'spec')) read_git_head end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
10 11 12 |
# File 'lib/rspactor/runner.rb', line 10 def dir @dir end |
#inspector ⇒ Object (readonly)
Returns the value of attribute inspector.
10 11 12 |
# File 'lib/rspactor/runner.rb', line 10 def inspector @inspector end |
#interactor ⇒ Object (readonly)
Returns the value of attribute interactor.
10 11 12 |
# File 'lib/rspactor/runner.rb', line 10 def interactor @interactor end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/rspactor/runner.rb', line 10 def @options end |
#rspec ⇒ Object (readonly)
Returns the value of attribute rspec.
10 11 12 |
# File 'lib/rspactor/runner.rb', line 10 def rspec @rspec end |
Class Method Details
.start(options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/rspactor/runner.rb', line 5 def self.start( = {}) run_in = .delete(:run_in) || Dir.pwd new(run_in, ).start end |
Instance Method Details
#last_run_failed? ⇒ Boolean
86 87 88 |
# File 'lib/rspactor/runner.rb', line 86 def last_run_failed? @last_run_failed == false end |
#load_dotfile ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rspactor/runner.rb', line 42 def load_dotfile dotfile = File.join(ENV['HOME'], '.rspactor') if File.exists?(dotfile) begin Kernel.load dotfile rescue => e $stderr.puts "Error while loading #{dotfile}: #{e}" end end end |
#run_all_tests ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rspactor/runner.rb', line 53 def run_all_tests if rspec? run_spec_command(File.join(dir, 'spec')) else patterns = ["test/unit/**/*_test.rb", "test/lib/**/*_test.rb", "test/functional/**/*_test.rb", "test/integration/**/*_test.rb"] patterns.each do |pattern| run_test_command(Dir[pattern]) end end end |
#run_spec_command(paths) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/rspactor/runner.rb', line 66 def run_spec_command(paths) paths = Array(paths) if paths.empty? @last_run_failed = nil else cmd = [ruby_opts, spec_runner, paths, spec_opts].flatten.join(' ') @last_run_failed = run_command(cmd) end end |
#run_test_command(paths) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/rspactor/runner.rb', line 76 def run_test_command(paths) paths = Array(paths) if paths.empty? @last_run_failed = nil else cmd = [ruby_opts, test_runner, paths].flatten.join(' ') @last_run_failed = run_command(cmd) end end |
#start ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rspactor/runner.rb', line 19 def start load_dotfile puts "** RSpactor is now watching at '#{dir}'" start_interactor start_listener end |
#start_interactor ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rspactor/runner.rb', line 26 def start_interactor @interactor = Interactor.new aborted = @interactor.wait_for_enter_key("** Hit <enter> to skip initial spec run", 3) @interactor.start_termination_handler run_all_tests unless aborted end |
#start_listener ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rspactor/runner.rb', line 33 def start_listener @inspector_class = rspec? ? RSpecInspector : TestInspector @inspector = @inspector_class.new(dir) Listener.new(@inspector_class::EXTENSIONS) do |files| test_changed_files(files) unless git_head_changed? end.run(dir) end |