rspec-core 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +297 -57
- data/README.md +16 -13
- data/lib/rspec/core.rb +55 -84
- data/lib/rspec/core/backport_random.rb +35 -3
- data/lib/rspec/core/backtrace_formatter.rb +4 -13
- data/lib/rspec/core/configuration.rb +330 -114
- data/lib/rspec/core/configuration_options.rb +38 -22
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +8 -2
- data/lib/rspec/core/example.rb +203 -94
- data/lib/rspec/core/example_group.rb +344 -316
- data/lib/rspec/core/filter_manager.rb +135 -90
- data/lib/rspec/core/flat_map.rb +1 -0
- data/lib/rspec/core/formatters.rb +50 -14
- data/lib/rspec/core/formatters/base_formatter.rb +32 -138
- data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
- data/lib/rspec/core/formatters/console_codes.rb +65 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
- data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
- data/lib/rspec/core/formatters/helpers.rb +15 -9
- data/lib/rspec/core/formatters/html_formatter.rb +17 -16
- data/lib/rspec/core/formatters/html_printer.rb +1 -0
- data/lib/rspec/core/formatters/json_formatter.rb +18 -20
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
- data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
- data/lib/rspec/core/hooks.rb +131 -125
- data/lib/rspec/core/memoized_helpers.rb +31 -26
- data/lib/rspec/core/metadata.rb +277 -184
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
- data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
- data/lib/rspec/core/mocking_adapters/null.rb +1 -1
- data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
- data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
- data/lib/rspec/core/notifications.rb +435 -24
- data/lib/rspec/core/option_parser.rb +16 -25
- data/lib/rspec/core/ordering.rb +3 -1
- data/lib/rspec/core/pending.rb +57 -33
- data/lib/rspec/core/project_initializer.rb +2 -0
- data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
- data/lib/rspec/core/rake_task.rb +45 -20
- data/lib/rspec/core/reporter.rb +50 -22
- data/lib/rspec/core/ruby_project.rb +1 -0
- data/lib/rspec/core/runner.rb +93 -39
- data/lib/rspec/core/shared_context.rb +7 -5
- data/lib/rspec/core/shared_example_group.rb +85 -77
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +35 -17
- data/lib/rspec/core/world.rb +57 -5
- metadata +56 -369
- metadata.gz.sig +3 -3
- data/features/README.md +0 -13
- data/features/Upgrade.md +0 -352
- data/features/command_line/README.md +0 -25
- data/features/command_line/dry_run.feature +0 -29
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/fail_fast.feature +0 -26
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -57
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -58
- data/features/command_line/order.feature +0 -25
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/randomization.feature +0 -63
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -23
- 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 -39
- data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
- 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/enable_global_dsl.feature +0 -54
- 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/overriding_global_ordering.feature +0 -93
- 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/example_groups/aliasing.feature +0 -48
- 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 -286
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -135
- data/features/filtering/if_and_unless.feature +0 -138
- data/features/filtering/inclusion_filters.feature +0 -101
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -68
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/regression_tests.feature +0 -95
- 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 -146
- data/features/hooks/around_hooks.feature +0 -344
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -232
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -100
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -94
- data/features/mock_framework_integration/use_mocha.feature +0 -95
- data/features/mock_framework_integration/use_rr.feature +0 -96
- data/features/mock_framework_integration/use_rspec.feature +0 -95
- data/features/pending_and_skipped_examples/README.md +0 -3
- data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
- data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -83
- 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 -21
- data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
- data/features/support/rubinius.rb +0 -6
- data/lib/rspec/core/command_line.rb +0 -35
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
- data/lib/rspec/core/shared_example_group/collection.rb +0 -27
- data/spec/command_line/order_spec.rb +0 -211
- data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
- data/spec/rspec/core/command_line_spec.rb +0 -112
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -409
- data/spec/rspec/core/configuration_spec.rb +0 -1479
- 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 -88
- data/spec/rspec/core/example_group_spec.rb +0 -1533
- data/spec/rspec/core/example_spec.rb +0 -642
- data/spec/rspec/core/filter_manager_spec.rb +0 -229
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
- data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters_spec.rb +0 -120
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -294
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
- data/spec/rspec/core/metadata_spec.rb +0 -491
- data/spec/rspec/core/option_parser_spec.rb +0 -262
- data/spec/rspec/core/ordering_spec.rb +0 -102
- data/spec/rspec/core/pending_example_spec.rb +0 -117
- data/spec/rspec/core/pending_spec.rb +0 -8
- data/spec/rspec/core/project_initializer_spec.rb +0 -73
- data/spec/rspec/core/rake_task_spec.rb +0 -146
- data/spec/rspec/core/random_spec.rb +0 -47
- data/spec/rspec/core/reporter_spec.rb +0 -155
- 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 -58
- 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 -151
- data/spec/rspec/core/shared_context_spec.rb +0 -102
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
- data/spec/rspec/core/shared_example_group_spec.rb +0 -114
- data/spec/rspec/core/warnings_spec.rb +0 -29
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -91
- data/spec/spec_helper.rb +0 -160
- data/spec/support/config_options_helper.rb +0 -13
- data/spec/support/formatter_support.rb +0 -83
- data/spec/support/helper_methods.rb +0 -26
- data/spec/support/isolate_load_path_mutation.rb +0 -5
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
- data/spec/support/matchers.rb +0 -85
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/old_style_formatter_example.rb +0 -69
- data/spec/support/shared_example_groups.rb +0 -13
- data/spec/support/spec_files.rb +0 -44
- data/spec/support/stderr_splitter.rb +0 -36
@@ -1,8 +1,9 @@
|
|
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
|
7
8
|
Formatters.register self, :example_group_started, :example_group_finished,
|
8
9
|
:example_passed, :example_pending, :example_failed
|
@@ -13,8 +14,6 @@ module RSpec
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def example_group_started(notification)
|
16
|
-
super
|
17
|
-
|
18
17
|
output.puts if @group_level == 0
|
19
18
|
output.puts "#{current_indentation}#{notification.group.description.strip}"
|
20
19
|
|
@@ -30,27 +29,25 @@ module RSpec
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def example_pending(pending)
|
33
|
-
|
34
|
-
output.puts pending_output(pending.example, pending.example.execution_result[:pending_message])
|
32
|
+
output.puts pending_output(pending.example, pending.example.execution_result.pending_message)
|
35
33
|
end
|
36
34
|
|
37
35
|
def example_failed(failure)
|
38
|
-
|
39
|
-
output.puts failure_output(failure.example, failure.example.execution_result[:exception])
|
36
|
+
output.puts failure_output(failure.example, failure.example.execution_result.exception)
|
40
37
|
end
|
41
38
|
|
42
39
|
private
|
43
40
|
|
44
41
|
def passed_output(example)
|
45
|
-
|
42
|
+
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
|
46
43
|
end
|
47
44
|
|
48
45
|
def pending_output(example, message)
|
49
|
-
|
46
|
+
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (PENDING: #{message})", :pending)
|
50
47
|
end
|
51
48
|
|
52
49
|
def failure_output(example, exception)
|
53
|
-
|
50
|
+
ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})", :failure)
|
54
51
|
end
|
55
52
|
|
56
53
|
def next_failure_index
|
@@ -1,21 +1,26 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
3
|
module Formatters
|
4
|
+
# Formatters helpers
|
4
5
|
module Helpers
|
6
|
+
|
7
|
+
# @private
|
5
8
|
SUB_SECOND_PRECISION = 5
|
9
|
+
|
10
|
+
# @private
|
6
11
|
DEFAULT_PRECISION = 2
|
7
12
|
|
8
13
|
# @api private
|
9
14
|
#
|
10
15
|
# Formats seconds into a human-readable string.
|
11
16
|
#
|
12
|
-
# @param [Float, Fixnum]
|
17
|
+
# @param duration [Float, Fixnum] in seconds
|
13
18
|
# @return [String] human-readable time
|
14
19
|
#
|
15
20
|
# @example
|
16
21
|
# format_duration(1) #=> "1 minute 1 second"
|
17
22
|
# format_duration(135.14) #=> "2 minutes 15.14 seconds"
|
18
|
-
def format_duration(duration)
|
23
|
+
def self.format_duration(duration)
|
19
24
|
precision = case
|
20
25
|
when duration < 1; SUB_SECOND_PRECISION
|
21
26
|
when duration < 120; DEFAULT_PRECISION
|
@@ -38,7 +43,7 @@ module RSpec
|
|
38
43
|
# Formats seconds to have 5 digits of precision with trailing zeros removed if the number
|
39
44
|
# is less than 1 or with 2 digits of precision if the number is greater than zero.
|
40
45
|
#
|
41
|
-
# @param [Float]
|
46
|
+
# @param float [Float]
|
42
47
|
# @return [String] formatted float
|
43
48
|
#
|
44
49
|
# @example
|
@@ -49,7 +54,7 @@ module RSpec
|
|
49
54
|
# The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
|
50
55
|
#
|
51
56
|
# @see #strip_trailing_zeroes
|
52
|
-
def format_seconds(float, precision = nil)
|
57
|
+
def self.format_seconds(float, precision = nil)
|
53
58
|
precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
|
54
59
|
formatted = sprintf("%.#{precision}f", float)
|
55
60
|
strip_trailing_zeroes(formatted)
|
@@ -59,21 +64,22 @@ module RSpec
|
|
59
64
|
#
|
60
65
|
# Remove trailing zeros from a string.
|
61
66
|
#
|
62
|
-
# @param [String] string
|
67
|
+
# @param string [String] string with trailing zeros
|
63
68
|
# @return [String] string with trailing zeros removed
|
64
|
-
def strip_trailing_zeroes(string)
|
69
|
+
def self.strip_trailing_zeroes(string)
|
65
70
|
stripped = string.sub(/[^1-9]+$/, '')
|
66
71
|
stripped.empty? ? "0" : stripped
|
67
72
|
end
|
73
|
+
private_class_method :strip_trailing_zeroes
|
68
74
|
|
69
75
|
# @api private
|
70
76
|
#
|
71
77
|
# Pluralize a word based on a count.
|
72
78
|
#
|
73
|
-
# @param [Fixnum]
|
74
|
-
# @param [String]
|
79
|
+
# @param count [Fixnum] number of objects
|
80
|
+
# @param string [String] word to be pluralized
|
75
81
|
# @return [String] pluralized word
|
76
|
-
def pluralize(count, string)
|
82
|
+
def self.pluralize(count, string)
|
77
83
|
"#{count} #{string}#{'s' unless count.to_f == 1}"
|
78
84
|
end
|
79
85
|
end
|
@@ -1,9 +1,10 @@
|
|
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
|
+
# @private
|
7
8
|
class HtmlFormatter < BaseFormatter
|
8
9
|
Formatters.register self, :start, :example_group_started, :start_dump,
|
9
10
|
:example_started, :example_passed, :example_failed,
|
@@ -11,6 +12,7 @@ module RSpec
|
|
11
12
|
|
12
13
|
def initialize(output)
|
13
14
|
super(output)
|
15
|
+
@failed_examples = []
|
14
16
|
@example_group_number = 0
|
15
17
|
@example_number = 0
|
16
18
|
@header_red = nil
|
@@ -46,13 +48,12 @@ module RSpec
|
|
46
48
|
|
47
49
|
def example_passed(passed)
|
48
50
|
@printer.move_progress(percent_done)
|
49
|
-
@printer.print_example_passed( passed.example.description, passed.example.execution_result
|
51
|
+
@printer.print_example_passed( passed.example.description, passed.example.execution_result.run_time )
|
50
52
|
@printer.flush
|
51
53
|
end
|
52
54
|
|
53
|
-
def example_failed(
|
54
|
-
|
55
|
-
|
55
|
+
def example_failed(failure)
|
56
|
+
@failed_examples << failure.example
|
56
57
|
unless @header_red
|
57
58
|
@header_red = true
|
58
59
|
@printer.make_header_red
|
@@ -65,23 +66,23 @@ module RSpec
|
|
65
66
|
|
66
67
|
@printer.move_progress(percent_done)
|
67
68
|
|
68
|
-
example =
|
69
|
+
example = failure.example
|
69
70
|
|
70
|
-
exception =
|
71
|
+
exception = failure.exception
|
71
72
|
exception_details = if exception
|
72
73
|
{
|
73
74
|
:message => exception.message,
|
74
|
-
:backtrace =>
|
75
|
+
:backtrace => failure.formatted_backtrace.join("\n")
|
75
76
|
}
|
76
77
|
else
|
77
78
|
false
|
78
79
|
end
|
79
|
-
extra = extra_failure_content(
|
80
|
+
extra = extra_failure_content(failure)
|
80
81
|
|
81
82
|
@printer.print_example_failed(
|
82
|
-
example.execution_result
|
83
|
+
example.execution_result.pending_fixed,
|
83
84
|
example.description,
|
84
|
-
example.execution_result
|
85
|
+
example.execution_result.run_time,
|
85
86
|
@failed_examples.size,
|
86
87
|
exception_details,
|
87
88
|
(extra == "") ? false : extra,
|
@@ -96,7 +97,7 @@ module RSpec
|
|
96
97
|
@printer.make_header_yellow unless @header_red
|
97
98
|
@printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
|
98
99
|
@printer.move_progress(percent_done)
|
99
|
-
@printer.print_example_pending( example.description, example.
|
100
|
+
@printer.print_example_pending( example.description, example.execution_result.pending_message )
|
100
101
|
@printer.flush
|
101
102
|
end
|
102
103
|
|
@@ -133,9 +134,9 @@ module RSpec
|
|
133
134
|
# Override this method if you wish to output extra HTML for a failed spec. For example, you
|
134
135
|
# could output links to images or other files produced during the specs.
|
135
136
|
#
|
136
|
-
def extra_failure_content(
|
137
|
-
|
138
|
-
backtrace = exception.backtrace.map {|line| configuration.backtrace_formatter.backtrace_line(line)}
|
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)}
|
139
140
|
backtrace.compact!
|
140
141
|
@snippet_extractor ||= SnippetExtractor.new
|
141
142
|
" <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
|
@@ -1,12 +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
|
+
# @private
|
7
8
|
class JsonFormatter < BaseFormatter
|
8
|
-
Formatters.register self, :message, :dump_summary, :stop, :close
|
9
|
-
:dump_profile
|
9
|
+
Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :close
|
10
10
|
|
11
11
|
attr_reader :output_hash
|
12
12
|
|
@@ -26,13 +26,11 @@ module RSpec
|
|
26
26
|
:failure_count => summary.failure_count,
|
27
27
|
:pending_count => summary.pending_count
|
28
28
|
}
|
29
|
-
@output_hash[:summary_line] = summary.
|
30
|
-
|
31
|
-
dump_profile unless mute_profile_output?(summary.failure_count)
|
29
|
+
@output_hash[:summary_line] = summary.totals_line
|
32
30
|
end
|
33
31
|
|
34
32
|
def stop(notification)
|
35
|
-
@output_hash[:examples] = examples.map do |example|
|
33
|
+
@output_hash[:examples] = notification.examples.map do |example|
|
36
34
|
format_example(example).tap do |hash|
|
37
35
|
if e=example.exception
|
38
36
|
hash[:exception] = {
|
@@ -50,29 +48,29 @@ module RSpec
|
|
50
48
|
output.close if IO === output && output != $stdout
|
51
49
|
end
|
52
50
|
|
53
|
-
def dump_profile
|
51
|
+
def dump_profile(profile)
|
54
52
|
@output_hash[:profile] = {}
|
55
|
-
dump_profile_slowest_examples
|
56
|
-
dump_profile_slowest_example_groups
|
53
|
+
dump_profile_slowest_examples(profile)
|
54
|
+
dump_profile_slowest_example_groups(profile)
|
57
55
|
end
|
58
56
|
|
59
57
|
# @api private
|
60
|
-
def dump_profile_slowest_examples
|
58
|
+
def dump_profile_slowest_examples(profile)
|
61
59
|
@output_hash[:profile] = {}
|
62
|
-
sorted_examples = slowest_examples
|
63
|
-
@output_hash[:profile][:examples] = sorted_examples
|
60
|
+
sorted_examples = profile.slowest_examples
|
61
|
+
@output_hash[:profile][:examples] = sorted_examples.map do |example|
|
64
62
|
format_example(example).tap do |hash|
|
65
|
-
hash[:run_time] = example.execution_result
|
63
|
+
hash[:run_time] = example.execution_result.run_time
|
66
64
|
end
|
67
65
|
end
|
68
|
-
@output_hash[:profile][:slowest] =
|
69
|
-
@output_hash[:profile][:total] =
|
66
|
+
@output_hash[:profile][:slowest] = profile.slow_duration
|
67
|
+
@output_hash[:profile][:total] = profile.duration
|
70
68
|
end
|
71
69
|
|
72
70
|
# @api private
|
73
|
-
def dump_profile_slowest_example_groups
|
71
|
+
def dump_profile_slowest_example_groups(profile)
|
74
72
|
@output_hash[:profile] ||= {}
|
75
|
-
@output_hash[:profile][:groups] = slowest_groups.map do |loc, hash|
|
73
|
+
@output_hash[:profile][:groups] = profile.slowest_groups.map do |loc, hash|
|
76
74
|
hash.update(:location => loc)
|
77
75
|
end
|
78
76
|
end
|
@@ -83,10 +81,10 @@ module RSpec
|
|
83
81
|
{
|
84
82
|
:description => example.description,
|
85
83
|
:full_description => example.full_description,
|
86
|
-
:status => example.execution_result
|
84
|
+
:status => example.execution_result.status.to_s,
|
87
85
|
:file_path => example.metadata[:file_path],
|
88
86
|
:line_number => example.metadata[:line_number],
|
89
|
-
:run_time => example.execution_result
|
87
|
+
:run_time => example.execution_result.run_time
|
90
88
|
}
|
91
89
|
end
|
92
90
|
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,28 +1,27 @@
|
|
1
|
-
|
1
|
+
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
|
2
|
+
|
2
3
|
module RSpec
|
3
4
|
module Core
|
4
5
|
module Formatters
|
6
|
+
# @private
|
5
7
|
class ProgressFormatter < BaseTextFormatter
|
6
8
|
Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
|
7
9
|
|
8
10
|
def example_passed(notification)
|
9
|
-
output.print
|
11
|
+
output.print ConsoleCodes.wrap('.', :success)
|
10
12
|
end
|
11
13
|
|
12
14
|
def example_pending(notification)
|
13
|
-
|
14
|
-
output.print pending_color('*')
|
15
|
+
output.print ConsoleCodes.wrap('*', :pending)
|
15
16
|
end
|
16
17
|
|
17
18
|
def example_failed(notification)
|
18
|
-
|
19
|
-
output.print failure_color('F')
|
19
|
+
output.print ConsoleCodes.wrap('F', :failure)
|
20
20
|
end
|
21
21
|
|
22
22
|
def start_dump(notification)
|
23
23
|
output.puts
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
@@ -5,12 +5,14 @@ module RSpec
|
|
5
5
|
#
|
6
6
|
# Extracts code snippets by looking at the backtrace of the passed error and applies synax highlighting and line numbers using html.
|
7
7
|
class SnippetExtractor
|
8
|
+
# @private
|
8
9
|
class NullConverter
|
9
10
|
def convert(code)
|
10
11
|
%Q(#{code}\n<span class="comment"># Install the coderay gem to get syntax highlighting</span>)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
# @private
|
14
16
|
class CoderayConverter
|
15
17
|
def convert(code)
|
16
18
|
CodeRay.scan(code, :ruby).html(:line_numbers => false)
|
@@ -28,7 +30,7 @@ module RSpec
|
|
28
30
|
#
|
29
31
|
# Extract lines of code corresponding to a backtrace.
|
30
32
|
#
|
31
|
-
# @param [String]
|
33
|
+
# @param backtrace [String] the backtrace from a test failure
|
32
34
|
# @return [String] highlighted code snippet indicating where the test failure occured
|
33
35
|
#
|
34
36
|
# @see #post_process
|
@@ -42,7 +44,7 @@ module RSpec
|
|
42
44
|
#
|
43
45
|
# Create a snippet from a line of code.
|
44
46
|
#
|
45
|
-
# @param [String]
|
47
|
+
# @param error_line [String] file name with line number (i.e. 'foo_spec.rb:12')
|
46
48
|
# @return [String] lines around the target line within the file
|
47
49
|
#
|
48
50
|
# @see #lines_around
|
@@ -60,8 +62,8 @@ module RSpec
|
|
60
62
|
#
|
61
63
|
# Extract lines of code centered around a particular line within a source file.
|
62
64
|
#
|
63
|
-
# @param [String]
|
64
|
-
# @param [Fixnum] line
|
65
|
+
# @param file [String] filename
|
66
|
+
# @param line [Fixnum] line number
|
65
67
|
# @return [String] lines around the target line within the file (2 above and 1 below).
|
66
68
|
def lines_around(file, line)
|
67
69
|
if File.file?(file)
|
@@ -82,8 +84,8 @@ module RSpec
|
|
82
84
|
#
|
83
85
|
# Adds line numbers to all lines and highlights the line where the failure occurred using html `span` tags.
|
84
86
|
#
|
85
|
-
# @param [String]
|
86
|
-
# @param [Fixnum]
|
87
|
+
# @param highlighted [String] syntax-highlighted snippet surrounding the offending line of code
|
88
|
+
# @param offending_line [Fixnum] line where failure occured
|
87
89
|
# @return [String] completed snippet
|
88
90
|
def post_process(highlighted, offending_line)
|
89
91
|
new_lines = []
|