guard-rspec 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -64,6 +64,7 @@ Other available options:
64
64
  :drb => true
65
65
  :bundler => false # don't use "bundle exec"
66
66
  :rvm => ['1.8.7', '1.9.2'] # directly run your specs on multiple ruby
67
+ :formatter => "instafail" # show failing specs instantly
67
68
 
68
69
  == Development
69
70
 
@@ -1,3 +1,5 @@
1
+ require "#{File.dirname(__FILE__)}/../rspec"
2
+
1
3
  module Formatter
2
4
 
3
5
  def guard_message(example_count, failure_count, pending_count, duration)
@@ -0,0 +1,29 @@
1
+ require "#{File.dirname(__FILE__)}/../formatter"
2
+
3
+ if defined?(Spec)
4
+ # RSpec 1.x
5
+ require 'spec/runner/formatter/progress_bar_formatter'
6
+ class Default < Spec::Runner::Formatter::ProgressBarFormatter
7
+ include Formatter
8
+
9
+ def dump_summary(duration, total, failures, pending)
10
+ message = guard_message(total, failures, pending, duration)
11
+ image = guard_image(failures, pending)
12
+ notify(message, image)
13
+ end
14
+ end
15
+ else
16
+ # RSpec 2.x
17
+ require 'rspec/core/formatters/progress_formatter'
18
+ class Default < RSpec::Core::Formatters::ProgressFormatter
19
+ include Formatter
20
+
21
+ def dump_summary(duration, total, failures, pending)
22
+ super # needed to keep progress formatter
23
+
24
+ message = guard_message(total, failures, pending, duration)
25
+ image = guard_image(failures, pending)
26
+ notify(message, image)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,69 @@
1
+ # Inspired from https://github.com/grosser/rspec-instafail/blob/master/lib/rspec/instafail.rb
2
+ require "#{File.dirname(__FILE__)}/../formatter"
3
+
4
+ if defined?(Spec)
5
+ # RSpec 1.x
6
+ require 'spec/runner/formatter/progress_bar_formatter'
7
+ class Instafail < Spec::Runner::Formatter::ProgressBarFormatter
8
+ include Formatter
9
+
10
+ def dump_summary(duration, total, failures, pending)
11
+ message = guard_message(total, failures, pending, duration)
12
+ image = guard_image(failures, pending)
13
+ notify(message, image)
14
+ end
15
+
16
+ def example_failed(example, counter, failure)
17
+ short_padding = ' '
18
+ padding = ' '
19
+
20
+ output.puts
21
+ output.puts red("#{short_padding}#{counter}) #{example_group.description} #{example.description}")
22
+ output.puts "#{padding}#{red(failure.exception)}"
23
+
24
+ format_backtrace(failure.exception.backtrace).each do |backtrace_info|
25
+ output.puts insta_gray("#{padding}# #{backtrace_info.strip}")
26
+ end
27
+
28
+ output.flush
29
+ end
30
+
31
+ private
32
+
33
+ # there is a gray() that returns nil, so we use our own...
34
+ def insta_gray(text)
35
+ colour(text, "\e[90m")
36
+ end
37
+ end
38
+ else
39
+ # RSpec 2.x
40
+ require 'rspec/core/formatters/progress_formatter'
41
+ class Instafail < RSpec::Core::Formatters::ProgressFormatter
42
+ include Formatter
43
+
44
+ def dump_summary(duration, total, failures, pending)
45
+ super # needed to keep progress formatter
46
+
47
+ message = guard_message(total, failures, pending, duration)
48
+ image = guard_image(failures, pending)
49
+ notify(message, image)
50
+ end
51
+
52
+ def example_failed(example)
53
+ @counter ||= 0
54
+ @counter += 1
55
+ exception = example.metadata[:execution_result][:exception_encountered]
56
+ short_padding = ' '
57
+ padding = ' '
58
+ output.puts
59
+ output.puts "#{short_padding}#{@counter}) #{example.full_description}"
60
+ output.puts "#{padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
61
+ output.puts "#{padding}#{red(exception)}"
62
+ format_backtrace(exception.backtrace, example).each do |backtrace_info|
63
+ output.puts grey("#{padding}# #{backtrace_info}")
64
+ end
65
+ output.flush
66
+ end
67
+
68
+ end
69
+ end
@@ -3,44 +3,45 @@ module Guard
3
3
  module Runner
4
4
  class << self
5
5
  attr_reader :rspec_version
6
-
6
+
7
7
  def run(paths, options = {})
8
8
  message = options[:message] || "Running: #{paths.join(' ')}"
9
9
  UI.info message, :reset => true
10
10
  system(rspec_command(paths, options))
11
11
  end
12
-
12
+
13
13
  def set_rspec_version(options = {})
14
14
  @rspec_version = options[:version] || determine_rspec_version
15
15
  end
16
-
16
+
17
17
  private
18
-
18
+
19
19
  def rspec_command(paths, options = {})
20
20
  cmd_parts = []
21
21
  cmd_parts << "rvm #{options[:rvm].join(',')} exec" if options[:rvm].is_a?(Array)
22
22
  cmd_parts << "bundle exec" if bundler? && options[:bundler] != false
23
-
23
+
24
24
  case rspec_version
25
25
  when 1
26
26
  cmd_parts << "spec"
27
- cmd_parts << "-f progress --require #{File.dirname(__FILE__)}/formatters/spec_notify.rb --format SpecNotify:STDOUT"
28
27
  when 2
29
28
  cmd_parts << "rspec"
30
- cmd_parts << "--require #{File.dirname(__FILE__)}/formatters/rspec_notify.rb --format RSpecNotify"
31
29
  end
32
-
30
+
31
+ formatter = options[:formatter] || "default"
32
+ cmd_parts << "--require #{File.dirname(__FILE__)}/formatters/#{formatter}.rb --format #{formatter.capitalize}"
33
+
33
34
  cmd_parts << "--drb" if options[:drb] == true
34
35
  cmd_parts << "--color" if options[:color] != false
35
-
36
+
36
37
  cmd_parts << paths.join(' ')
37
38
  cmd_parts.join(" ")
38
39
  end
39
-
40
+
40
41
  def bundler?
41
42
  @bundler ||= File.exist?("#{Dir.pwd}/Gemfile")
42
43
  end
43
-
44
+
44
45
  def determine_rspec_version
45
46
  UI.info "Determine rspec_version... (can be forced with Guard::RSpec version option)"
46
47
  if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
@@ -53,7 +54,7 @@ module Guard
53
54
  2
54
55
  end
55
56
  end
56
-
57
+
57
58
  end
58
59
  end
59
60
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module RSpecVersion
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-rspec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thibaud Guillaume-Gentil
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-05 00:00:00 +01:00
18
+ date: 2010-11-07 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -77,8 +77,8 @@ extra_rdoc_files: []
77
77
 
78
78
  files:
79
79
  - lib/guard/rspec/formatter.rb
80
- - lib/guard/rspec/formatters/rspec_notify.rb
81
- - lib/guard/rspec/formatters/spec_notify.rb
80
+ - lib/guard/rspec/formatters/default.rb
81
+ - lib/guard/rspec/formatters/instafail.rb
82
82
  - lib/guard/rspec/inspector.rb
83
83
  - lib/guard/rspec/runner.rb
84
84
  - lib/guard/rspec/templates/Guardfile
@@ -1,16 +0,0 @@
1
- require 'rspec/core/formatters/progress_formatter'
2
- require "#{File.dirname(__FILE__)}/../formatter"
3
- require "#{File.dirname(__FILE__)}/../../rspec"
4
-
5
- class RSpecNotify < RSpec::Core::Formatters::ProgressFormatter
6
- include Formatter
7
-
8
- def dump_summary(duration, total, failures, pending)
9
- super # needed to keep progress formatter
10
-
11
- message = guard_message(total, failures, pending, duration)
12
- image = guard_image(failures, pending)
13
- notify(message, image)
14
- end
15
-
16
- end
@@ -1,14 +0,0 @@
1
- require 'spec/runner/formatter/base_formatter'
2
- require "#{File.dirname(__FILE__)}/../formatter"
3
- require "#{File.dirname(__FILE__)}/../../rspec"
4
-
5
- class SpecNotify < Spec::Runner::Formatter::BaseFormatter
6
- include Formatter
7
-
8
- def dump_summary(duration, total, failures, pending)
9
- message = guard_message(total, failures, pending, duration)
10
- image = guard_image(failures, pending)
11
- notify(message, image)
12
- end
13
-
14
- end