Class: Rspectacle::SpecRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rspectacle/spec_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ SpecRunner

Returns a new instance of SpecRunner.



5
6
7
# File 'lib/rspectacle/spec_runner.rb', line 5

def initialize(files)
  self.files = files
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



3
4
5
# File 'lib/rspectacle/spec_runner.rb', line 3

def files
  @files
end

Instance Method Details

#announce_filesObject



32
33
34
35
36
37
38
39
# File 'lib/rspectacle/spec_runner.rb', line 32

def announce_files
  puts ""
  puts "Running Specs:"
  files.each do |file|
    puts "* #{file}"
  end
  puts ""
end

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspectacle/spec_runner.rb', line 9

def run
  raise "No Files Found" if files.empty?

  announce_files

  cmd = "bin/rspec #{files.join(' ')}"

  begin
    PTY.spawn( cmd ) do |stdout, stdin, pid|
      begin
        stdout.each do |line|
          next if line =~ /^cat\r\n$/
          print line
        end
      rescue Errno::EIO
        nil
      end
    end
  rescue PTY::ChildExited
    nil
  end
end