rspec-core 2.99.0 → 3.0.0
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.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +339 -1
- data/License.txt +1 -0
- data/README.md +19 -37
- data/exe/rspec +2 -23
- data/lib/rspec/core/backport_random.rb +336 -0
- data/lib/rspec/core/backtrace_formatter.rb +70 -0
- data/lib/rspec/core/configuration.rb +479 -577
- data/lib/rspec/core/configuration_options.rb +71 -54
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +86 -18
- data/lib/rspec/core/example.rb +267 -119
- data/lib/rspec/core/example_group.rb +381 -393
- data/lib/rspec/core/filter_manager.rb +133 -114
- data/lib/rspec/core/flat_map.rb +18 -0
- data/lib/rspec/core/formatters/base_formatter.rb +51 -125
- data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
- data/lib/rspec/core/formatters/console_codes.rb +24 -1
- data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
- data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
- data/lib/rspec/core/formatters/helpers.rb +14 -36
- data/lib/rspec/core/formatters/html_formatter.rb +58 -65
- data/lib/rspec/core/formatters/html_printer.rb +12 -18
- data/lib/rspec/core/formatters/json_formatter.rb +54 -31
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
- data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
- data/lib/rspec/core/formatters.rb +90 -43
- data/lib/rspec/core/hooks.rb +325 -270
- data/lib/rspec/core/memoized_helpers.rb +45 -156
- data/lib/rspec/core/metadata.rb +284 -236
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
- data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
- data/lib/rspec/core/mocking_adapters/null.rb +12 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
- data/lib/rspec/core/notifications.rb +511 -0
- data/lib/rspec/core/option_parser.rb +49 -74
- data/lib/rspec/core/ordering.rb +156 -0
- data/lib/rspec/core/pending.rb +94 -96
- data/lib/rspec/core/project_initializer/.rspec +3 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
- data/lib/rspec/core/project_initializer.rb +24 -64
- data/lib/rspec/core/rake_task.rb +44 -130
- data/lib/rspec/core/reporter.rb +76 -59
- data/lib/rspec/core/ruby_project.rb +2 -1
- data/lib/rspec/core/runner.rb +117 -52
- data/lib/rspec/core/shared_context.rb +10 -10
- data/lib/rspec/core/shared_example_group.rb +108 -121
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +66 -10
- data/lib/rspec/core.rb +64 -104
- data.tar.gz.sig +3 -0
- metadata +75 -322
- metadata.gz.sig +1 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/README.md +0 -17
- data/features/Upgrade.md +0 -364
- data/features/command_line/README.md +0 -28
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -18
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -53
- data/features/command_line/order.feature +0 -26
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -22
- data/features/command_line/tag.feature +0 -98
- data/features/command_line/warnings_option.feature +0 -29
- data/features/configuration/alias_example_to.feature +0 -48
- data/features/configuration/backtrace_clean_patterns.feature +0 -102
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/deprecation_stream.feature +0 -58
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/failure_exit_code.feature +0 -36
- data/features/configuration/order_and_seed.feature +0 -3
- data/features/configuration/output_stream.feature +0 -24
- data/features/configuration/pattern.feature +0 -38
- data/features/configuration/profile.feature +0 -220
- data/features/configuration/read_options_from_file.feature +0 -90
- data/features/configuration/run_all_when_everything_filtered.feature +0 -76
- data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
- data/features/example_groups/basic_structure.feature +0 -55
- data/features/example_groups/shared_context.feature +0 -74
- data/features/example_groups/shared_examples.feature +0 -294
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
- data/features/filtering/exclusion_filters.feature +0 -138
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -36
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/text_formatter.feature +0 -46
- data/features/helper_methods/arbitrary_methods.feature +0 -40
- data/features/helper_methods/let.feature +0 -50
- data/features/helper_methods/modules.feature +0 -149
- data/features/hooks/around_hooks.feature +0 -343
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -113
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -96
- data/features/mock_framework_integration/use_mocha.feature +0 -97
- data/features/mock_framework_integration/use_rr.feature +0 -98
- data/features/mock_framework_integration/use_rspec.feature +0 -97
- data/features/pending/pending_examples.feature +0 -229
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -49
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/explicit_subject.feature +0 -101
- data/features/subject/implicit_subject.feature +0 -63
- data/features/subject/one_liner_syntax.feature +0 -71
- data/features/support/env.rb +0 -14
- data/features/support/rubinius.rb +0 -6
- data/lib/autotest/discover.rb +0 -10
- data/lib/autotest/rspec2.rb +0 -77
- data/lib/rspec/core/backtrace_cleaner.rb +0 -46
- data/lib/rspec/core/backward_compatibility.rb +0 -55
- data/lib/rspec/core/caller_filter.rb +0 -60
- data/lib/rspec/core/command_line.rb +0 -47
- data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
- data/lib/rspec/core/deprecation.rb +0 -26
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
- data/lib/rspec/core/extensions/kernel.rb +0 -9
- data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
- data/lib/rspec/core/extensions/ordered.rb +0 -27
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/metadata_hash_builder.rb +0 -97
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
- data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -27
- data/lib/rspec/core/shared_example_group/collection.rb +0 -45
- data/spec/autotest/discover_spec.rb +0 -49
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -133
- data/spec/command_line/order_spec.rb +0 -204
- data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
- data/spec/rspec/core/caller_filter_spec.rb +0 -58
- data/spec/rspec/core/command_line_spec.rb +0 -127
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -417
- data/spec/rspec/core/configuration_spec.rb +0 -2072
- data/spec/rspec/core/deprecation_spec.rb +0 -27
- data/spec/rspec/core/deprecations_spec.rb +0 -59
- data/spec/rspec/core/drb_command_line_spec.rb +0 -102
- data/spec/rspec/core/drb_options_spec.rb +0 -193
- data/spec/rspec/core/dsl_spec.rb +0 -25
- data/spec/rspec/core/example_group_spec.rb +0 -1337
- data/spec/rspec/core/example_spec.rb +0 -502
- data/spec/rspec/core/filter_manager_spec.rb +0 -246
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
- data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -269
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
- data/spec/rspec/core/metadata_spec.rb +0 -514
- data/spec/rspec/core/option_parser_spec.rb +0 -297
- data/spec/rspec/core/pending_example_spec.rb +0 -260
- data/spec/rspec/core/pending_spec.rb +0 -27
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -202
- data/spec/rspec/core/reporter_spec.rb +0 -167
- data/spec/rspec/core/resources/a_bar.rb +0 -0
- data/spec/rspec/core/resources/a_foo.rb +0 -0
- data/spec/rspec/core/resources/a_spec.rb +0 -1
- data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
- data/spec/rspec/core/resources/formatter_specs.rb +0 -60
- data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
- data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
- data/spec/rspec/core/ruby_project_spec.rb +0 -26
- data/spec/rspec/core/runner_spec.rb +0 -82
- data/spec/rspec/core/shared_context_spec.rb +0 -114
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
- data/spec/rspec/core/shared_example_group_spec.rb +0 -138
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -108
- data/spec/spec_helper.rb +0 -135
- data/spec/support/config_options_helper.rb +0 -15
- data/spec/support/helper_methods.rb +0 -55
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/isolate_load_path_mutation.rb +0 -6
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/matchers.rb +0 -65
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/sandboxed_mock_space.rb +0 -116
- data/spec/support/shared_example_groups.rb +0 -42
- data/spec/support/silence_dsl_deprecations.rb +0 -32
- data/spec/support/spec_files.rb +0 -44
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/base_formatter"
|
|
2
|
+
RSpec::Support.require_rspec_core "formatters/console_codes"
|
|
3
3
|
|
|
4
4
|
module RSpec
|
|
5
5
|
module Core
|
|
@@ -11,319 +11,67 @@ module RSpec
|
|
|
11
11
|
# @see RSpec::Core::Formatters::BaseFormatter
|
|
12
12
|
# @see RSpec::Core::Reporter
|
|
13
13
|
class BaseTextFormatter < BaseFormatter
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def dump_failures
|
|
19
|
-
return if failed_examples.empty?
|
|
20
|
-
output.puts
|
|
21
|
-
output.puts "Failures:"
|
|
22
|
-
failed_examples.each_with_index do |example, index|
|
|
23
|
-
output.puts
|
|
24
|
-
pending_fixed?(example) ? dump_pending_fixed(example, index) : dump_failure(example, index)
|
|
25
|
-
dump_backtrace(example)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
14
|
+
Formatters.register self, :message, :dump_summary, :dump_failures,
|
|
15
|
+
:dump_pending, :seed
|
|
28
16
|
|
|
17
|
+
# @method message
|
|
29
18
|
# @api public
|
|
30
19
|
#
|
|
31
|
-
#
|
|
32
|
-
# pending, and green otherwise.
|
|
20
|
+
# Used by the reporter to send messages to the output stream.
|
|
33
21
|
#
|
|
34
|
-
# @param [
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
color(summary, RSpec.configuration.failure_color)
|
|
38
|
-
elsif pending_count > 0
|
|
39
|
-
color(summary, RSpec.configuration.pending_color)
|
|
40
|
-
else
|
|
41
|
-
color(summary, RSpec.configuration.success_color)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def dump_summary(duration, example_count, failure_count, pending_count)
|
|
46
|
-
super(duration, example_count, failure_count, pending_count)
|
|
47
|
-
dump_profile unless mute_profile_output?(failure_count)
|
|
48
|
-
output.puts "\nFinished in #{format_duration(duration)}\n"
|
|
49
|
-
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
|
|
50
|
-
dump_commands_to_rerun_failed_examples
|
|
22
|
+
# @param notification [MessageNotification] containing message
|
|
23
|
+
def message(notification)
|
|
24
|
+
output.puts notification.message
|
|
51
25
|
end
|
|
52
26
|
|
|
27
|
+
# @method dump_failures
|
|
53
28
|
# @api public
|
|
54
29
|
#
|
|
55
|
-
#
|
|
30
|
+
# Dumps detailed information about each example failure.
|
|
56
31
|
#
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
output.puts
|
|
61
|
-
output.puts
|
|
62
|
-
|
|
63
|
-
failed_examples.each do |example|
|
|
64
|
-
output.puts(failure_color("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + detail_color("# #{example.full_description}"))
|
|
65
|
-
end
|
|
32
|
+
# @param notification [NullNotification]
|
|
33
|
+
def dump_failures(notification)
|
|
34
|
+
return if notification.failure_notifications.empty?
|
|
35
|
+
output.puts notification.fully_formatted_failed_examples
|
|
66
36
|
end
|
|
67
37
|
|
|
38
|
+
# @method dump_summary
|
|
68
39
|
# @api public
|
|
69
40
|
#
|
|
70
|
-
#
|
|
41
|
+
# This method is invoked after the dumping of examples and failures. Each parameter
|
|
42
|
+
# is assigned to a corresponding attribute.
|
|
71
43
|
#
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
44
|
+
# @param summary [SummaryNotification] containing duration, example_count,
|
|
45
|
+
# failure_count and pending_count
|
|
46
|
+
def dump_summary(summary)
|
|
47
|
+
output.puts summary.fully_formatted
|
|
75
48
|
end
|
|
76
49
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
total, slows = [examples, sorted_examples].map {|exs|
|
|
83
|
-
exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }}
|
|
84
|
-
|
|
85
|
-
time_taken = slows / total
|
|
86
|
-
percentage = '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
|
|
87
|
-
|
|
88
|
-
output.puts "\nTop #{sorted_examples.size} slowest examples (#{format_seconds(slows)} seconds, #{percentage}% of total time):\n"
|
|
89
|
-
|
|
90
|
-
sorted_examples.each do |example|
|
|
91
|
-
output.puts " #{example.full_description}"
|
|
92
|
-
output.puts detail_color(" #{failure_color(format_seconds(example.execution_result[:run_time]))} #{failure_color("seconds")} #{format_caller(example.location)}")
|
|
93
|
-
end
|
|
50
|
+
# @private
|
|
51
|
+
def dump_pending(notification)
|
|
52
|
+
return if notification.pending_examples.empty?
|
|
53
|
+
output.puts notification.fully_formatted_pending_examples
|
|
94
54
|
end
|
|
95
55
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
examples.each do |example|
|
|
101
|
-
location = example.example_group.parent_groups.last.metadata[:example_group][:location]
|
|
102
|
-
|
|
103
|
-
example_groups[location] ||= Hash.new(0)
|
|
104
|
-
example_groups[location][:total_time] += example.execution_result[:run_time]
|
|
105
|
-
example_groups[location][:count] += 1
|
|
106
|
-
example_groups[location][:description] = example.example_group.top_level_description unless example_groups[location].has_key?(:description)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# stop if we've only one example group
|
|
110
|
-
return if example_groups.keys.length <= 1
|
|
111
|
-
|
|
112
|
-
example_groups.each do |loc, hash|
|
|
113
|
-
hash[:average] = hash[:total_time].to_f / hash[:count]
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
sorted_groups = example_groups.sort_by {|_, hash| -hash[:average]}.first(number_of_examples)
|
|
117
|
-
|
|
118
|
-
output.puts "\nTop #{sorted_groups.size} slowest example groups:"
|
|
119
|
-
sorted_groups.each do |loc, hash|
|
|
120
|
-
average = "#{failure_color(format_seconds(hash[:average]))} #{failure_color("seconds")} average"
|
|
121
|
-
total = "#{format_seconds(hash[:total_time])} seconds"
|
|
122
|
-
count = pluralize(hash[:count], "example")
|
|
123
|
-
output.puts " #{hash[:description]}"
|
|
124
|
-
output.puts detail_color(" #{average} (#{total} / #{count}) #{loc}")
|
|
125
|
-
end
|
|
56
|
+
# @private
|
|
57
|
+
def seed(notification)
|
|
58
|
+
return unless notification.seed_used?
|
|
59
|
+
output.puts notification.fully_formatted
|
|
126
60
|
end
|
|
127
61
|
|
|
128
62
|
# @api public
|
|
129
63
|
#
|
|
130
|
-
#
|
|
64
|
+
# Invoked at the very end, `close` allows the formatter to clean
|
|
65
|
+
# up resources, e.g. open streams, etc.
|
|
131
66
|
#
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
summary << ", " << pluralize(failure_count, "failure")
|
|
135
|
-
summary << ", #{pending_count} pending" if pending_count > 0
|
|
136
|
-
summary
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def dump_pending
|
|
140
|
-
unless pending_examples.empty?
|
|
141
|
-
output.puts
|
|
142
|
-
output.puts "Pending:"
|
|
143
|
-
pending_examples.each do |pending_example|
|
|
144
|
-
output.puts pending_color(" #{pending_example.full_description}")
|
|
145
|
-
output.puts detail_color(" # #{pending_example.execution_result[:pending_message]}")
|
|
146
|
-
output.puts detail_color(" # #{format_caller(pending_example.location)}")
|
|
147
|
-
# instance_variable_get is a hack to avoid a deprecation warning,
|
|
148
|
-
# it's only for 2.99.
|
|
149
|
-
if pending_example.execution_result[:exception] \
|
|
150
|
-
&& RSpec.configuration.instance_variable_get(:@show_failures_in_pending_blocks)
|
|
151
|
-
dump_failure_info(pending_example)
|
|
152
|
-
dump_backtrace(pending_example)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def seed(number)
|
|
159
|
-
output.puts
|
|
160
|
-
output.puts "Randomized with seed #{number}"
|
|
161
|
-
output.puts
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def close
|
|
67
|
+
# @param notification [NullNotification]
|
|
68
|
+
def close(notification)
|
|
165
69
|
return unless IO === output
|
|
166
70
|
return if output.closed? || output == $stdout
|
|
167
71
|
|
|
168
72
|
output.close
|
|
169
73
|
end
|
|
170
74
|
|
|
171
|
-
def self.const_missing(name)
|
|
172
|
-
base = "RSpec::Core::Formatters::"
|
|
173
|
-
case name
|
|
174
|
-
when :VT100_COLORS then
|
|
175
|
-
RSpec.deprecate("#{base}#{name}", :replacement => "#{base}ConsoleCodes::VT100_CODES")
|
|
176
|
-
RSpec::Core::Formatters::ConsoleCodes::VT100_CODES
|
|
177
|
-
when :VT100_COLOR_CODES then
|
|
178
|
-
RSpec.deprecate("#{base}#{name}", :replacement => "#{base}ConsoleCodes::VT100_CODE_VALUES")
|
|
179
|
-
require 'set'
|
|
180
|
-
RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.to_set
|
|
181
|
-
else
|
|
182
|
-
super
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def color_code_for(code_or_symbol)
|
|
187
|
-
ConsoleCodes.console_code_for(code_or_symbol)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def colorize(text, code_or_symbol)
|
|
191
|
-
ConsoleCodes.wrap(text, code_or_symbol)
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
protected
|
|
195
|
-
|
|
196
|
-
def bold(text)
|
|
197
|
-
ConsoleCodes.wrap(text, :bold)
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def color(text, color_code)
|
|
201
|
-
ConsoleCodes.wrap(text, color_code)
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
def failure_color(text)
|
|
205
|
-
color(text, RSpec.configuration.failure_color)
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
def success_color(text)
|
|
209
|
-
color(text, RSpec.configuration.success_color)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def pending_color(text)
|
|
213
|
-
color(text, RSpec.configuration.pending_color)
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def fixed_color(text)
|
|
217
|
-
color(text, RSpec.configuration.fixed_color)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def detail_color(text)
|
|
221
|
-
color(text, RSpec.configuration.detail_color)
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
def default_color(text)
|
|
225
|
-
color(text, RSpec.configuration.default_color)
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
def red(text)
|
|
229
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", :replacement => "#failure_color")
|
|
230
|
-
color(text, :red)
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
def green(text)
|
|
234
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", :replacement => "#success_color")
|
|
235
|
-
color(text, :green)
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def yellow(text)
|
|
239
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", :replacement => "#pending_color")
|
|
240
|
-
color(text, :yellow)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def blue(text)
|
|
244
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", :replacement => "#fixed_color")
|
|
245
|
-
color(text, :blue)
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
def magenta(text)
|
|
249
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta")
|
|
250
|
-
color(text, :magenta)
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
def cyan(text)
|
|
254
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", :replacement => "#detail_color")
|
|
255
|
-
color(text, :cyan)
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
def white(text)
|
|
259
|
-
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", :replacement => "#default_color")
|
|
260
|
-
color(text, :white)
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def short_padding
|
|
264
|
-
' '
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
def long_padding
|
|
268
|
-
' '
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
private
|
|
272
|
-
|
|
273
|
-
def format_caller(caller_info)
|
|
274
|
-
backtrace_line(caller_info.to_s.split(':in `block').first)
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
def dump_backtrace(example)
|
|
278
|
-
format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info|
|
|
279
|
-
output.puts detail_color("#{long_padding}# #{backtrace_info}")
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
def dump_pending_fixed(example, index)
|
|
284
|
-
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
|
|
285
|
-
output.puts fixed_color("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def pending_fixed?(example)
|
|
289
|
-
example.execution_result[:pending_fixed]
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
def dump_failure(example, index)
|
|
293
|
-
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
|
|
294
|
-
dump_failure_info(example)
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
def dump_failure_info(example)
|
|
298
|
-
exception = example.execution_result[:exception]
|
|
299
|
-
exception_class_name = exception_class_name_for(exception)
|
|
300
|
-
output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
|
|
301
|
-
output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/
|
|
302
|
-
exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
|
|
303
|
-
|
|
304
|
-
if shared_group = find_shared_group(example)
|
|
305
|
-
dump_shared_failure_info(shared_group)
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def exception_class_name_for(exception)
|
|
310
|
-
name = exception.class.name.to_s
|
|
311
|
-
name ="(anonymous error class)" if name == ''
|
|
312
|
-
name
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
def dump_shared_failure_info(group)
|
|
316
|
-
output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
|
|
317
|
-
"#{backtrace_line(group.metadata[:example_group][:location])}"
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
def find_shared_group(example)
|
|
321
|
-
group_and_parent_groups(example).find {|group| group.metadata[:shared_group_name]}
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
def group_and_parent_groups(example)
|
|
325
|
-
example.example_group.parent_groups + [example.example_group]
|
|
326
|
-
end
|
|
327
75
|
end
|
|
328
76
|
end
|
|
329
77
|
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module RSpec
|
|
2
2
|
module Core
|
|
3
3
|
module Formatters
|
|
4
|
+
# ConsoleCodes provides helpers for formatting console output
|
|
5
|
+
# with ANSI codes, e.g. color's and bold.
|
|
4
6
|
module ConsoleCodes
|
|
7
|
+
# @private
|
|
5
8
|
VT100_CODES =
|
|
6
9
|
{
|
|
7
10
|
:black => 30,
|
|
@@ -14,12 +17,20 @@ module RSpec
|
|
|
14
17
|
:white => 37,
|
|
15
18
|
:bold => 1,
|
|
16
19
|
}
|
|
20
|
+
# @private
|
|
17
21
|
VT100_CODE_VALUES = VT100_CODES.invert
|
|
18
22
|
|
|
19
23
|
module_function
|
|
20
24
|
|
|
25
|
+
# Fetches the correct code for the supplied symbol, or checks
|
|
26
|
+
# that a code is valid. Defaults to white (37).
|
|
27
|
+
#
|
|
28
|
+
# @param code_or_symbol [Symbol, Fixnum] Symbol or code to check
|
|
29
|
+
# @return [Fixnum] a console code
|
|
21
30
|
def console_code_for(code_or_symbol)
|
|
22
|
-
if
|
|
31
|
+
if RSpec.configuration.respond_to?(:"#{code_or_symbol}_color")
|
|
32
|
+
console_code_for configuration_color(code_or_symbol)
|
|
33
|
+
elsif VT100_CODE_VALUES.has_key?(code_or_symbol)
|
|
23
34
|
code_or_symbol
|
|
24
35
|
else
|
|
25
36
|
VT100_CODES.fetch(code_or_symbol) do
|
|
@@ -28,6 +39,13 @@ module RSpec
|
|
|
28
39
|
end
|
|
29
40
|
end
|
|
30
41
|
|
|
42
|
+
# Wraps a piece of text in ANSI codes with the supplied code. Will
|
|
43
|
+
# only apply the control code if `RSpec.configuration.color_enabled?`
|
|
44
|
+
# returns true.
|
|
45
|
+
#
|
|
46
|
+
# @param text [String] the text to wrap
|
|
47
|
+
# @param code_or_symbol [Symbol, Fixnum] the desired control code
|
|
48
|
+
# @return [String] the wrapped text
|
|
31
49
|
def wrap(text, code_or_symbol)
|
|
32
50
|
if RSpec.configuration.color_enabled?
|
|
33
51
|
"\e[#{console_code_for(code_or_symbol)}m#{text}\e[0m"
|
|
@@ -36,6 +54,11 @@ module RSpec
|
|
|
36
54
|
end
|
|
37
55
|
end
|
|
38
56
|
|
|
57
|
+
# @private
|
|
58
|
+
def configuration_color(code)
|
|
59
|
+
RSpec.configuration.__send__(:"#{code}_color")
|
|
60
|
+
end
|
|
61
|
+
|
|
39
62
|
end
|
|
40
63
|
end
|
|
41
64
|
end
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/helpers"
|
|
2
2
|
require 'set'
|
|
3
3
|
|
|
4
4
|
module RSpec
|
|
5
5
|
module Core
|
|
6
6
|
module Formatters
|
|
7
|
+
# @private
|
|
7
8
|
class DeprecationFormatter
|
|
9
|
+
Formatters.register self, :deprecation, :deprecation_summary
|
|
10
|
+
|
|
8
11
|
attr_reader :count, :deprecation_stream, :summary_stream
|
|
9
12
|
|
|
10
13
|
def initialize(deprecation_stream, summary_stream)
|
|
@@ -13,6 +16,7 @@ module RSpec
|
|
|
13
16
|
@seen_deprecations = Set.new
|
|
14
17
|
@count = 0
|
|
15
18
|
end
|
|
19
|
+
alias :output :deprecation_stream
|
|
16
20
|
|
|
17
21
|
def printer
|
|
18
22
|
@printer ||= case deprecation_stream
|
|
@@ -25,24 +29,20 @@ module RSpec
|
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
|
-
def deprecation(
|
|
29
|
-
return if @seen_deprecations.include?
|
|
32
|
+
def deprecation(notification)
|
|
33
|
+
return if @seen_deprecations.include? notification
|
|
30
34
|
|
|
31
35
|
@count += 1
|
|
32
|
-
printer.print_deprecation_message
|
|
33
|
-
@seen_deprecations <<
|
|
36
|
+
printer.print_deprecation_message notification
|
|
37
|
+
@seen_deprecations << notification
|
|
34
38
|
end
|
|
35
39
|
|
|
36
|
-
def deprecation_summary
|
|
40
|
+
def deprecation_summary(notification)
|
|
37
41
|
printer.deprecation_summary
|
|
38
42
|
end
|
|
39
43
|
|
|
40
|
-
def start(example_count=nil)
|
|
41
|
-
#no-op to fix #966
|
|
42
|
-
end
|
|
43
|
-
|
|
44
44
|
def deprecation_message_for(data)
|
|
45
|
-
if data
|
|
45
|
+
if data.message
|
|
46
46
|
SpecifiedDeprecationMessage.new(data)
|
|
47
47
|
else
|
|
48
48
|
GeneratedDeprecationMessage.new(data)
|
|
@@ -62,7 +62,7 @@ module RSpec
|
|
|
62
62
|
|
|
63
63
|
SpecifiedDeprecationMessage = Struct.new(:type) do
|
|
64
64
|
def initialize(data)
|
|
65
|
-
@message = data
|
|
65
|
+
@message = data.message
|
|
66
66
|
super deprecation_type_for(data)
|
|
67
67
|
end
|
|
68
68
|
|
|
@@ -85,20 +85,20 @@ module RSpec
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def deprecation_type_for(data)
|
|
88
|
-
data
|
|
88
|
+
data.message.gsub(/(\w+\/)+\w+\.rb:\d+/, '')
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
GeneratedDeprecationMessage = Struct.new(:type) do
|
|
93
93
|
def initialize(data)
|
|
94
94
|
@data = data
|
|
95
|
-
super data.
|
|
95
|
+
super data.deprecated
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
def to_s
|
|
99
|
-
msg = "#{@data
|
|
100
|
-
msg << " Use #{@data
|
|
101
|
-
msg << " Called from #{@data
|
|
99
|
+
msg = "#{@data.deprecated} is deprecated."
|
|
100
|
+
msg << " Use #{@data.replacement} instead." if @data.replacement
|
|
101
|
+
msg << " Called from #{@data.call_site}." if @data.call_site
|
|
102
102
|
msg
|
|
103
103
|
end
|
|
104
104
|
|
|
@@ -109,6 +109,7 @@ module RSpec
|
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
# @private
|
|
112
113
|
class ImmediatePrinter
|
|
113
114
|
attr_reader :deprecation_stream, :summary_stream, :deprecation_formatter
|
|
114
115
|
|
|
@@ -130,11 +131,10 @@ module RSpec
|
|
|
130
131
|
end
|
|
131
132
|
end
|
|
132
133
|
|
|
134
|
+
# @private
|
|
133
135
|
class DelayedPrinter
|
|
134
136
|
TOO_MANY_USES_LIMIT = 4
|
|
135
137
|
|
|
136
|
-
include ::RSpec::Core::Formatters::Helpers
|
|
137
|
-
|
|
138
138
|
attr_reader :deprecation_stream, :summary_stream, :deprecation_formatter
|
|
139
139
|
|
|
140
140
|
def initialize(deprecation_stream, summary_stream, deprecation_formatter)
|
|
@@ -166,7 +166,7 @@ module RSpec
|
|
|
166
166
|
print_deferred_deprecation_warnings
|
|
167
167
|
deprecation_stream.puts RAISE_ERROR_CONFIG_NOTICE
|
|
168
168
|
|
|
169
|
-
summary_stream.puts "\n#{pluralize(deprecation_formatter.count, 'deprecation warning')} total"
|
|
169
|
+
summary_stream.puts "\n#{Helpers.pluralize(deprecation_formatter.count, 'deprecation warning')} total"
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
def print_deferred_deprecation_warnings
|
|
@@ -179,23 +179,21 @@ module RSpec
|
|
|
179
179
|
end
|
|
180
180
|
end
|
|
181
181
|
|
|
182
|
+
# @private
|
|
182
183
|
# Not really a stream, but is usable in place of one.
|
|
183
184
|
class RaiseErrorStream
|
|
184
|
-
include ::RSpec::Core::Formatters::Helpers
|
|
185
|
-
|
|
186
185
|
def puts(message)
|
|
187
186
|
raise DeprecationError, message
|
|
188
187
|
end
|
|
189
188
|
|
|
190
189
|
def summarize(summary_stream, deprecation_count)
|
|
191
|
-
summary_stream.puts "\n#{pluralize(deprecation_count, 'deprecation')} found."
|
|
190
|
+
summary_stream.puts "\n#{Helpers.pluralize(deprecation_count, 'deprecation')} found."
|
|
192
191
|
end
|
|
193
192
|
end
|
|
194
193
|
|
|
194
|
+
# @private
|
|
195
195
|
# Wraps a File object and provides file-specific operations.
|
|
196
196
|
class FileStream
|
|
197
|
-
include ::RSpec::Core::Formatters::Helpers
|
|
198
|
-
|
|
199
197
|
def initialize(file)
|
|
200
198
|
@file = file
|
|
201
199
|
|
|
@@ -211,7 +209,7 @@ module RSpec
|
|
|
211
209
|
end
|
|
212
210
|
|
|
213
211
|
def summarize(summary_stream, deprecation_count)
|
|
214
|
-
summary_stream.puts "\n#{pluralize(deprecation_count, 'deprecation')} logged to #{@file.path}"
|
|
212
|
+
summary_stream.puts "\n#{Helpers.pluralize(deprecation_count, 'deprecation')} logged to #{@file.path}"
|
|
215
213
|
puts RAISE_ERROR_CONFIG_NOTICE
|
|
216
214
|
end
|
|
217
215
|
end
|
|
@@ -219,6 +217,7 @@ module RSpec
|
|
|
219
217
|
end
|
|
220
218
|
end
|
|
221
219
|
|
|
220
|
+
# Deprecation Error
|
|
222
221
|
DeprecationError = Class.new(StandardError)
|
|
223
222
|
end
|
|
224
223
|
end
|
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
|
|
2
2
|
|
|
3
3
|
module RSpec
|
|
4
4
|
module Core
|
|
5
5
|
module Formatters
|
|
6
|
+
# @private
|
|
6
7
|
class DocumentationFormatter < BaseTextFormatter
|
|
8
|
+
Formatters.register self, :example_group_started, :example_group_finished,
|
|
9
|
+
:example_passed, :example_pending, :example_failed
|
|
10
|
+
|
|
7
11
|
def initialize(output)
|
|
8
|
-
super
|
|
12
|
+
super
|
|
9
13
|
@group_level = 0
|
|
10
14
|
end
|
|
11
15
|
|
|
12
|
-
def example_group_started(
|
|
13
|
-
super(example_group)
|
|
14
|
-
|
|
16
|
+
def example_group_started(notification)
|
|
15
17
|
output.puts if @group_level == 0
|
|
16
|
-
output.puts "#{current_indentation}#{
|
|
18
|
+
output.puts "#{current_indentation}#{notification.group.description.strip}"
|
|
17
19
|
|
|
18
20
|
@group_level += 1
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
def example_group_finished(
|
|
23
|
+
def example_group_finished(notification)
|
|
22
24
|
@group_level -= 1
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
def example_passed(
|
|
26
|
-
|
|
27
|
-
output.puts passed_output(example)
|
|
27
|
+
def example_passed(passed)
|
|
28
|
+
output.puts passed_output(passed.example)
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
def example_pending(
|
|
31
|
-
|
|
32
|
-
output.puts pending_output(example, example.execution_result[:pending_message])
|
|
31
|
+
def example_pending(pending)
|
|
32
|
+
output.puts pending_output(pending.example, pending.example.execution_result.pending_message)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def example_failed(
|
|
36
|
-
|
|
37
|
-
output.puts failure_output(example, example.execution_result[:exception])
|
|
35
|
+
def example_failed(failure)
|
|
36
|
+
output.puts failure_output(failure.example, failure.example.execution_result.exception)
|
|
38
37
|
end
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def passed_output(example)
|
|
42
|
+
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
|
|
42
43
|
end
|
|
43
44
|
|
|
44
|
-
def
|
|
45
|
-
|
|
46
|
-
@next_failure_index += 1
|
|
45
|
+
def pending_output(example, message)
|
|
46
|
+
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (PENDING: #{message})", :pending)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def
|
|
50
|
-
|
|
49
|
+
def failure_output(example, exception)
|
|
50
|
+
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})", :failure)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def
|
|
54
|
-
|
|
53
|
+
def next_failure_index
|
|
54
|
+
@next_failure_index ||= 0
|
|
55
|
+
@next_failure_index += 1
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
def current_indentation
|
|
@@ -61,6 +62,7 @@ module RSpec
|
|
|
61
62
|
def example_group_chain
|
|
62
63
|
example_group.parent_groups.reverse
|
|
63
64
|
end
|
|
65
|
+
|
|
64
66
|
end
|
|
65
67
|
end
|
|
66
68
|
end
|