Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't --profile with --fail-fast and failures

i.e. don't display slow examples in the output if `--fail-fast` option
is used and there are any failures as it clutters the output.

References #730.
  • Loading branch information...
commit eb8546a2435b2508fdf913528b23d3ebefd70e15 1 parent 80e7975
@pjg pjg authored
View
2  Changelog.md
@@ -3,6 +3,8 @@
Enhancements
+* Don't show slow examples if there's a failure and both `--fail-fast`
+ and `--profile` options are used (Paweł Gościcki).
* Rather than always adding `spec` to the load path, add the configured
`--default-path` to the load path (which defaults to `spec`). This
better supports folks who choose to put their specs in a different
View
61 features/configuration/profile.feature
@@ -4,7 +4,8 @@ Feature: Profile examples
`#profile_examples`), when set, will cause RSpec to dump out a list of
your slowest examples. By default, it prints the 10 slowest examples,
but you can set it to a different value to have it print more or fewer
- slow examples.
+ slow examples. If `--fail-fast` option is used together with `--profile`
+ and there is a failure, slow examples are not shown.
Background:
Given a file named "spec/spec_helper.rb" with:
@@ -15,7 +16,7 @@ Feature: Profile examples
require "spec_helper"
describe "something" do
- it "sleeps for 0.1 secionds (example 1)" do
+ it "sleeps for 0.1 seconds (example 1)" do
sleep 0.1
1.should == 1
end
@@ -161,3 +162,59 @@ Feature: Profile examples
And the output should not contain "example 10"
And the output should not contain "example 11"
+ Scenario: Using `--profile` with `--fail-fast` shows slow examples if everything passes
+ When I run `rspec spec --fail-fast --profile`
+ Then the examples should all pass
+ And the output should contain "Top 10 slowest examples"
+ And the output should contain "example 1"
+ And the output should not contain "example 2"
+ And the output should contain "example 3"
+ And the output should contain "example 4"
+ And the output should contain "example 5"
+ And the output should contain "example 6"
+ And the output should contain "example 7"
+ And the output should contain "example 8"
+ And the output should contain "example 9"
+ And the output should contain "example 10"
+ And the output should contain "example 11"
+
+ Scenario: Using `--profile` shows slow examples even in case of failures
+ Given a file named "spec/example_spec.rb" with:
+ """ruby
+ require "spec_helper"
+
+ describe "something" do
+ it "sleeps for 0.1 seconds (example 1)" do
+ sleep 0.1
+ 1.should == 1
+ end
+
+ it "fails" do
+ fail
+ end
+ end
+ """
+ When I run `rspec spec --profile`
+ Then the output should contain "2 examples, 1 failure"
+ And the output should contain "Top 2 slowest examples"
+ And the output should contain "example 1"
+
+ Scenario: Using `--profile` with `--fail-fast` doesn't show slow examples in case of failures
+ Given a file named "spec/example_spec.rb" with:
+ """ruby
+ require "spec_helper"
+
+ describe "something" do
+ it "sleeps for 0.1 seconds (example 1)" do
+ sleep 0.1
+ 1.should == 1
+ end
+
+ it "fails" do
+ fail
+ end
+ end
+ """
+ When I run `rspec spec --fail-fast --profile`
+ Then the output should not contain "Top 2 slowest examples"
+ And the output should not contain "example 1"
View
4 lib/rspec/core/formatters/base_formatter.rb
@@ -228,6 +228,10 @@ def profile_examples?
configuration.profile_examples
end
+ def fail_fast?
+ configuration.fail_fast
+ end
+
def color_enabled?
configuration.color_enabled?(output)
end
View
5 lib/rspec/core/formatters/base_text_formatter.rb
@@ -44,7 +44,10 @@ def colorise_summary(summary)
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
- dump_profile if profile_examples?
+ # Don't print out profiled info if there are failures and `--fail-fast` is used, it just clutters the output
+ if profile_examples? && (!fail_fast? || fail_fast? && failure_count == 0)
+ dump_profile
+ end
output.puts "\nFinished in #{format_duration(duration)}\n"
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
dump_commands_to_rerun_failed_examples
Please sign in to comment.
Something went wrong with that request. Please try again.