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,48 +1,26 @@
|
|
|
1
1
|
module RSpec
|
|
2
2
|
module Core
|
|
3
|
-
module BacktraceFormatter
|
|
4
|
-
extend self
|
|
5
|
-
|
|
6
|
-
def format_backtrace(backtrace, options = {})
|
|
7
|
-
return "" unless backtrace
|
|
8
|
-
return backtrace if options[:full_backtrace] == true
|
|
9
|
-
|
|
10
|
-
if at_exit_index = backtrace.index(RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE)
|
|
11
|
-
backtrace = backtrace[0, at_exit_index]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
cleansed = backtrace.map { |line| backtrace_line(line) }.compact
|
|
15
|
-
cleansed.empty? ? backtrace : cleansed
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
protected
|
|
19
|
-
|
|
20
|
-
def backtrace_line(line)
|
|
21
|
-
return nil if RSpec.configuration.backtrace_formatter.exclude?(line)
|
|
22
|
-
RSpec::Core::Metadata::relative_path(line)
|
|
23
|
-
rescue SecurityError
|
|
24
|
-
nil
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
3
|
module Formatters
|
|
4
|
+
# Formatters helpers
|
|
29
5
|
module Helpers
|
|
30
|
-
include BacktraceFormatter
|
|
31
6
|
|
|
7
|
+
# @private
|
|
32
8
|
SUB_SECOND_PRECISION = 5
|
|
9
|
+
|
|
10
|
+
# @private
|
|
33
11
|
DEFAULT_PRECISION = 2
|
|
34
12
|
|
|
35
13
|
# @api private
|
|
36
14
|
#
|
|
37
15
|
# Formats seconds into a human-readable string.
|
|
38
16
|
#
|
|
39
|
-
# @param [Float, Fixnum]
|
|
17
|
+
# @param duration [Float, Fixnum] in seconds
|
|
40
18
|
# @return [String] human-readable time
|
|
41
19
|
#
|
|
42
20
|
# @example
|
|
43
21
|
# format_duration(1) #=> "1 minute 1 second"
|
|
44
22
|
# format_duration(135.14) #=> "2 minutes 15.14 seconds"
|
|
45
|
-
def format_duration(duration)
|
|
23
|
+
def self.format_duration(duration)
|
|
46
24
|
precision = case
|
|
47
25
|
when duration < 1; SUB_SECOND_PRECISION
|
|
48
26
|
when duration < 120; DEFAULT_PRECISION
|
|
@@ -65,7 +43,7 @@ module RSpec
|
|
|
65
43
|
# Formats seconds to have 5 digits of precision with trailing zeros removed if the number
|
|
66
44
|
# is less than 1 or with 2 digits of precision if the number is greater than zero.
|
|
67
45
|
#
|
|
68
|
-
# @param [Float]
|
|
46
|
+
# @param float [Float]
|
|
69
47
|
# @return [String] formatted float
|
|
70
48
|
#
|
|
71
49
|
# @example
|
|
@@ -76,7 +54,7 @@ module RSpec
|
|
|
76
54
|
# The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
|
|
77
55
|
#
|
|
78
56
|
# @see #strip_trailing_zeroes
|
|
79
|
-
def format_seconds(float, precision = nil)
|
|
57
|
+
def self.format_seconds(float, precision = nil)
|
|
80
58
|
precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
|
|
81
59
|
formatted = sprintf("%.#{precision}f", float)
|
|
82
60
|
strip_trailing_zeroes(formatted)
|
|
@@ -86,25 +64,25 @@ module RSpec
|
|
|
86
64
|
#
|
|
87
65
|
# Remove trailing zeros from a string.
|
|
88
66
|
#
|
|
89
|
-
# @param [String] string
|
|
67
|
+
# @param string [String] string with trailing zeros
|
|
90
68
|
# @return [String] string with trailing zeros removed
|
|
91
|
-
def strip_trailing_zeroes(string)
|
|
69
|
+
def self.strip_trailing_zeroes(string)
|
|
92
70
|
stripped = string.sub(/[^1-9]+$/, '')
|
|
93
71
|
stripped.empty? ? "0" : stripped
|
|
94
72
|
end
|
|
73
|
+
private_class_method :strip_trailing_zeroes
|
|
95
74
|
|
|
96
75
|
# @api private
|
|
97
76
|
#
|
|
98
77
|
# Pluralize a word based on a count.
|
|
99
78
|
#
|
|
100
|
-
# @param [Fixnum]
|
|
101
|
-
# @param [String]
|
|
79
|
+
# @param count [Fixnum] number of objects
|
|
80
|
+
# @param string [String] word to be pluralized
|
|
102
81
|
# @return [String] pluralized word
|
|
103
|
-
def pluralize(count, string)
|
|
82
|
+
def self.pluralize(count, string)
|
|
104
83
|
"#{count} #{string}#{'s' unless count.to_f == 1}"
|
|
105
84
|
end
|
|
106
85
|
end
|
|
107
|
-
|
|
108
86
|
end
|
|
109
87
|
end
|
|
110
88
|
end
|
|
@@ -1,75 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
|
|
2
|
+
RSpec::Support.require_rspec_core "formatters/html_printer"
|
|
3
3
|
|
|
4
4
|
module RSpec
|
|
5
5
|
module Core
|
|
6
6
|
module Formatters
|
|
7
|
-
|
|
7
|
+
# @private
|
|
8
|
+
class HtmlFormatter < BaseFormatter
|
|
9
|
+
Formatters.register self, :start, :example_group_started, :start_dump,
|
|
10
|
+
:example_started, :example_passed, :example_failed,
|
|
11
|
+
:example_pending, :dump_summary
|
|
8
12
|
|
|
9
13
|
def initialize(output)
|
|
10
14
|
super(output)
|
|
15
|
+
@failed_examples = []
|
|
11
16
|
@example_group_number = 0
|
|
12
17
|
@example_number = 0
|
|
13
18
|
@header_red = nil
|
|
14
19
|
@printer = HtmlPrinter.new(output)
|
|
15
20
|
end
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# no-op
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
public
|
|
23
|
-
def message(message)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# The number of the currently running example_group
|
|
27
|
-
def example_group_number
|
|
28
|
-
@example_group_number
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# The number of the currently running example (a global counter)
|
|
32
|
-
def example_number
|
|
33
|
-
@example_number
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def start(example_count)
|
|
37
|
-
super(example_count)
|
|
22
|
+
def start(notification)
|
|
23
|
+
super
|
|
38
24
|
@printer.print_html_start
|
|
39
25
|
@printer.flush
|
|
40
26
|
end
|
|
41
27
|
|
|
42
|
-
def example_group_started(
|
|
43
|
-
super
|
|
28
|
+
def example_group_started(notification)
|
|
29
|
+
super
|
|
44
30
|
@example_group_red = false
|
|
45
31
|
@example_group_number += 1
|
|
46
32
|
|
|
47
33
|
unless example_group_number == 1
|
|
48
34
|
@printer.print_example_group_end
|
|
49
35
|
end
|
|
50
|
-
@printer.print_example_group_start( example_group_number,
|
|
36
|
+
@printer.print_example_group_start( example_group_number, notification.group.description, notification.group.parent_groups.size )
|
|
51
37
|
@printer.flush
|
|
52
38
|
end
|
|
53
39
|
|
|
54
|
-
def start_dump
|
|
40
|
+
def start_dump(notification)
|
|
55
41
|
@printer.print_example_group_end
|
|
56
42
|
@printer.flush
|
|
57
43
|
end
|
|
58
44
|
|
|
59
|
-
def example_started(
|
|
60
|
-
super(example)
|
|
45
|
+
def example_started(notification)
|
|
61
46
|
@example_number += 1
|
|
62
47
|
end
|
|
63
48
|
|
|
64
|
-
def example_passed(
|
|
49
|
+
def example_passed(passed)
|
|
65
50
|
@printer.move_progress(percent_done)
|
|
66
|
-
@printer.print_example_passed( example.description, example.execution_result
|
|
51
|
+
@printer.print_example_passed( passed.example.description, passed.example.execution_result.run_time )
|
|
67
52
|
@printer.flush
|
|
68
53
|
end
|
|
69
54
|
|
|
70
|
-
def example_failed(
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
def example_failed(failure)
|
|
56
|
+
@failed_examples << failure.example
|
|
73
57
|
unless @header_red
|
|
74
58
|
@header_red = true
|
|
75
59
|
@printer.make_header_red
|
|
@@ -82,21 +66,23 @@ module RSpec
|
|
|
82
66
|
|
|
83
67
|
@printer.move_progress(percent_done)
|
|
84
68
|
|
|
85
|
-
|
|
69
|
+
example = failure.example
|
|
70
|
+
|
|
71
|
+
exception = failure.exception
|
|
86
72
|
exception_details = if exception
|
|
87
73
|
{
|
|
88
74
|
:message => exception.message,
|
|
89
|
-
:backtrace =>
|
|
75
|
+
:backtrace => failure.formatted_backtrace.join("\n")
|
|
90
76
|
}
|
|
91
77
|
else
|
|
92
78
|
false
|
|
93
79
|
end
|
|
94
|
-
extra = extra_failure_content(
|
|
80
|
+
extra = extra_failure_content(failure)
|
|
95
81
|
|
|
96
82
|
@printer.print_example_failed(
|
|
97
|
-
example.execution_result
|
|
83
|
+
example.execution_result.pending_fixed,
|
|
98
84
|
example.description,
|
|
99
|
-
example.execution_result
|
|
85
|
+
example.execution_result.run_time,
|
|
100
86
|
@failed_examples.size,
|
|
101
87
|
exception_details,
|
|
102
88
|
(extra == "") ? false : extra,
|
|
@@ -105,24 +91,36 @@ module RSpec
|
|
|
105
91
|
@printer.flush
|
|
106
92
|
end
|
|
107
93
|
|
|
108
|
-
def example_pending(
|
|
94
|
+
def example_pending(pending)
|
|
95
|
+
example = pending.example
|
|
109
96
|
|
|
110
97
|
@printer.make_header_yellow unless @header_red
|
|
111
98
|
@printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
|
|
112
99
|
@printer.move_progress(percent_done)
|
|
113
|
-
@printer.print_example_pending( example.description, example.
|
|
100
|
+
@printer.print_example_pending( example.description, example.execution_result.pending_message )
|
|
114
101
|
@printer.flush
|
|
115
102
|
end
|
|
116
103
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
@
|
|
125
|
-
|
|
104
|
+
def dump_summary(summary)
|
|
105
|
+
@printer.print_summary(
|
|
106
|
+
summary.duration,
|
|
107
|
+
summary.example_count,
|
|
108
|
+
summary.failure_count,
|
|
109
|
+
summary.pending_count
|
|
110
|
+
)
|
|
111
|
+
@printer.flush
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
# The number of the currently running example_group
|
|
117
|
+
def example_group_number
|
|
118
|
+
@example_group_number
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# The number of the currently running example (a global counter)
|
|
122
|
+
def example_number
|
|
123
|
+
@example_number
|
|
126
124
|
end
|
|
127
125
|
|
|
128
126
|
def percent_done
|
|
@@ -133,22 +131,17 @@ module RSpec
|
|
|
133
131
|
result
|
|
134
132
|
end
|
|
135
133
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def
|
|
134
|
+
# Override this method if you wish to output extra HTML for a failed spec. For example, you
|
|
135
|
+
# could output links to images or other files produced during the specs.
|
|
136
|
+
#
|
|
137
|
+
def extra_failure_content(failure)
|
|
138
|
+
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
|
|
139
|
+
backtrace = failure.exception.backtrace.map {|line| RSpec.configuration.backtrace_formatter.backtrace_line(line)}
|
|
140
|
+
backtrace.compact!
|
|
141
|
+
@snippet_extractor ||= SnippetExtractor.new
|
|
142
|
+
" <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
|
|
140
143
|
end
|
|
141
144
|
|
|
142
|
-
def dump_summary(duration, example_count, failure_count, pending_count)
|
|
143
|
-
@printer.print_summary(
|
|
144
|
-
dry_run?,
|
|
145
|
-
duration,
|
|
146
|
-
example_count,
|
|
147
|
-
failure_count,
|
|
148
|
-
pending_count
|
|
149
|
-
)
|
|
150
|
-
@printer.flush
|
|
151
|
-
end
|
|
152
145
|
end
|
|
153
146
|
end
|
|
154
147
|
end
|
|
@@ -3,6 +3,7 @@ require 'erb'
|
|
|
3
3
|
module RSpec
|
|
4
4
|
module Core
|
|
5
5
|
module Formatters
|
|
6
|
+
# @private
|
|
6
7
|
class HtmlPrinter
|
|
7
8
|
include ERB::Util # for the #h method
|
|
8
9
|
def initialize(output)
|
|
@@ -19,18 +20,18 @@ module RSpec
|
|
|
19
20
|
@output.puts "</div>"
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
def print_example_group_start(
|
|
23
|
+
def print_example_group_start(group_id, description, number_of_parents)
|
|
23
24
|
@output.puts "<div id=\"div_group_#{group_id}\" class=\"example_group passed\">"
|
|
24
25
|
@output.puts " <dl #{indentation_style(number_of_parents)}>"
|
|
25
26
|
@output.puts " <dt id=\"example_group_#{group_id}\" class=\"passed\">#{h(description)}</dt>"
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
def print_example_passed(
|
|
29
|
+
def print_example_passed(description, run_time)
|
|
29
30
|
formatted_run_time = sprintf("%.5f", run_time)
|
|
30
31
|
@output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(description)}</span><span class='duration'>#{formatted_run_time}s</span></dd>"
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
def print_example_failed(
|
|
34
|
+
def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false)
|
|
34
35
|
formatted_run_time = sprintf("%.5f", run_time)
|
|
35
36
|
|
|
36
37
|
@output.puts " <dd class=\"example #{pending_fixed ? 'pending_fixed' : 'failed'}\">"
|
|
@@ -50,19 +51,14 @@ module RSpec
|
|
|
50
51
|
@output.puts " </dd>"
|
|
51
52
|
end
|
|
52
53
|
|
|
53
|
-
def print_example_pending(
|
|
54
|
+
def print_example_pending(description, pending_message)
|
|
54
55
|
@output.puts " <dd class=\"example not_implemented\"><span class=\"not_implemented_spec_name\">#{h(description)} (PENDING: #{h(pending_message)})</span></dd>"
|
|
55
56
|
end
|
|
56
57
|
|
|
57
|
-
def print_summary(
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
else
|
|
62
|
-
totals = "#{example_count} example#{'s' unless example_count == 1}, "
|
|
63
|
-
totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
|
|
64
|
-
totals << ", #{pending_count} pending" if pending_count > 0
|
|
65
|
-
end
|
|
58
|
+
def print_summary(duration, example_count, failure_count, pending_count)
|
|
59
|
+
totals = "#{example_count} example#{'s' unless example_count == 1}, "
|
|
60
|
+
totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
|
|
61
|
+
totals << ", #{pending_count} pending" if pending_count > 0
|
|
66
62
|
|
|
67
63
|
formatted_duration = sprintf("%.5f", duration)
|
|
68
64
|
|
|
@@ -78,7 +74,7 @@ module RSpec
|
|
|
78
74
|
@output.flush
|
|
79
75
|
end
|
|
80
76
|
|
|
81
|
-
def move_progress(
|
|
77
|
+
def move_progress(percent_done)
|
|
82
78
|
@output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
|
|
83
79
|
@output.flush
|
|
84
80
|
end
|
|
@@ -101,14 +97,12 @@ module RSpec
|
|
|
101
97
|
@output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{group_id}');</script>"
|
|
102
98
|
end
|
|
103
99
|
|
|
100
|
+
private
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def indentation_style( number_of_parents )
|
|
102
|
+
def indentation_style(number_of_parents)
|
|
108
103
|
"style=\"margin-left: #{(number_of_parents - 1) * 15}px;\""
|
|
109
104
|
end
|
|
110
105
|
|
|
111
|
-
|
|
112
106
|
REPORT_HEADER = <<-EOF
|
|
113
107
|
<div class="rspec-report">
|
|
114
108
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/base_formatter"
|
|
2
2
|
require 'json'
|
|
3
3
|
|
|
4
4
|
module RSpec
|
|
5
5
|
module Core
|
|
6
6
|
module Formatters
|
|
7
|
-
|
|
7
|
+
# @private
|
|
8
8
|
class JsonFormatter < BaseFormatter
|
|
9
|
+
Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :close
|
|
9
10
|
|
|
10
11
|
attr_reader :output_hash
|
|
11
12
|
|
|
@@ -14,40 +15,23 @@ module RSpec
|
|
|
14
15
|
@output_hash = {}
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
def message(
|
|
18
|
-
(@output_hash[:messages] ||= []) << message
|
|
18
|
+
def message(notification)
|
|
19
|
+
(@output_hash[:messages] ||= []) << notification.message
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
def dump_summary(
|
|
22
|
-
super(duration, example_count, failure_count, pending_count)
|
|
22
|
+
def dump_summary(summary)
|
|
23
23
|
@output_hash[:summary] = {
|
|
24
|
-
:duration => duration,
|
|
25
|
-
:example_count => example_count,
|
|
26
|
-
:failure_count => failure_count,
|
|
27
|
-
:pending_count => pending_count
|
|
24
|
+
:duration => summary.duration,
|
|
25
|
+
:example_count => summary.example_count,
|
|
26
|
+
:failure_count => summary.failure_count,
|
|
27
|
+
:pending_count => summary.pending_count
|
|
28
28
|
}
|
|
29
|
-
@output_hash[:summary_line] =
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def summary_line(example_count, failure_count, pending_count)
|
|
33
|
-
summary = pluralize(example_count, "example")
|
|
34
|
-
summary << ", " << pluralize(failure_count, "failure")
|
|
35
|
-
summary << ", #{pending_count} pending" if pending_count > 0
|
|
36
|
-
summary
|
|
29
|
+
@output_hash[:summary_line] = summary.totals_line
|
|
37
30
|
end
|
|
38
31
|
|
|
39
|
-
def stop
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
:description => example.description,
|
|
44
|
-
:full_description => example.full_description,
|
|
45
|
-
:status => example.execution_result[:status],
|
|
46
|
-
# :example_group,
|
|
47
|
-
# :execution_result,
|
|
48
|
-
:file_path => example.metadata[:file_path],
|
|
49
|
-
:line_number => example.metadata[:line_number],
|
|
50
|
-
}.tap do |hash|
|
|
32
|
+
def stop(notification)
|
|
33
|
+
@output_hash[:examples] = notification.examples.map do |example|
|
|
34
|
+
format_example(example).tap do |hash|
|
|
51
35
|
if e=example.exception
|
|
52
36
|
hash[:exception] = {
|
|
53
37
|
:class => e.class.name,
|
|
@@ -59,11 +43,50 @@ module RSpec
|
|
|
59
43
|
end
|
|
60
44
|
end
|
|
61
45
|
|
|
62
|
-
def close
|
|
46
|
+
def close(notification)
|
|
63
47
|
output.write @output_hash.to_json
|
|
64
48
|
output.close if IO === output && output != $stdout
|
|
65
49
|
end
|
|
66
50
|
|
|
51
|
+
def dump_profile(profile)
|
|
52
|
+
@output_hash[:profile] = {}
|
|
53
|
+
dump_profile_slowest_examples(profile)
|
|
54
|
+
dump_profile_slowest_example_groups(profile)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @api private
|
|
58
|
+
def dump_profile_slowest_examples(profile)
|
|
59
|
+
@output_hash[:profile] = {}
|
|
60
|
+
sorted_examples = profile.slowest_examples
|
|
61
|
+
@output_hash[:profile][:examples] = sorted_examples.map do |example|
|
|
62
|
+
format_example(example).tap do |hash|
|
|
63
|
+
hash[:run_time] = example.execution_result.run_time
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
@output_hash[:profile][:slowest] = profile.slow_duration
|
|
67
|
+
@output_hash[:profile][:total] = profile.duration
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @api private
|
|
71
|
+
def dump_profile_slowest_example_groups(profile)
|
|
72
|
+
@output_hash[:profile] ||= {}
|
|
73
|
+
@output_hash[:profile][:groups] = profile.slowest_groups.map do |loc, hash|
|
|
74
|
+
hash.update(:location => loc)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def format_example(example)
|
|
81
|
+
{
|
|
82
|
+
:description => example.description,
|
|
83
|
+
:full_description => example.full_description,
|
|
84
|
+
:status => example.execution_result.status.to_s,
|
|
85
|
+
:file_path => example.metadata[:file_path],
|
|
86
|
+
:line_number => example.metadata[:line_number],
|
|
87
|
+
:run_time => example.execution_result.run_time
|
|
88
|
+
}
|
|
89
|
+
end
|
|
67
90
|
end
|
|
68
91
|
end
|
|
69
92
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/console_codes"
|
|
2
|
+
|
|
3
|
+
module RSpec
|
|
4
|
+
module Core
|
|
5
|
+
module Formatters
|
|
6
|
+
|
|
7
|
+
# @api private
|
|
8
|
+
# Formatter for providing profile output
|
|
9
|
+
class ProfileFormatter
|
|
10
|
+
Formatters.register self, :dump_profile
|
|
11
|
+
|
|
12
|
+
def initialize(output)
|
|
13
|
+
@output = output
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @private
|
|
17
|
+
attr_reader :output
|
|
18
|
+
|
|
19
|
+
# @method dump_profile
|
|
20
|
+
# @api public
|
|
21
|
+
#
|
|
22
|
+
# This method is invoked after the dumping the summary if profiling is
|
|
23
|
+
# enabled.
|
|
24
|
+
#
|
|
25
|
+
# @param profile [ProfileNotification] containing duration, slowest_examples
|
|
26
|
+
# and slowest_example_groups
|
|
27
|
+
def dump_profile(profile)
|
|
28
|
+
dump_profile_slowest_examples(profile)
|
|
29
|
+
dump_profile_slowest_example_groups(profile)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def dump_profile_slowest_examples(profile)
|
|
35
|
+
@output.puts "\nTop #{profile.slowest_examples.size} slowest examples (#{Helpers.format_seconds(profile.slow_duration)} 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))} #{bold("seconds")} #{format_caller(example.location)}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def dump_profile_slowest_example_groups(profile)
|
|
44
|
+
return if profile.slowest_groups.empty?
|
|
45
|
+
|
|
46
|
+
@output.puts "\nTop #{profile.slowest_groups.size} slowest example groups:"
|
|
47
|
+
profile.slowest_groups.each do |loc, hash|
|
|
48
|
+
average = "#{bold(Helpers.format_seconds(hash[:average]))} #{bold("seconds")} average"
|
|
49
|
+
total = "#{Helpers.format_seconds(hash[:total_time])} seconds"
|
|
50
|
+
count = Helpers.pluralize(hash[:count], "example")
|
|
51
|
+
@output.puts " #{hash[:description]}"
|
|
52
|
+
@output.puts " #{average} (#{total} / #{count}) #{loc}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def format_caller(caller_info)
|
|
57
|
+
RSpec.configuration.backtrace_formatter.backtrace_line(caller_info.to_s.split(':in `block').first)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def bold(text)
|
|
61
|
+
ConsoleCodes.wrap(text, :bold)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
|
|
2
|
+
|
|
2
3
|
module RSpec
|
|
3
4
|
module Core
|
|
4
5
|
module Formatters
|
|
5
|
-
|
|
6
|
+
# @private
|
|
6
7
|
class ProgressFormatter < BaseTextFormatter
|
|
8
|
+
Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
|
|
7
9
|
|
|
8
|
-
def example_passed(
|
|
9
|
-
|
|
10
|
-
output.print success_color('.')
|
|
10
|
+
def example_passed(notification)
|
|
11
|
+
output.print ConsoleCodes.wrap('.', :success)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
def example_pending(
|
|
14
|
-
|
|
15
|
-
output.print pending_color('*')
|
|
14
|
+
def example_pending(notification)
|
|
15
|
+
output.print ConsoleCodes.wrap('*', :pending)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def example_failed(
|
|
19
|
-
|
|
20
|
-
output.print failure_color('F')
|
|
18
|
+
def example_failed(notification)
|
|
19
|
+
output.print ConsoleCodes.wrap('F', :failure)
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
def start_dump
|
|
24
|
-
super()
|
|
22
|
+
def start_dump(notification)
|
|
25
23
|
output.puts
|
|
26
24
|
end
|
|
27
|
-
|
|
28
25
|
end
|
|
29
|
-
|
|
30
26
|
end
|
|
31
27
|
end
|
|
32
28
|
end
|