Class: Guard::JRubyRSpec::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/jruby-rspec/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
18
# File 'lib/guard/jruby-rspec/runner.rb', line 9

def initialize(options = {})
  @options = {
    :cli          => [],
    :notification => true
  }.merge(options)

  @pipefile = options[:pipefile]
  @pipefile ||= ".guard-jruby-rspec-pipe"
  cleanup
end

Instance Method Details

#cleanupObject



20
21
22
# File 'lib/guard/jruby-rspec/runner.rb', line 20

def cleanup
  File.delete(@pipefile) if File.exists?(@pipefile)
end

#parsed_or_default_formatterObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/guard/jruby-rspec/runner.rb', line 55

def parsed_or_default_formatter
  @parsed_or_default_formatter ||= begin
    file_name = "#{Dir.pwd}/.rspec"
    parsed_formatter = if File.exist?(file_name)
      formatters = File.read(file_name).scan(formatter_regex).flatten
      formatters.map { |formatter| "-f#{formatter}" }.join(' ')
    end

    parsed_formatter.nil? || parsed_formatter.empty? ? '-fprogress' : parsed_formatter
  end
end

#run(paths, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/guard/jruby-rspec/runner.rb', line 24

def run(paths, options = {})
  return false if paths.empty?

  message = options[:message] || "Running: #{paths.join(' ')}"
  UI.info(message, :reset => true)

  # it might be a problem to run Rspec within this runtime.  Might have to create an
  # embedded jruby.
  if File.exists?(@pipefile)
    raise "not supported yet"
    # instead of writing to the pipefile, we should probably use a
    # formatter and write to /dev/null
    # orig_stdout = $stdout.clone
    # orig_stderr = $stderr.clone
    # begin
    #   $stdout.reopen(@pipefile, "w")
    #   $stderr.reopen(@pipefile, "w")
    #   ::RSpec::Core::Runner.run(paths)
    # ensure
    #   $stdout.reopen(orig_stdout)
    #   $stderr.reopen(orig_stderr)
    # end
  else
    orig_configuration = ::RSpec.configuration
    Containment.new.protect do
      ::RSpec::Core::Runner.run(rspec_arguments(paths, @options))
    end
    ::RSpec.instance_variable_set(:@configuration, orig_configuration)
  end
end