rspec-core 3.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.document +5 -0
  5. data/.yardopts +8 -0
  6. data/Changelog.md +2243 -0
  7. data/LICENSE.md +26 -0
  8. data/README.md +384 -0
  9. data/exe/rspec +4 -0
  10. data/lib/rspec/autorun.rb +3 -0
  11. data/lib/rspec/core.rb +185 -0
  12. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  13. data/lib/rspec/core/bisect/coordinator.rb +62 -0
  14. data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
  15. data/lib/rspec/core/bisect/fork_runner.rb +134 -0
  16. data/lib/rspec/core/bisect/server.rb +61 -0
  17. data/lib/rspec/core/bisect/shell_command.rb +126 -0
  18. data/lib/rspec/core/bisect/shell_runner.rb +73 -0
  19. data/lib/rspec/core/bisect/utilities.rb +58 -0
  20. data/lib/rspec/core/configuration.rb +2308 -0
  21. data/lib/rspec/core/configuration_options.rb +233 -0
  22. data/lib/rspec/core/drb.rb +113 -0
  23. data/lib/rspec/core/dsl.rb +98 -0
  24. data/lib/rspec/core/example.rb +656 -0
  25. data/lib/rspec/core/example_group.rb +889 -0
  26. data/lib/rspec/core/example_status_persister.rb +235 -0
  27. data/lib/rspec/core/filter_manager.rb +231 -0
  28. data/lib/rspec/core/flat_map.rb +20 -0
  29. data/lib/rspec/core/formatters.rb +269 -0
  30. data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
  31. data/lib/rspec/core/formatters/base_formatter.rb +70 -0
  32. data/lib/rspec/core/formatters/base_text_formatter.rb +75 -0
  33. data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
  34. data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
  35. data/lib/rspec/core/formatters/console_codes.rb +68 -0
  36. data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
  37. data/lib/rspec/core/formatters/documentation_formatter.rb +70 -0
  38. data/lib/rspec/core/formatters/exception_presenter.rb +508 -0
  39. data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
  40. data/lib/rspec/core/formatters/helpers.rb +110 -0
  41. data/lib/rspec/core/formatters/html_formatter.rb +153 -0
  42. data/lib/rspec/core/formatters/html_printer.rb +414 -0
  43. data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
  44. data/lib/rspec/core/formatters/json_formatter.rb +102 -0
  45. data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
  46. data/lib/rspec/core/formatters/progress_formatter.rb +29 -0
  47. data/lib/rspec/core/formatters/protocol.rb +182 -0
  48. data/lib/rspec/core/formatters/snippet_extractor.rb +134 -0
  49. data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
  50. data/lib/rspec/core/hooks.rb +624 -0
  51. data/lib/rspec/core/invocations.rb +87 -0
  52. data/lib/rspec/core/memoized_helpers.rb +554 -0
  53. data/lib/rspec/core/metadata.rb +498 -0
  54. data/lib/rspec/core/metadata_filter.rb +255 -0
  55. data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
  56. data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
  57. data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
  58. data/lib/rspec/core/mocking_adapters/null.rb +14 -0
  59. data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
  60. data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
  61. data/lib/rspec/core/notifications.rb +521 -0
  62. data/lib/rspec/core/option_parser.rb +309 -0
  63. data/lib/rspec/core/ordering.rb +158 -0
  64. data/lib/rspec/core/output_wrapper.rb +29 -0
  65. data/lib/rspec/core/pending.rb +165 -0
  66. data/lib/rspec/core/profiler.rb +34 -0
  67. data/lib/rspec/core/project_initializer.rb +48 -0
  68. data/lib/rspec/core/project_initializer/.rspec +1 -0
  69. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +100 -0
  70. data/lib/rspec/core/rake_task.rb +168 -0
  71. data/lib/rspec/core/reporter.rb +257 -0
  72. data/lib/rspec/core/ruby_project.rb +53 -0
  73. data/lib/rspec/core/runner.rb +199 -0
  74. data/lib/rspec/core/sandbox.rb +37 -0
  75. data/lib/rspec/core/set.rb +54 -0
  76. data/lib/rspec/core/shared_context.rb +55 -0
  77. data/lib/rspec/core/shared_example_group.rb +269 -0
  78. data/lib/rspec/core/shell_escape.rb +49 -0
  79. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  80. data/lib/rspec/core/version.rb +9 -0
  81. data/lib/rspec/core/warnings.rb +40 -0
  82. data/lib/rspec/core/world.rb +275 -0
  83. metadata +292 -0
  84. metadata.gz.sig +0 -0
@@ -0,0 +1,120 @@
1
+ module RSpec
2
+ module Core
3
+ module Formatters
4
+ # @api private
5
+ #
6
+ # Extracts code snippets by looking at the backtrace of the passed error
7
+ # and applies synax highlighting and line numbers using html.
8
+ class HtmlSnippetExtractor
9
+ # @private
10
+ module NullConverter
11
+ def self.convert(code)
12
+ %Q(#{code}\n<span class="comment"># Install the coderay gem to get syntax highlighting</span>)
13
+ end
14
+ end
15
+
16
+ # @private
17
+ module CoderayConverter
18
+ def self.convert(code)
19
+ CodeRay.scan(code, :ruby).html(:line_numbers => false)
20
+ end
21
+ end
22
+
23
+ # rubocop:disable Style/ClassVars
24
+ # @private
25
+ @@converter = NullConverter
26
+
27
+ begin
28
+ require 'coderay'
29
+ RSpec::Support.require_rspec_core 'formatters/syntax_highlighter'
30
+ RSpec::Core::Formatters::SyntaxHighlighter.attempt_to_add_rspec_terms_to_coderay_keywords
31
+ @@converter = CoderayConverter
32
+ # rubocop:disable Lint/HandleExceptions
33
+ rescue LoadError
34
+ # it'll fall back to the NullConverter assigned above
35
+ # rubocop:enable Lint/HandleExceptions
36
+ end
37
+
38
+ # rubocop:enable Style/ClassVars
39
+
40
+ # @api private
41
+ #
42
+ # Extract lines of code corresponding to a backtrace.
43
+ #
44
+ # @param backtrace [String] the backtrace from a test failure
45
+ # @return [String] highlighted code snippet indicating where the test
46
+ # failure occured
47
+ #
48
+ # @see #post_process
49
+ def snippet(backtrace)
50
+ raw_code, line = snippet_for(backtrace[0])
51
+ highlighted = @@converter.convert(raw_code)
52
+ post_process(highlighted, line)
53
+ end
54
+ # rubocop:enable Style/ClassVars
55
+
56
+ # @api private
57
+ #
58
+ # Create a snippet from a line of code.
59
+ #
60
+ # @param error_line [String] file name with line number (i.e.
61
+ # 'foo_spec.rb:12')
62
+ # @return [String] lines around the target line within the file
63
+ #
64
+ # @see #lines_around
65
+ def snippet_for(error_line)
66
+ if error_line =~ /(.*):(\d+)/
67
+ file = Regexp.last_match[1]
68
+ line = Regexp.last_match[2].to_i
69
+ [lines_around(file, line), line]
70
+ else
71
+ ["# Couldn't get snippet for #{error_line}", 1]
72
+ end
73
+ end
74
+
75
+ # @api private
76
+ #
77
+ # Extract lines of code centered around a particular line within a
78
+ # source file.
79
+ #
80
+ # @param file [String] filename
81
+ # @param line [Fixnum] line number
82
+ # @return [String] lines around the target line within the file (2 above
83
+ # and 1 below).
84
+ def lines_around(file, line)
85
+ if File.file?(file)
86
+ lines = File.read(file).split("\n")
87
+ min = [0, line - 3].max
88
+ max = [line + 1, lines.length - 1].min
89
+ selected_lines = []
90
+ selected_lines.join("\n")
91
+ lines[min..max].join("\n")
92
+ else
93
+ "# Couldn't get snippet for #{file}"
94
+ end
95
+ rescue SecurityError
96
+ "# Couldn't get snippet for #{file}"
97
+ end
98
+
99
+ # @api private
100
+ #
101
+ # Adds line numbers to all lines and highlights the line where the
102
+ # failure occurred using html `span` tags.
103
+ #
104
+ # @param highlighted [String] syntax-highlighted snippet surrounding the
105
+ # offending line of code
106
+ # @param offending_line [Fixnum] line where failure occured
107
+ # @return [String] completed snippet
108
+ def post_process(highlighted, offending_line)
109
+ new_lines = []
110
+ highlighted.split("\n").each_with_index do |line, i|
111
+ new_line = "<span class=\"linenum\">#{offending_line + i - 2}</span>#{line}"
112
+ new_line = "<span class=\"offending\">#{new_line}</span>" if i == 2
113
+ new_lines << new_line
114
+ end
115
+ new_lines.join("\n")
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,102 @@
1
+ RSpec::Support.require_rspec_core "formatters/base_formatter"
2
+ require 'json'
3
+
4
+ module RSpec
5
+ module Core
6
+ module Formatters
7
+ # @private
8
+ class JsonFormatter < BaseFormatter
9
+ Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :seed, :close
10
+
11
+ attr_reader :output_hash
12
+
13
+ def initialize(output)
14
+ super
15
+ @output_hash = {
16
+ :version => RSpec::Core::Version::STRING
17
+ }
18
+ end
19
+
20
+ def message(notification)
21
+ (@output_hash[:messages] ||= []) << notification.message
22
+ end
23
+
24
+ def dump_summary(summary)
25
+ @output_hash[:summary] = {
26
+ :duration => summary.duration,
27
+ :example_count => summary.example_count,
28
+ :failure_count => summary.failure_count,
29
+ :pending_count => summary.pending_count,
30
+ :errors_outside_of_examples_count => summary.errors_outside_of_examples_count
31
+ }
32
+ @output_hash[:summary_line] = summary.totals_line
33
+ end
34
+
35
+ def stop(notification)
36
+ @output_hash[:examples] = notification.examples.map do |example|
37
+ format_example(example).tap do |hash|
38
+ e = example.exception
39
+ if e
40
+ hash[:exception] = {
41
+ :class => e.class.name,
42
+ :message => e.message,
43
+ :backtrace => e.backtrace,
44
+ }
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def seed(notification)
51
+ return unless notification.seed_used?
52
+ @output_hash[:seed] = notification.seed
53
+ end
54
+
55
+ def close(_notification)
56
+ output.write @output_hash.to_json
57
+ end
58
+
59
+ def dump_profile(profile)
60
+ @output_hash[:profile] = {}
61
+ dump_profile_slowest_examples(profile)
62
+ dump_profile_slowest_example_groups(profile)
63
+ end
64
+
65
+ # @api private
66
+ def dump_profile_slowest_examples(profile)
67
+ @output_hash[:profile] = {}
68
+ @output_hash[:profile][:examples] = profile.slowest_examples.map do |example|
69
+ format_example(example).tap do |hash|
70
+ hash[:run_time] = example.execution_result.run_time
71
+ end
72
+ end
73
+ @output_hash[:profile][:slowest] = profile.slow_duration
74
+ @output_hash[:profile][:total] = profile.duration
75
+ end
76
+
77
+ # @api private
78
+ def dump_profile_slowest_example_groups(profile)
79
+ @output_hash[:profile] ||= {}
80
+ @output_hash[:profile][:groups] = profile.slowest_groups.map do |loc, hash|
81
+ hash.update(:location => loc)
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def format_example(example)
88
+ {
89
+ :id => example.id,
90
+ :description => example.description,
91
+ :full_description => example.full_description,
92
+ :status => example.execution_result.status.to_s,
93
+ :file_path => example.metadata[:file_path],
94
+ :line_number => example.metadata[:line_number],
95
+ :run_time => example.execution_result.run_time,
96
+ :pending_message => example.execution_result.pending_message,
97
+ }
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,68 @@
1
+ RSpec::Support.require_rspec_core "formatters/console_codes"
2
+
3
+ module RSpec
4
+ module Core
5
+ module Formatters
6
+ # @api private
7
+ # Formatter for providing profile output.
8
+ class ProfileFormatter
9
+ Formatters.register self, :dump_profile
10
+
11
+ def initialize(output)
12
+ @output = output
13
+ end
14
+
15
+ # @private
16
+ attr_reader :output
17
+
18
+ # @api public
19
+ #
20
+ # This method is invoked after the dumping the summary if profiling is
21
+ # enabled.
22
+ #
23
+ # @param profile [ProfileNotification] containing duration,
24
+ # slowest_examples and slowest_example_groups
25
+ def dump_profile(profile)
26
+ dump_profile_slowest_examples(profile)
27
+ dump_profile_slowest_example_groups(profile)
28
+ end
29
+
30
+ private
31
+
32
+ def dump_profile_slowest_examples(profile)
33
+ @output.puts "\nTop #{profile.slowest_examples.size} slowest " \
34
+ "examples (#{Helpers.format_seconds(profile.slow_duration)} " \
35
+ "seconds, #{profile.percentage}% of total time):\n"
36
+
37
+ profile.slowest_examples.each do |example|
38
+ @output.puts " #{example.full_description}"
39
+ @output.puts " #{bold(Helpers.format_seconds(example.execution_result.run_time))} " \
40
+ "#{bold("seconds")} #{format_caller(example.location)}"
41
+ end
42
+ end
43
+
44
+ def dump_profile_slowest_example_groups(profile)
45
+ return if profile.slowest_groups.empty?
46
+
47
+ @output.puts "\nTop #{profile.slowest_groups.size} slowest example groups:"
48
+ profile.slowest_groups.each do |loc, hash|
49
+ average = "#{bold(Helpers.format_seconds(hash[:average]))} #{bold("seconds")} average"
50
+ total = "#{Helpers.format_seconds(hash[:total_time])} seconds"
51
+ count = Helpers.pluralize(hash[:count], "example")
52
+ @output.puts " #{hash[:description]}"
53
+ @output.puts " #{average} (#{total} / #{count}) #{loc}"
54
+ end
55
+ end
56
+
57
+ def format_caller(caller_info)
58
+ RSpec.configuration.backtrace_formatter.backtrace_line(
59
+ caller_info.to_s.split(':in `block').first)
60
+ end
61
+
62
+ def bold(text)
63
+ ConsoleCodes.wrap(text, :bold)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,29 @@
1
+ RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2
+ RSpec::Support.require_rspec_core "formatters/console_codes"
3
+
4
+ module RSpec
5
+ module Core
6
+ module Formatters
7
+ # @private
8
+ class ProgressFormatter < BaseTextFormatter
9
+ Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
10
+
11
+ def example_passed(_notification)
12
+ output.print ConsoleCodes.wrap('.', :success)
13
+ end
14
+
15
+ def example_pending(_notification)
16
+ output.print ConsoleCodes.wrap('*', :pending)
17
+ end
18
+
19
+ def example_failed(_notification)
20
+ output.print ConsoleCodes.wrap('F', :failure)
21
+ end
22
+
23
+ def start_dump(_notification)
24
+ output.puts
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,182 @@
1
+ module RSpec
2
+ module Core
3
+ module Formatters
4
+ # This class isn't loaded at runtime but serves to document all of the
5
+ # notifications implemented as part of the standard interface. The
6
+ # reporter will issue these during a normal test suite run, but a
7
+ # formatter will only receive those notifications it has registered
8
+ # itself to receive. To register a formatter call:
9
+ #
10
+ # `::RSpec::Core::Formatters.register class, :list, :of, :notifications`
11
+ #
12
+ # e.g.
13
+ #
14
+ # `::RSpec::Core::Formatters.register self, :start, :example_started`
15
+ #
16
+ # @see RSpec::Core::Formatters::BaseFormatter
17
+ # @see RSpec::Core::Formatters::BaseTextFormatter
18
+ # @see RSpec::Core::Reporter
19
+ class Protocol
20
+ # @method initialize(output)
21
+ # @api public
22
+ #
23
+ # @param output [IO] the formatter output
24
+
25
+ # @method start(notification)
26
+ # @api public
27
+ # @group Suite Notifications
28
+ #
29
+ # This method is invoked before any examples are run, right after
30
+ # they have all been collected. This can be useful for special
31
+ # formatters that need to provide progress on feedback (graphical ones).
32
+ #
33
+ # This will only be invoked once, and the next one to be invoked
34
+ # is {#example_group_started}.
35
+ #
36
+ # @param notification [Notifications::StartNotification]
37
+
38
+ # @method example_group_started(notification)
39
+ # @api public
40
+ # @group Group Notifications
41
+ #
42
+ # This method is invoked at the beginning of the execution of each
43
+ # example group.
44
+ #
45
+ # The next method to be invoked after this is {#example_passed},
46
+ # {#example_pending}, or {#example_group_finished}.
47
+ #
48
+ # @param notification [Notifications::GroupNotification] containing example_group
49
+ # subclass of {ExampleGroup}
50
+
51
+ # @method example_group_finished(notification)
52
+ # @api public
53
+ # @group Group Notifications
54
+ #
55
+ # Invoked at the end of the execution of each example group.
56
+ #
57
+ # @param notification [Notifications::GroupNotification] containing example_group
58
+ # subclass of {ExampleGroup}
59
+
60
+ # @method example_started(notification)
61
+ # @api public
62
+ # @group Example Notifications
63
+ #
64
+ # Invoked at the beginning of the execution of each example.
65
+ #
66
+ # @param notification [Notifications::ExampleNotification] containing example subclass
67
+ # of {Example}
68
+
69
+ # @method example_finished(notification)
70
+ # @api public
71
+ # @group Example Notifications
72
+ #
73
+ # Invoked at the end of the execution of each example.
74
+ #
75
+ # @param notification [Notifications::ExampleNotification] containing example subclass
76
+ # of {Example}
77
+
78
+ # @method example_passed(notification)
79
+ # @api public
80
+ # @group Example Notifications
81
+ #
82
+ # Invoked when an example passes.
83
+ #
84
+ # @param notification [Notifications::ExampleNotification] containing example subclass
85
+ # of {Example}
86
+
87
+ # @method example_pending(notification)
88
+ # @api public
89
+ # @group Example Notifications
90
+ #
91
+ # Invoked when an example is pending.
92
+ #
93
+ # @param notification [Notifications::ExampleNotification] containing example subclass
94
+ # of {Example}
95
+
96
+ # @method example_failed(notification)
97
+ # @api public
98
+ # @group Example Notifications
99
+ #
100
+ # Invoked when an example fails.
101
+ #
102
+ # @param notification [Notifications::ExampleNotification] containing example subclass
103
+ # of {Example}
104
+
105
+ # @method message(notification)
106
+ # @api public
107
+ # @group Suite Notifications
108
+ #
109
+ # Used by the reporter to send messages to the output stream.
110
+ #
111
+ # @param notification [Notifications::MessageNotification] containing message
112
+
113
+ # @method stop(notification)
114
+ # @api public
115
+ # @group Suite Notifications
116
+ #
117
+ # Invoked after all examples have executed, before dumping post-run
118
+ # reports.
119
+ #
120
+ # @param notification [Notifications::NullNotification]
121
+
122
+ # @method start_dump(notification)
123
+ # @api public
124
+ # @group Suite Notifications
125
+ #
126
+ # This method is invoked after all of the examples have executed. The
127
+ # next method to be invoked after this one is {#dump_failures}
128
+ # (BaseTextFormatter then calls {#dump_failures} once for each failed
129
+ # example).
130
+ #
131
+ # @param notification [Notifications::NullNotification]
132
+
133
+ # @method dump_failures(notification)
134
+ # @api public
135
+ # @group Suite Notifications
136
+ #
137
+ # Dumps detailed information about each example failure.
138
+ #
139
+ # @param notification [Notifications::NullNotification]
140
+
141
+ # @method dump_summary(summary)
142
+ # @api public
143
+ # @group Suite Notifications
144
+ #
145
+ # This method is invoked after the dumping of examples and failures.
146
+ # Each parameter is assigned to a corresponding attribute.
147
+ #
148
+ # @param summary [Notifications::SummaryNotification] containing duration,
149
+ # example_count, failure_count and pending_count
150
+
151
+ # @method dump_profile(profile)
152
+ # @api public
153
+ # @group Suite Notifications
154
+ #
155
+ # This method is invoked after the dumping the summary if profiling is
156
+ # enabled.
157
+ #
158
+ # @param profile [Notifications::ProfileNotification] containing duration,
159
+ # slowest_examples and slowest_example_groups
160
+
161
+ # @method dump_pending(notification)
162
+ # @api public
163
+ # @group Suite Notifications
164
+ #
165
+ # Outputs a report of pending examples. This gets invoked
166
+ # after the summary if option is set to do so.
167
+ #
168
+ # @param notification [Notifications::NullNotification]
169
+
170
+ # @method close(notification)
171
+ # @api public
172
+ # @group Suite Notifications
173
+ #
174
+ # Invoked at the end of a suite run. Allows the formatter to do any
175
+ # tidying up, but be aware that formatter output streams may be used
176
+ # elsewhere so don't actually close them.
177
+ #
178
+ # @param notification [Notifications::NullNotification]
179
+ end
180
+ end
181
+ end
182
+ end