rspec-core 2.12.1 → 2.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,14 @@
1
+ ### 2.12.2 / 2012-12-13
2
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.12.1...v2.12.2)
3
+
4
+ Bug fixes
5
+
6
+ * Fix `RSpec::Core::RakeTask` so that it is compatible with rake 0.8.7
7
+ on ruby 1.8.7. We had accidentally broke it in the 2.12 release
8
+ (Myron Marston).
9
+ * Fix `RSpec::Core::RakeTask` so it is tolerant of the `Rspec` constant
10
+ for backwards compatibility (Patrick Van Stee)
11
+
1
12
  ### 2.12.1 / 2012-12-01
2
13
  [full changelog](http://github.com/rspec/rspec-core/compare/v2.12.0...v2.12.1)
3
14
 
@@ -17,6 +17,9 @@ module RSpec
17
17
  attr_reader :example_count, :pending_count, :failure_count
18
18
  attr_reader :failed_examples, :pending_examples
19
19
 
20
+ # @api public
21
+ #
22
+ # @param output
20
23
  def initialize(output)
21
24
  @output = output || StringIO.new
22
25
  @example_count = @pending_count = @failure_count = 0
@@ -26,9 +29,14 @@ module RSpec
26
29
  @example_group = nil
27
30
  end
28
31
 
29
- # Invoked before any examples are run, right after they have all
30
- # been collected. This can be useful for formatters that provide
31
- # feedback on progress through a suite.
32
+ # @api public
33
+ #
34
+ # This method is invoked before any examples are run, right after
35
+ # they have all been collected. This can be useful for special
36
+ # formatters that need to provide progress on feedback (graphical ones).
37
+ #
38
+ # This will only be invoked once, and the next one to be invoked
39
+ # is {#example_group_started}.
32
40
  #
33
41
  # @param example_count
34
42
  def start(example_count)
@@ -36,28 +44,40 @@ module RSpec
36
44
  @example_count = example_count
37
45
  end
38
46
 
39
- # Invoked at the beginning of the execution of each example
40
- # group.
47
+ # @api public
48
+ #
49
+ # This method is invoked at the beginning of the execution of each example group.
41
50
  #
42
51
  # @param example_group subclass of `RSpec::Core::ExampleGroup`
52
+ #
53
+ # The next method to be invoked after this is {#example_passed},
54
+ # {#example_pending}, or {#example_group_finished}.
55
+ #
56
+ # @param example_group
43
57
  def example_group_started(example_group)
44
58
  @example_group = example_group
45
59
  end
46
60
 
61
+ # @api public
62
+ #
47
63
  # Invoked at the end of the execution of each example group.
48
64
  #
49
65
  # @param example_group subclass of `RSpec::Core::ExampleGroup`
50
66
  def example_group_finished(example_group)
51
67
  end
52
68
 
53
-
69
+ # @api public
70
+ #
54
71
  # Invoked at the beginning of the execution of each example.
55
72
  #
56
73
  # @param example instance of subclass of `RSpec::Core::ExampleGroup`
74
+ # @return [Array]
57
75
  def example_started(example)
58
76
  examples << example
59
77
  end
60
78
 
79
+ # @api public
80
+ #
61
81
  # Invoked when an example passes.
62
82
  #
63
83
  # @param example instance of subclass of `RSpec::Core::ExampleGroup`
@@ -67,35 +87,64 @@ module RSpec
67
87
  # Invoked when an example is pending.
68
88
  #
69
89
  # @param example instance of subclass of `RSpec::Core::ExampleGroup`
90
+ # @return [Array]
70
91
  def example_pending(example)
71
92
  @pending_examples << example
72
93
  end
73
94
 
95
+ # @api public
96
+ #
74
97
  # Invoked when an example fails.
75
98
  #
76
99
  # @param example instance of subclass of `RSpec::Core::ExampleGroup`
100
+ # @return [Array]
77
101
  def example_failed(example)
78
102
  @failed_examples << example
79
103
  end
80
104
 
105
+ # @api public
106
+ #
81
107
  # Used by the reporter to send messages to the output stream.
108
+ #
82
109
  # @param [String] message
83
110
  def message(message)
84
111
  end
85
112
 
113
+ # @api public
114
+ #
86
115
  # Invoked after all examples have executed, before dumping post-run reports.
116
+ #
117
+ # @return [nil]
87
118
  def stop
88
119
  end
89
120
 
90
- # Invoked after all of the examples have executed (after `stop`).
121
+ # @api public
122
+ #
123
+ # This method is invoked after all of the examples have executed. The next method
124
+ # to be invoked after this one is {#dump_failures}
125
+ # (BaseTextFormatter then calls {#dump_failure} once for each failed example.)
126
+ #
127
+ # @return [nil]
91
128
  def start_dump
92
129
  end
93
130
 
131
+ # @api public
132
+ #
94
133
  # Dumps detailed information about each example failure.
134
+ #
135
+ # @return [nil]
95
136
  def dump_failures
96
137
  end
97
138
 
98
- # Invoked after the dumping of examples and failures.
139
+ # @api public
140
+ #
141
+ # This method is invoked after the dumping of examples and failures. Each parameter
142
+ # is assigned to a corresponding attribute.
143
+ #
144
+ # @param duration
145
+ # @param example_count
146
+ # @param failure_count
147
+ # @param pending_count
99
148
  def dump_summary(duration, example_count, failure_count, pending_count)
100
149
  @duration = duration
101
150
  @example_count = example_count
@@ -103,7 +152,12 @@ module RSpec
103
152
  @pending_count = pending_count
104
153
  end
105
154
 
106
- # Invoked after the summary if option is set to do so.
155
+ # @api public
156
+ #
157
+ # Outputs a report of pending examples. This gets invoked
158
+ # after the summary if option is set to do so.
159
+ #
160
+ # @return [nil]
107
161
  def dump_pending
108
162
  end
109
163
 
@@ -111,6 +165,8 @@ module RSpec
111
165
  def seed(number)
112
166
  end
113
167
 
168
+ # @api public
169
+ #
114
170
  # Invoked at the very end, `close` allows the formatter to clean
115
171
  # up resources, e.g. open streams, etc.
116
172
  def close
@@ -25,6 +25,12 @@ module RSpec
25
25
  end
26
26
  end
27
27
 
28
+ # @api public
29
+ #
30
+ # Colorizes the output red for failure, yellow for
31
+ # pending, and green otherwise.
32
+ #
33
+ # @param [String] string
28
34
  def colorise_summary(summary)
29
35
  if failure_count > 0
30
36
  red(summary)
@@ -44,6 +50,10 @@ module RSpec
44
50
  dump_commands_to_rerun_failed_examples
45
51
  end
46
52
 
53
+ # @api public
54
+ #
55
+ # Outputs commands which can be used to re-run failed examples.
56
+ #
47
57
  def dump_commands_to_rerun_failed_examples
48
58
  return if failed_examples.empty?
49
59
  output.puts
@@ -55,6 +65,10 @@ module RSpec
55
65
  end
56
66
  end
57
67
 
68
+ # @api public
69
+ #
70
+ # Outputs the 10 slowest examples in a report when using `--profile`.
71
+ #
58
72
  def dump_profile
59
73
  sorted_examples = examples.sort_by {|example|
60
74
  example.execution_result[:run_time] }.reverse.first(10)
@@ -73,6 +87,10 @@ module RSpec
73
87
  end
74
88
  end
75
89
 
90
+ # @api public
91
+ #
92
+ # Outputs summary with number of examples, failures and pending.
93
+ #
76
94
  def summary_line(example_count, failure_count, pending_count)
77
95
  summary = pluralize(example_count, "example")
78
96
  summary << ", " << pluralize(failure_count, "failure")
@@ -32,6 +32,16 @@ module RSpec
32
32
  SUB_SECOND_PRECISION = 5
33
33
  DEFAULT_PRECISION = 2
34
34
 
35
+ # @api private
36
+ #
37
+ # Formats seconds into a human-readable string.
38
+ #
39
+ # @param [Float, Fixnum] duration in seconds
40
+ # @return [String] human-readable time
41
+ #
42
+ # @example
43
+ # format_duration(1) #=> "1 minute 1 second"
44
+ # format_duration(135.14) #=> "2 minutes 15.14 seconds"
35
45
  def format_duration(duration)
36
46
  if duration > 60
37
47
  minutes = duration.to_i / 60
@@ -43,17 +53,46 @@ module RSpec
43
53
  end
44
54
  end
45
55
 
56
+ # @api private
57
+ #
58
+ # Formats seconds to have 5 digits of precision with trailing zeros removed if the number
59
+ # if less than 1 or with 2 digits of precision if the number is greater than zero.
60
+ #
61
+ # @param [Float] float
62
+ # @return [String] formatted float
63
+ #
64
+ # @example
65
+ # format_seconds(0.000006) #=> "0.00001"
66
+ # format_seconds(0.020000) #=> "0.02"
67
+ # format_seconds(1.00000000001) #=> "1"
68
+ #
69
+ # The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
70
+ #
71
+ # @see #strip_trailing_zeroes
46
72
  def format_seconds(float)
47
73
  precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
48
74
  formatted = sprintf("%.#{precision}f", float)
49
75
  strip_trailing_zeroes(formatted)
50
76
  end
51
77
 
78
+ # @api private
79
+ #
80
+ # Remove trailing zeros from a string.
81
+ #
82
+ # @param [String] string string with trailing zeros
83
+ # @return [String] string with trailing zeros removed
52
84
  def strip_trailing_zeroes(string)
53
85
  stripped = string.sub(/[^1-9]+$/, '')
54
86
  stripped.empty? ? "0" : stripped
55
87
  end
56
88
 
89
+ # @api private
90
+ #
91
+ # Pluralize a word based on a count.
92
+ #
93
+ # @param [Fixnum] count number of objects
94
+ # @param [String] string word to be pluralized
95
+ # @return [String] pluralized word
57
96
  def pluralize(count, string)
58
97
  "#{count} #{string}#{'s' unless count.to_f == 1}"
59
98
  end
@@ -1,7 +1,9 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Formatters
4
- # This class extracts code snippets by looking at the backtrace of the passed error
4
+ # @api private
5
+ #
6
+ # Extracts code snippets by looking at the backtrace of the passed error and applies synax highlighting and line numbers using html.
5
7
  class SnippetExtractor
6
8
  class NullConverter; def convert(code, pre); code; end; end
7
9
 
@@ -12,6 +14,14 @@ module RSpec
12
14
  @@converter = NullConverter.new
13
15
  end
14
16
 
17
+ # @api private
18
+ #
19
+ # Extract lines of code corresponding to a backtrace.
20
+ #
21
+ # @param [String] backtrace the backtrace from a test failure
22
+ # @return [String] highlighted code snippet indicating where the test failure occured
23
+ #
24
+ # @see #post_process
15
25
  def snippet(backtrace)
16
26
  raw_code, line = snippet_for(backtrace[0])
17
27
  highlighted = @@converter.convert(raw_code, false)
@@ -19,6 +29,14 @@ module RSpec
19
29
  post_process(highlighted, line)
20
30
  end
21
31
 
32
+ # @api private
33
+ #
34
+ # Create a snippet from a line of code.
35
+ #
36
+ # @param [String] error_line file name with line number (i.e. 'foo_spec.rb:12')
37
+ # @return [String] lines around the target line within the file
38
+ #
39
+ # @see #lines_around
22
40
  def snippet_for(error_line)
23
41
  if error_line =~ /(.*):(\d+)/
24
42
  file = $1
@@ -29,6 +47,13 @@ module RSpec
29
47
  end
30
48
  end
31
49
 
50
+ # @api private
51
+ #
52
+ # Extract lines of code centered around a particular line within a source file.
53
+ #
54
+ # @param [String] file filename
55
+ # @param [Fixnum] line line number
56
+ # @return [String] lines around the target line within the file (2 above and 1 below).
32
57
  def lines_around(file, line)
33
58
  if File.file?(file)
34
59
  lines = File.read(file).split("\n")
@@ -44,6 +69,13 @@ module RSpec
44
69
  "# Couldn't get snippet for #{file}"
45
70
  end
46
71
 
72
+ # @api private
73
+ #
74
+ # Adds line numbers to all lines and highlights the line where the failure occurred using html `span` tags.
75
+ #
76
+ # @param [String] highlighted syntax-highlighted snippet surrounding the offending line of code
77
+ # @param [Fixnum] offending_line line where failure occured
78
+ # @return [String] completed snippet
47
79
  def post_process(highlighted, offending_line)
48
80
  new_lines = []
49
81
  highlighted.split("\n").each_with_index do |line, i|
@@ -1,6 +1,8 @@
1
+ require 'rspec/core/backward_compatibility'
1
2
  require 'rspec/core/deprecation'
2
3
  require 'rake'
3
4
  require 'rake/tasklib'
5
+ require 'shellwords'
4
6
 
5
7
  module RSpec
6
8
  module Core
@@ -157,13 +159,13 @@ module RSpec
157
159
 
158
160
  private
159
161
 
160
- if RUBY_VERSION == '1.8.6'
162
+ if "".respond_to?(:shellescape)
161
163
  def shellescape(string)
162
- string.gsub(/"/, '\"').gsub(/'/, "\\\\'")
164
+ string.shellescape
163
165
  end
164
- else
166
+ else # 1.8.6's shellwords doesn't provide shellescape :(.
165
167
  def shellescape(string)
166
- string.shellescape
168
+ string.gsub(/"/, '\"').gsub(/'/, "\\\\'")
167
169
  end
168
170
  end
169
171
 
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Version
4
- STRING = '2.12.1'
4
+ STRING = '2.12.2'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 12
9
- - 1
10
- version: 2.12.1
9
+ - 2
10
+ version: 2.12.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steven Baker
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: exe
18
18
  cert_chain: []
19
19
 
20
- date: 2012-12-01 00:00:00 Z
20
+ date: 2012-12-14 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -389,7 +389,7 @@ rubyforge_project: rspec
389
389
  rubygems_version: 1.8.24
390
390
  signing_key:
391
391
  specification_version: 3
392
- summary: rspec-core-2.12.1
392
+ summary: rspec-core-2.12.2
393
393
  test_files:
394
394
  - features/Autotest.md
395
395
  - features/README.md