Module: Guard::RSpectacle::Runner

Defined in:
lib/guard/rspectacle/runner.rb

Overview

The RSpectacle runner handles the execution of the rspec test.

Class Method Summary collapse

Class Method Details

.run(examples, options, err = $stderr, out = $stdout) ⇒ Array

Parameters:

  • examples (Array<String>)

    the specs to run

  • options (Hash)

    the options

  • err (IO) (defaults to: $stderr)

    the error stream

  • out (IO) (defaults to: $stdout)

    the output stream

Options Hash (options):

  • :cli (String)

    the RSpec CLI options

  • :notification (Boolean)

    show notifications

  • :hide_success (Boolean)

    hide success message notification

Returns:

  • (Array)

    the spec result: status, failed_specs, passed_specs



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/guard/rspectacle/runner.rb', line 29

def run(examples, options, err=$stderr, out=$stdout)
  message = options[:message] || "Run #{ examples.join(' ') }"
  ::Guard::UI.info(message, :reset => true)

  rspec_options = options[:cli].to_s.split
  rspec_options.delete('--drb')
  rspec_options.delete('-X')
  rspec_options += rspectacular_options + examples

  begin
    status = ::RSpec::Core::Runner.run(rspec_options, err, out)

    passed        = status == 0
    failed_specs  = ::Guard::RSpectacle::Notifier.failed_specs || []
    passed_specs  = ::Guard::RSpectacle::Notifier.passed_specs || []
    duration      = ::Guard::RSpectacle::Notifier.duration || 0.0
    example_count = ::Guard::RSpectacle::Notifier.example_count || -1
    failure_count = ::Guard::RSpectacle::Notifier.failure_count || -1
    pending_count = ::Guard::RSpectacle::Notifier.pending_count || -1

    if options[:notification]

      message = " #{ example_count } example#{ example_count == 1 ? '' : 's' }"
      message << ", #{ failure_count } failure#{ failure_count == 1 ? '' : 's' }"
      message << " (#{ pending_count } pending)" if pending_count > 0
      message << "\nin #{ round(duration) } seconds"

      if failure_count > 0
        ::Guard::RSpectacle::Formatter.notify(::Guard::RSpectacle::Humanity.failure + message,
                                              :title    => 'RSpec results',
                                              :image    => :failed,
                                              :priority => -2)
      elsif pending_count > 0
        ::Guard::RSpectacle::Formatter.notify(::Guard::RSpectacle::Humanity.pending + message,
                                              :title    => 'RSpec results',
                                              :image    => :pending,
                                              :priority => -1)
      else
        ::Guard::RSpectacle::Formatter.notify(::Guard::RSpectacle::Humanity.success + message,
                                              :title    => 'RSpec results',
                                              :image    => :success,
                                              :priority => 2) if !options[:hide_success]
      end
    end

    [passed, relative(failed_specs), relative(passed_specs)]

  rescue Exception => e
    ::Guard::RSpectacle::Formatter.error("Error running specs: #{ e.message }")

    [false, [], []]
  end
end