rspec-core 2.12.2 → 2.13.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.
- data/Changelog.md +31 -0
- data/README.md +11 -10
- data/features/command_line/example_name_option.feature +6 -10
- data/features/command_line/tag.feature +15 -8
- data/features/configuration/backtrace_clean_patterns.feature +102 -0
- data/features/configuration/failure_exit_code.feature +36 -0
- data/features/configuration/order_and_seed.feature +3 -0
- data/features/configuration/output_stream.feature +24 -0
- data/features/configuration/pattern.feature +30 -0
- data/features/configuration/profile.feature +163 -0
- data/features/configuration/run_all_when_everything_filtered.feature +60 -0
- data/features/configuration/show_failures_in_pending_blocks.feature +61 -0
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +52 -0
- data/features/filtering/exclusion_filters.feature +1 -2
- data/features/formatters/configurable_colors.feature +31 -0
- data/features/step_definitions/additional_cli_steps.rb +21 -0
- data/features/subject/explicit_subject.feature +19 -0
- data/lib/autotest/rspec2.rb +1 -1
- data/lib/rspec/core.rb +1 -2
- data/lib/rspec/core/configuration.rb +33 -3
- data/lib/rspec/core/configuration_options.rb +5 -5
- data/lib/rspec/core/deprecation.rb +1 -1
- data/lib/rspec/core/example.rb +2 -2
- data/lib/rspec/core/example_group.rb +1 -3
- data/lib/rspec/core/formatters/base_text_formatter.rb +93 -27
- data/lib/rspec/core/formatters/documentation_formatter.rb +3 -3
- data/lib/rspec/core/formatters/progress_formatter.rb +3 -3
- data/lib/rspec/core/memoized_helpers.rb +425 -0
- data/lib/rspec/core/metadata.rb +6 -2
- data/lib/rspec/core/option_parser.rb +8 -2
- data/lib/rspec/core/pending.rb +7 -0
- data/lib/rspec/core/shared_context.rb +1 -1
- data/lib/rspec/core/version.rb +1 -1
- data/spec/autotest/failed_results_re_spec.rb +4 -4
- data/spec/autotest/rspec_spec.rb +25 -20
- data/spec/command_line/order_spec.rb +21 -21
- data/spec/rspec/core/command_line_spec.rb +6 -6
- data/spec/rspec/core/configuration_options_spec.rb +86 -72
- data/spec/rspec/core/configuration_spec.rb +161 -156
- data/spec/rspec/core/deprecations_spec.rb +4 -4
- data/spec/rspec/core/drb_command_line_spec.rb +9 -9
- data/spec/rspec/core/drb_options_spec.rb +46 -33
- data/spec/rspec/core/dsl_spec.rb +3 -3
- data/spec/rspec/core/example_group_spec.rb +156 -124
- data/spec/rspec/core/example_spec.rb +68 -52
- data/spec/rspec/core/filter_manager_spec.rb +36 -36
- data/spec/rspec/core/formatters/base_formatter_spec.rb +9 -9
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +104 -42
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +4 -4
- data/spec/rspec/core/formatters/helpers_spec.rb +13 -13
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +5 -17
- data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +159 -44
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +14 -14
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +20 -20
- data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +159 -44
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +20 -20
- data/spec/rspec/core/formatters/{html_formatted-1.9.2-jruby.html → html_formatted-2.0.0.html} +24 -18
- data/spec/rspec/core/formatters/html_formatter_spec.rb +9 -5
- data/spec/rspec/core/formatters/json_formatter_spec.rb +9 -9
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +4 -4
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +3 -3
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +5 -17
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-rbx.html +159 -44
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +16 -16
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +23 -23
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-jruby.html +5 -17
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-rbx.html +159 -44
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +23 -23
- data/spec/rspec/core/formatters/{text_mate_formatted-1.9.2-jruby.html → text_mate_formatted-2.0.0.html} +25 -19
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +8 -4
- data/spec/rspec/core/hooks_filtering_spec.rb +16 -16
- data/spec/rspec/core/hooks_spec.rb +11 -11
- data/spec/rspec/core/kernel_extensions_spec.rb +1 -1
- data/spec/rspec/core/memoized_helpers_spec.rb +458 -0
- data/spec/rspec/core/metadata_spec.rb +74 -74
- data/spec/rspec/core/option_parser_spec.rb +27 -27
- data/spec/rspec/core/pending_example_spec.rb +32 -32
- data/spec/rspec/core/project_initializer_spec.rb +8 -8
- data/spec/rspec/core/rake_task_spec.rb +16 -16
- data/spec/rspec/core/reporter_spec.rb +3 -3
- data/spec/rspec/core/resources/formatter_specs.rb +4 -4
- data/spec/rspec/core/ruby_project_spec.rb +4 -2
- data/spec/rspec/core/shared_context_spec.rb +34 -7
- data/spec/rspec/core/shared_example_group_spec.rb +14 -14
- data/spec/rspec/core/world_spec.rb +9 -9
- data/spec/rspec/core_spec.rb +5 -5
- data/spec/spec_helper.rb +4 -0
- data/spec/support/shared_example_groups.rb +4 -4
- data/spec/support/spec_files.rb +2 -2
- metadata +158 -150
- data/lib/rspec/core/let.rb +0 -110
- data/lib/rspec/core/subject.rb +0 -223
- data/spec/rspec/core/let_spec.rb +0 -55
- data/spec/rspec/core/subject_spec.rb +0 -255
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Feature: run all when everything filtered
|
|
2
|
+
|
|
3
|
+
Use the run_all_when_everything_filtered option to tell RSpec to run
|
|
4
|
+
all the specs in the case where you try to run a filtered list of
|
|
5
|
+
specs but no specs match that filter.
|
|
6
|
+
|
|
7
|
+
RSpec.configure { |c| c.run_all_when_everything_filtered = true }
|
|
8
|
+
|
|
9
|
+
Background:
|
|
10
|
+
Given a file named "spec/spec_helper.rb" with:
|
|
11
|
+
"""ruby
|
|
12
|
+
RSpec.configure {|c| c.run_all_when_everything_filtered = true}
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
Scenario: by default, no specs are run if they are all filtered out
|
|
16
|
+
Given a file named "spec/example_spec.rb" with:
|
|
17
|
+
"""ruby
|
|
18
|
+
describe "examples" do
|
|
19
|
+
it "with no tag" do
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "with no tag as well" do
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
"""
|
|
26
|
+
When I run `rspec spec/example_spec.rb --tag some_tag`
|
|
27
|
+
Then the output should contain "0 examples, 0 failures"
|
|
28
|
+
|
|
29
|
+
Scenario: when the run_all_when_everything_filtered option is turned on, if there are any matches for the filtering tag, only those features are run
|
|
30
|
+
Given a file named "spec/example_spec.rb" with:
|
|
31
|
+
"""ruby
|
|
32
|
+
require "spec_helper"
|
|
33
|
+
describe "examples" do
|
|
34
|
+
it "with no tag", :some_tag => true do
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "with no tag as well" do
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
"""
|
|
41
|
+
When I run `rspec spec/example_spec.rb --tag some_tag`
|
|
42
|
+
Then the output should contain "1 example, 0 failures"
|
|
43
|
+
And the output should contain "Run options: include {:some_tag=>true}"
|
|
44
|
+
|
|
45
|
+
Scenario: when the run_all_when_everything_filtered option is turned on, all the specs are run when the tag has no matches
|
|
46
|
+
Given a file named "spec/example_spec.rb" with:
|
|
47
|
+
"""ruby
|
|
48
|
+
require "spec_helper"
|
|
49
|
+
describe "examples" do
|
|
50
|
+
it "with no tag" do
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "with no tag as well" do
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
"""
|
|
57
|
+
When I run `rspec spec/example_spec.rb --tag some_tag`
|
|
58
|
+
Then the output should contain "2 examples, 0 failures"
|
|
59
|
+
And the output should contain "All examples were filtered out; ignoring {:some_tag=>true}"
|
|
60
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Feature: show_failures_in_pending_blocks
|
|
2
|
+
|
|
3
|
+
Use the show_failures_in_pending_blocks option to run the code in pending blocks while keeping the tests pending.
|
|
4
|
+
|
|
5
|
+
RSpec.configure { |c| c.show_failures_in_pending_blocks = true }
|
|
6
|
+
|
|
7
|
+
Background:
|
|
8
|
+
Given a file named "spec/spec_helper.rb" with:
|
|
9
|
+
"""ruby
|
|
10
|
+
RSpec.configure {|c| c.show_failures_in_pending_blocks = true}
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
Scenario: by default, code in pending examples is not exercised
|
|
14
|
+
Given a file named "spec/example_spec.rb" with:
|
|
15
|
+
"""ruby
|
|
16
|
+
describe "fails" do
|
|
17
|
+
pending "code will not be exercised" do
|
|
18
|
+
fail
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
"""
|
|
22
|
+
When I run `rspec spec/example_spec.rb`
|
|
23
|
+
Then the output should not contain "Failure/Error: pending { fail }"
|
|
24
|
+
|
|
25
|
+
Scenario: by default, code in pending blocks inside examples is not exercised
|
|
26
|
+
Given a file named "spec/example_spec.rb" with:
|
|
27
|
+
"""ruby
|
|
28
|
+
describe "fails" do
|
|
29
|
+
it "code will not be exercised" do
|
|
30
|
+
pending { fail }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
"""
|
|
34
|
+
When I run `rspec spec/example_spec.rb`
|
|
35
|
+
Then the output should not contain "Failure/Error: pending { fail }"
|
|
36
|
+
|
|
37
|
+
Scenario: when turned on, pending code blocks inside examples are exercised
|
|
38
|
+
Given a file named "spec/example_spec.rb" with:
|
|
39
|
+
"""ruby
|
|
40
|
+
require "spec_helper"
|
|
41
|
+
describe "fails" do
|
|
42
|
+
it "code will be exercised" do
|
|
43
|
+
pending { fail }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
"""
|
|
47
|
+
When I run `rspec spec/example_spec.rb`
|
|
48
|
+
Then the output should contain "Failure/Error: pending { fail }"
|
|
49
|
+
|
|
50
|
+
Scenario: when turned on, code inside pending examples is not exercised
|
|
51
|
+
Given a file named "spec/example_spec.rb" with:
|
|
52
|
+
"""ruby
|
|
53
|
+
require "spec_helper"
|
|
54
|
+
describe "fails" do
|
|
55
|
+
pending "code will not be exercised" do
|
|
56
|
+
fail
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
"""
|
|
60
|
+
When I run `rspec spec/example_spec.rb`
|
|
61
|
+
Then the output should not contain "Failure/Error: pending { fail }"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Feature: treat symbols as metadata keys with true values
|
|
2
|
+
|
|
3
|
+
Use the treat_symbols_as_metadata_keys_with_true_values option to tell RSpec that :key is shorthand for :key => true.
|
|
4
|
+
|
|
5
|
+
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
|
|
6
|
+
|
|
7
|
+
Background:
|
|
8
|
+
Given a file named "spec/spec_helper.rb" with:
|
|
9
|
+
"""ruby
|
|
10
|
+
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
Scenario: by default, symbols without values are ignored and the specs are filtered out
|
|
14
|
+
Given a file named "spec/example_spec.rb" with:
|
|
15
|
+
"""ruby
|
|
16
|
+
describe "failed filtering" do
|
|
17
|
+
it "this will be filted out", :some_tag do
|
|
18
|
+
true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "so will this" do
|
|
22
|
+
false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
"""
|
|
26
|
+
When I run `rspec spec/example_spec.rb --tag some_tag`
|
|
27
|
+
Then the output should contain "0 examples, 0 failures"
|
|
28
|
+
And the output should contain "All examples were filtered out"
|
|
29
|
+
|
|
30
|
+
Scenario: when treat_symbols_as_metadata_keys_with_true_values is true, specs can be tagged with only a symbol
|
|
31
|
+
Given a file named "spec/example_spec.rb" with:
|
|
32
|
+
"""ruby
|
|
33
|
+
require "spec_helper"
|
|
34
|
+
describe "run me", :some_tag do
|
|
35
|
+
it "runs" do
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "run one of these" do
|
|
41
|
+
it "run this one", :some_tag do
|
|
42
|
+
true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "but not me" do
|
|
46
|
+
false
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
"""
|
|
50
|
+
When I run `rspec spec/example_spec.rb --tag some_tag`
|
|
51
|
+
Then the output should contain "2 examples, 0 failures"
|
|
52
|
+
And the output should contain "Run options: include {:some_tag=>true}"
|
|
@@ -81,8 +81,7 @@ Feature: exclusion filters
|
|
|
81
81
|
end
|
|
82
82
|
"""
|
|
83
83
|
When I run `rspec ./spec/sample_spec.rb --format doc`
|
|
84
|
-
Then the
|
|
85
|
-
And the examples should all pass
|
|
84
|
+
Then the process should succeed even though no examples were run
|
|
86
85
|
And the output should not contain "group 1"
|
|
87
86
|
And the output should not contain "group 2"
|
|
88
87
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Feature: Configurable colors
|
|
2
|
+
|
|
3
|
+
RSpec allows you to configure the terminal colors used in the text formatters.
|
|
4
|
+
|
|
5
|
+
* `failure_color`: Color used when tests fail (default: `:red`)
|
|
6
|
+
* `success_color`: Color used when tests pass (default: `:green`)
|
|
7
|
+
* `pending_color`: Color used when tests are pending (default: `:yellow`)
|
|
8
|
+
* `fixed_color`: Color used when a pending block inside an example passes, but was expected to fail (default: `:blue`)
|
|
9
|
+
* `detail_color`: Color used for miscellaneous test details (default: `:cyan`)
|
|
10
|
+
|
|
11
|
+
Colors are normally specified as symbols. Options are `:black`, `:red`,
|
|
12
|
+
`:green`, `:yellow`, `:blue`, `:magenta`, `:cyan`, and `:white`.
|
|
13
|
+
|
|
14
|
+
@ansi
|
|
15
|
+
Scenario: Customizing the failure color
|
|
16
|
+
Given a file named "custom_failure_color_spec.rb" with:
|
|
17
|
+
"""ruby
|
|
18
|
+
RSpec.configure do |config|
|
|
19
|
+
config.failure_color = :magenta
|
|
20
|
+
config.tty = true
|
|
21
|
+
config.color = true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "failure" do
|
|
25
|
+
it "fails and uses the custom color" do
|
|
26
|
+
expect(2).to eq(4)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
"""
|
|
30
|
+
When I run `rspec custom_failure_color_spec.rb --format progress`
|
|
31
|
+
Then the failing example is printed in magenta
|
|
@@ -12,8 +12,22 @@ Then /^the output should not contain any of these:$/ do |table|
|
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
Then /^the output should contain one of the following:$/ do |table|
|
|
16
|
+
matching_output = table.raw.flatten.select do |string|
|
|
17
|
+
all_output =~ regexp(string)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
matching_output.should have(1).item
|
|
21
|
+
end
|
|
22
|
+
|
|
15
23
|
Then /^the example(?:s)? should(?: all)? pass$/ do
|
|
16
24
|
step %q{the output should contain "0 failures"}
|
|
25
|
+
step %q{the output should not contain "0 examples"}
|
|
26
|
+
step %q{the exit status should be 0}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Then /^the process should succeed even though no examples were run$/ do
|
|
30
|
+
step %q{the output should contain "0 examples, 0 failures"}
|
|
17
31
|
step %q{the exit status should be 0}
|
|
18
32
|
end
|
|
19
33
|
|
|
@@ -30,3 +44,10 @@ Then /^the backtrace\-normalized output should contain:$/ do |partial_output|
|
|
|
30
44
|
|
|
31
45
|
normalized_output.should =~ regexp(partial_output)
|
|
32
46
|
end
|
|
47
|
+
|
|
48
|
+
# This step can be generalized if it's ever used to test other colors
|
|
49
|
+
Then /^the failing example is printed in magenta$/ do
|
|
50
|
+
# \e[35m = enable magenta
|
|
51
|
+
# \e[0m = reset colors
|
|
52
|
+
expect(all_output).to include("\e[35m" + "F" + "\e[0m")
|
|
53
|
+
end
|
|
@@ -80,3 +80,22 @@ Feature: explicit subject
|
|
|
80
80
|
"""
|
|
81
81
|
When I run `rspec nil_subject_spec.rb`
|
|
82
82
|
Then the examples should all pass
|
|
83
|
+
|
|
84
|
+
Scenario: subject bang method
|
|
85
|
+
Given a file named "subject_bang_spec.rb" with:
|
|
86
|
+
"""ruby
|
|
87
|
+
describe Array do
|
|
88
|
+
describe '#pop' do
|
|
89
|
+
let(:prepared_array) { [1,2,3] }
|
|
90
|
+
subject! { prepared_array.pop }
|
|
91
|
+
it "removes the last value from the array" do
|
|
92
|
+
prepared_array.should eq([1,2])
|
|
93
|
+
end
|
|
94
|
+
it "returns the last value of the array" do
|
|
95
|
+
subject.should eq(3)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
"""
|
|
100
|
+
When I run `rspec subject_bang_spec.rb`
|
|
101
|
+
Then the examples should all pass
|
data/lib/autotest/rspec2.rb
CHANGED
|
@@ -47,7 +47,7 @@ class Autotest::Rspec2 < Autotest
|
|
|
47
47
|
# Overrides Autotest's implementation to generate the rspec command to run
|
|
48
48
|
def make_test_cmd(files_to_test)
|
|
49
49
|
files_to_test.empty? ? '' :
|
|
50
|
-
|
|
50
|
+
%|#{prefix}"#{ruby}"#{suffix} -S "#{RSPEC_EXECUTABLE}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# Generates a map of filenames to Arrays for Autotest
|
data/lib/rspec/core.rb
CHANGED
|
@@ -23,8 +23,7 @@ require_rspec['core/reporter']
|
|
|
23
23
|
|
|
24
24
|
require_rspec['core/metadata_hash_builder']
|
|
25
25
|
require_rspec['core/hooks']
|
|
26
|
-
require_rspec['core/
|
|
27
|
-
require_rspec['core/let']
|
|
26
|
+
require_rspec['core/memoized_helpers']
|
|
28
27
|
require_rspec['core/metadata']
|
|
29
28
|
require_rspec['core/pending']
|
|
30
29
|
require_rspec['core/formatters']
|
|
@@ -99,7 +99,7 @@ MESSAGE
|
|
|
99
99
|
# server, but you can use tools like spork.
|
|
100
100
|
add_setting :drb
|
|
101
101
|
|
|
102
|
-
# The drb_port (default:
|
|
102
|
+
# The drb_port (default: nil).
|
|
103
103
|
add_setting :drb_port
|
|
104
104
|
|
|
105
105
|
# Default: `$stderr`.
|
|
@@ -122,12 +122,22 @@ MESSAGE
|
|
|
122
122
|
# Load files matching this pattern (default: `'**/*_spec.rb'`)
|
|
123
123
|
add_setting :pattern, :alias_with => :filename_pattern
|
|
124
124
|
|
|
125
|
-
# Report the times for the
|
|
125
|
+
# Report the times for the slowest examples (default: `false`).
|
|
126
|
+
# Use this to specify the number of examples to include in the profile.
|
|
126
127
|
add_setting :profile_examples
|
|
127
128
|
|
|
128
129
|
# Run all examples if none match the configured filters (default: `false`).
|
|
129
130
|
add_setting :run_all_when_everything_filtered
|
|
130
131
|
|
|
132
|
+
# Allow user to configure their own success/pending/failure colors
|
|
133
|
+
# @param [Symbol] should be one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
|
134
|
+
add_setting :success_color
|
|
135
|
+
add_setting :pending_color
|
|
136
|
+
add_setting :failure_color
|
|
137
|
+
add_setting :default_color
|
|
138
|
+
add_setting :fixed_color
|
|
139
|
+
add_setting :detail_color
|
|
140
|
+
|
|
131
141
|
# Seed for random ordering (default: generated randomly each run).
|
|
132
142
|
#
|
|
133
143
|
# When you run specs with `--order random`, RSpec generates a random seed
|
|
@@ -176,7 +186,7 @@ MESSAGE
|
|
|
176
186
|
/\/lib\d*\/ruby\//,
|
|
177
187
|
/org\/jruby\//,
|
|
178
188
|
/bin\//,
|
|
179
|
-
|
|
189
|
+
%r|/gems/|,
|
|
180
190
|
/spec\/spec_helper\.rb/,
|
|
181
191
|
/lib\/rspec\/(core|expectations|matchers|mocks)/
|
|
182
192
|
]
|
|
@@ -195,6 +205,13 @@ MESSAGE
|
|
|
195
205
|
@filter_manager = FilterManager.new
|
|
196
206
|
@preferred_options = {}
|
|
197
207
|
@seed = srand % 0xFFFF
|
|
208
|
+
@failure_color = :red
|
|
209
|
+
@success_color = :green
|
|
210
|
+
@pending_color = :yellow
|
|
211
|
+
@default_color = :white
|
|
212
|
+
@fixed_color = :blue
|
|
213
|
+
@detail_color = :cyan
|
|
214
|
+
@profile_examples = false
|
|
198
215
|
end
|
|
199
216
|
|
|
200
217
|
# @private
|
|
@@ -506,6 +523,19 @@ EOM
|
|
|
506
523
|
end
|
|
507
524
|
end
|
|
508
525
|
|
|
526
|
+
# @api private
|
|
527
|
+
#
|
|
528
|
+
# Defaults `profile_examples` to 10 examples when `@profile_examples` is `true`.
|
|
529
|
+
#
|
|
530
|
+
def profile_examples
|
|
531
|
+
profile = value_for(:profile_examples, @profile_examples)
|
|
532
|
+
if profile && !profile.is_a?(Integer)
|
|
533
|
+
10
|
|
534
|
+
else
|
|
535
|
+
profile
|
|
536
|
+
end
|
|
537
|
+
end
|
|
538
|
+
|
|
509
539
|
# @private
|
|
510
540
|
def files_or_directories_to_run=(*files)
|
|
511
541
|
files = files.flatten
|
|
@@ -8,13 +8,13 @@ module RSpec
|
|
|
8
8
|
attr_reader :options
|
|
9
9
|
|
|
10
10
|
def initialize(args)
|
|
11
|
-
@args = args
|
|
12
|
-
if args.include?("--default_path")
|
|
13
|
-
args[args.index("--default_path")] = "--default-path"
|
|
11
|
+
@args = args.dup
|
|
12
|
+
if @args.include?("--default_path")
|
|
13
|
+
@args[@args.index("--default_path")] = "--default-path"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
if args.include?("--line_number")
|
|
17
|
-
args[args.index("--line_number")] = "--line-number"
|
|
16
|
+
if @args.include?("--line_number")
|
|
17
|
+
@args[@args.index("--line_number")] = "--line-number"
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
data/lib/rspec/core/example.rb
CHANGED
|
@@ -233,8 +233,8 @@ An error occurred #{context}
|
|
|
233
233
|
end
|
|
234
234
|
|
|
235
235
|
# @private
|
|
236
|
-
def instance_eval(&block)
|
|
237
|
-
@example_group_instance.instance_eval(&block)
|
|
236
|
+
def instance_eval(*args, &block)
|
|
237
|
+
@example_group_instance.instance_eval(*args, &block)
|
|
238
238
|
end
|
|
239
239
|
|
|
240
240
|
# @private
|
|
@@ -15,13 +15,11 @@ module RSpec
|
|
|
15
15
|
class ExampleGroup
|
|
16
16
|
extend MetadataHashBuilder::WithDeprecationWarning
|
|
17
17
|
extend Extensions::ModuleEvalWithArgs
|
|
18
|
-
extend Subject::ExampleGroupMethods
|
|
19
18
|
extend Hooks
|
|
20
19
|
|
|
20
|
+
include MemoizedHelpers
|
|
21
21
|
include Extensions::InstanceEvalWithArgs
|
|
22
|
-
include Subject::ExampleMethods
|
|
23
22
|
include Pending
|
|
24
|
-
include Let
|
|
25
23
|
include SharedExampleGroup
|
|
26
24
|
|
|
27
25
|
# @private
|
|
@@ -33,18 +33,17 @@ module RSpec
|
|
|
33
33
|
# @param [String] string
|
|
34
34
|
def colorise_summary(summary)
|
|
35
35
|
if failure_count > 0
|
|
36
|
-
|
|
36
|
+
color(summary, RSpec.configuration.failure_color)
|
|
37
37
|
elsif pending_count > 0
|
|
38
|
-
|
|
38
|
+
color(summary, RSpec.configuration.pending_color)
|
|
39
39
|
else
|
|
40
|
-
|
|
40
|
+
color(summary, RSpec.configuration.success_color)
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def dump_summary(duration, example_count, failure_count, pending_count)
|
|
45
45
|
super(duration, example_count, failure_count, pending_count)
|
|
46
|
-
|
|
47
|
-
dump_profile if profile_examples? && failure_count == 0
|
|
46
|
+
dump_profile if profile_examples?
|
|
48
47
|
output.puts "\nFinished in #{format_duration(duration)}\n"
|
|
49
48
|
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
|
|
50
49
|
dump_commands_to_rerun_failed_examples
|
|
@@ -61,17 +60,18 @@ module RSpec
|
|
|
61
60
|
output.puts
|
|
62
61
|
|
|
63
62
|
failed_examples.each do |example|
|
|
64
|
-
output.puts(
|
|
63
|
+
output.puts(failure_color("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + detail_color("# #{example.full_description}"))
|
|
65
64
|
end
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
# @api public
|
|
69
68
|
#
|
|
70
|
-
# Outputs the
|
|
69
|
+
# Outputs the slowest examples in a report when using `--profile COUNT` (default 10).
|
|
71
70
|
#
|
|
72
71
|
def dump_profile
|
|
72
|
+
number_of_examples = RSpec.configuration.profile_examples
|
|
73
73
|
sorted_examples = examples.sort_by {|example|
|
|
74
|
-
example.execution_result[:run_time] }.reverse.first(
|
|
74
|
+
example.execution_result[:run_time] }.reverse.first(number_of_examples)
|
|
75
75
|
|
|
76
76
|
total, slows = [examples, sorted_examples].map {|exs|
|
|
77
77
|
exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }}
|
|
@@ -83,7 +83,7 @@ module RSpec
|
|
|
83
83
|
|
|
84
84
|
sorted_examples.each do |example|
|
|
85
85
|
output.puts " #{example.full_description}"
|
|
86
|
-
output.puts
|
|
86
|
+
output.puts detail_color(" #{failure_color(format_seconds(example.execution_result[:run_time]))} #{failure_color("seconds")} #{format_caller(example.location)}")
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
@@ -103,9 +103,9 @@ module RSpec
|
|
|
103
103
|
output.puts
|
|
104
104
|
output.puts "Pending:"
|
|
105
105
|
pending_examples.each do |pending_example|
|
|
106
|
-
output.puts
|
|
107
|
-
output.puts
|
|
108
|
-
output.puts
|
|
106
|
+
output.puts pending_color(" #{pending_example.full_description}")
|
|
107
|
+
output.puts detail_color(" # #{pending_example.execution_result[:pending_message]}")
|
|
108
|
+
output.puts detail_color(" # #{format_caller(pending_example.location)}")
|
|
109
109
|
if pending_example.execution_result[:exception] \
|
|
110
110
|
&& RSpec.configuration.show_failures_in_pending_blocks?
|
|
111
111
|
dump_failure_info(pending_example)
|
|
@@ -125,42 +125,100 @@ module RSpec
|
|
|
125
125
|
output.close if IO === output && output != $stdout
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
+
VT100_COLORS = {
|
|
129
|
+
:black => 30,
|
|
130
|
+
:red => 31,
|
|
131
|
+
:green => 32,
|
|
132
|
+
:yellow => 33,
|
|
133
|
+
:blue => 34,
|
|
134
|
+
:magenta => 35,
|
|
135
|
+
:cyan => 36,
|
|
136
|
+
:white => 37
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
VT100_COLOR_CODES = VT100_COLORS.values.to_set
|
|
140
|
+
|
|
141
|
+
def color_code_for(code_or_symbol)
|
|
142
|
+
if VT100_COLOR_CODES.include?(code_or_symbol)
|
|
143
|
+
code_or_symbol
|
|
144
|
+
else
|
|
145
|
+
VT100_COLORS.fetch(code_or_symbol) do
|
|
146
|
+
color_code_for(:white)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def colorize(text, code_or_symbol)
|
|
152
|
+
"\e[#{color_code_for(code_or_symbol)}m#{text}\e[0m"
|
|
153
|
+
end
|
|
154
|
+
|
|
128
155
|
protected
|
|
129
156
|
|
|
157
|
+
def bold(text)
|
|
158
|
+
color_enabled? ? "\e[1m#{text}\e[0m" : text
|
|
159
|
+
end
|
|
160
|
+
|
|
130
161
|
def color(text, color_code)
|
|
131
|
-
color_enabled? ?
|
|
162
|
+
color_enabled? ? colorize(text, color_code) : text
|
|
132
163
|
end
|
|
133
164
|
|
|
134
|
-
def
|
|
135
|
-
color(text,
|
|
165
|
+
def failure_color(text)
|
|
166
|
+
color(text, RSpec.configuration.failure_color)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def success_color(text)
|
|
170
|
+
color(text, RSpec.configuration.success_color)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def pending_color(text)
|
|
174
|
+
color(text, RSpec.configuration.pending_color)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def fixed_color(text)
|
|
178
|
+
color(text, RSpec.configuration.fixed_color)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def detail_color(text)
|
|
182
|
+
color(text, RSpec.configuration.detail_color)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def default_color(text)
|
|
186
|
+
color(text, RSpec.configuration.default_color)
|
|
136
187
|
end
|
|
137
188
|
|
|
138
189
|
def red(text)
|
|
139
|
-
|
|
190
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", "#failure_color", "3.0")
|
|
191
|
+
color(text, :red)
|
|
140
192
|
end
|
|
141
193
|
|
|
142
194
|
def green(text)
|
|
143
|
-
|
|
195
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", "#success_color", "3.0")
|
|
196
|
+
color(text, :green)
|
|
144
197
|
end
|
|
145
198
|
|
|
146
199
|
def yellow(text)
|
|
147
|
-
|
|
200
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", "#pending_color", "3.0")
|
|
201
|
+
color(text, :yellow)
|
|
148
202
|
end
|
|
149
203
|
|
|
150
204
|
def blue(text)
|
|
151
|
-
|
|
205
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", "#fixed_color", "3.0")
|
|
206
|
+
color(text, :blue)
|
|
152
207
|
end
|
|
153
208
|
|
|
154
209
|
def magenta(text)
|
|
155
|
-
|
|
210
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta", nil, "3.0")
|
|
211
|
+
color(text, :magenta)
|
|
156
212
|
end
|
|
157
213
|
|
|
158
214
|
def cyan(text)
|
|
159
|
-
|
|
215
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", "#detail_color", "3.0")
|
|
216
|
+
color(text, :cyan)
|
|
160
217
|
end
|
|
161
218
|
|
|
162
219
|
def white(text)
|
|
163
|
-
|
|
220
|
+
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", "#default_color", "3.0")
|
|
221
|
+
color(text, :white)
|
|
164
222
|
end
|
|
165
223
|
|
|
166
224
|
def short_padding
|
|
@@ -179,13 +237,13 @@ module RSpec
|
|
|
179
237
|
|
|
180
238
|
def dump_backtrace(example)
|
|
181
239
|
format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info|
|
|
182
|
-
output.puts
|
|
240
|
+
output.puts detail_color("#{long_padding}# #{backtrace_info}")
|
|
183
241
|
end
|
|
184
242
|
end
|
|
185
243
|
|
|
186
244
|
def dump_pending_fixed(example, index)
|
|
187
245
|
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
|
|
188
|
-
output.puts
|
|
246
|
+
output.puts fixed_color("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
|
|
189
247
|
end
|
|
190
248
|
|
|
191
249
|
def pending_fixed?(example)
|
|
@@ -199,14 +257,22 @@ module RSpec
|
|
|
199
257
|
|
|
200
258
|
def dump_failure_info(example)
|
|
201
259
|
exception = example.execution_result[:exception]
|
|
202
|
-
|
|
203
|
-
output.puts "#{long_padding}#{
|
|
204
|
-
|
|
260
|
+
exception_class_name = exception_class_name_for(exception)
|
|
261
|
+
output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
|
|
262
|
+
output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/
|
|
263
|
+
exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
|
|
264
|
+
|
|
205
265
|
if shared_group = find_shared_group(example)
|
|
206
266
|
dump_shared_failure_info(shared_group)
|
|
207
267
|
end
|
|
208
268
|
end
|
|
209
269
|
|
|
270
|
+
def exception_class_name_for(exception)
|
|
271
|
+
name = exception.class.name.to_s
|
|
272
|
+
name ="(anonymous error class)" if name == ''
|
|
273
|
+
name
|
|
274
|
+
end
|
|
275
|
+
|
|
210
276
|
def dump_shared_failure_info(group)
|
|
211
277
|
output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
|
|
212
278
|
"#{backtrace_line(group.metadata[:example_group][:location])}"
|