Permalink
Browse files

Merge branch 'master' into charliemaffitt-configurable_terminal_colors

Conflicts:
	lib/rspec/core/configuration.rb
	lib/rspec/core/formatters/base_text_formatter.rb
  • Loading branch information...
2 parents f15615a + c578697 commit 4eb7ebe1b025108a4b923962ed5637d5ace19976 @myronmarston myronmarston committed Jan 1, 2013
View
@@ -18,3 +18,4 @@ vendor
Gemfile-custom
.idea
bundle
+.rspec-local
View
@@ -1,3 +1,4 @@
+language: ruby
before_install:
- if [[ `gem -v` != 1.8.* ]]; then gem update --system; fi
script: "script/test_all 2>&1"
@@ -15,6 +16,6 @@ rvm:
matrix:
allow_failures:
- rvm: 2.0.0
- - rbx-19mode
- - rbx-18mode
+ - rvm: rbx-19mode
+ - rvm: rbx-18mode
View
@@ -1,3 +1,29 @@
+### dev
+[full changelog](http://github.com/rspec/rspec-core/compare/v2.12.2...master)
+
+Enhancements
+
+* Allow `--profile` option to take a count argument that
+ determines the number of slow examples to dump
+ (Greggory Rothmeier).
+* Add `subject!` that is the analog to `let!`. It defines an
+ explicit subject and sets a `before` hook that will invoke
+ the subject (Zubin Henner).
+* Fix `let` and `subject` declaration so that `super`
+ and `return` can be used in them, just like in a normal
+ method. (Myron Marston)
+
+Bug fixes
+
+* Don't blow up when dumping error output for instances
+ of anonymous error classes (Myron Marston).
+* Fix default backtrace filters so lines from projects
+ containing "gems" in the name are not filtered, but
+ lines from installed gems still are (Myron Marston).
+* Fix autotest command so that is uses double quotes
+ rather than single quotes for windows compatibility
+ (Jonas Tingeborn).
+
### 2.12.2 / 2012-12-13
[full changelog](http://github.com/rspec/rspec-core/compare/v2.12.1...v2.12.2)
@@ -0,0 +1,161 @@
+Feature: profile examples
+
+ Use the profile_count option to tell RSpec have many specs to include in the profile:
+
+ RSpec.configure { |c| c.profile_examples = 15 }
+
+ Background:
+ Given a file named "spec/spec_helper.rb" with:
+ """ruby
+ """
+ And a file named "spec/example_spec.rb" with:
+ """ruby
+ require "spec_helper"
+
+ describe "something" do
+ it "sleeps for 0.1 secionds (example 1)" do
+ sleep 0.1
+ 1.should == 1
+ end
+
+ it "sleeps for 0 seconds (example 2)" do
+ 2.should == 2
+ end
+
+ it "sleeps for 0.15 seconds (example 3)" do
+ sleep 0.15
+ 3.should == 3
+ end
+
+ it "sleeps for 0.05 seconds (example 4)" do
+ sleep 0.05
+ 4.should == 4
+ end
+
+ it "sleeps for 0.05 seconds (example 5)" do
+ sleep 0.05
+ 5.should == 5
+ end
+
+ it "sleeps for 0.05 seconds (example 6)" do
+ sleep 0.05
+ 6.should == 6
+ end
+
+ it "sleeps for 0.05 seconds (example 7)" do
+ sleep 0.05
+ 7.should == 7
+ end
+
+ it "sleeps for 0.05 seconds (example 8)" do
+ sleep 0.05
+ 8.should == 8
+ end
+
+ it "sleeps for 0.05 seconds (example 9)" do
+ sleep 0.05
+ 9.should == 9
+ end
+
+ it "sleeps for 0.05 seconds (example 10)" do
+ sleep 0.05
+ 10.should == 10
+ end
+
+ it "sleeps for 0.05 seconds (example 11)" do
+ sleep 0.05
+ 11.should == 11
+ end
+ end
+ """
+
+ Scenario: by default does not show profile
+ When I run `rspec spec`
+ Then the examples should all pass
+ And the output should not contain "example 1"
+ And the output should not contain "example 2"
+ And the output should not contain "example 3"
+ And the output should not contain "example 4"
+ And the output should not contain "example 5"
+ And the output should not contain "example 6"
+ And the output should not contain "example 7"
+ And the output should not contain "example 8"
+ And the output should not contain "example 9"
+ And the output should not contain "example 10"
+ And the output should not contain "example 11"
+
+ Scenario: setting `profile_examples` to true shows 10 examples
+ Given a file named "spec/spec_helper.rb" with:
+ """ruby
+ RSpec.configure { |c| c.profile_examples = true }
+ """
+ When I run `rspec spec`
+ 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: setting `profile_examples` to 2 shows 2 examples
+ Given a file named "spec/spec_helper.rb" with:
+ """ruby
+ RSpec.configure { |c| c.profile_examples = 2 }
+ """
+ When I run `rspec spec`
+ Then the examples should all pass
+ And the output should contain "Top 2 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 not contain "example 4"
+ And the output should not contain "example 5"
+ And the output should not contain "example 6"
+ And the output should not contain "example 7"
+ And the output should not contain "example 8"
+ And the output should not contain "example 9"
+ And the output should not contain "example 10"
+ And the output should not contain "example 11"
+
+ Scenario: setting profile examples through CLI
+ When I run `rspec spec --profile 2`
+ Then the examples should all pass
+ And the output should contain "Top 2 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 not contain "example 4"
+ And the output should not contain "example 5"
+ And the output should not contain "example 6"
+ And the output should not contain "example 7"
+ And the output should not contain "example 8"
+ And the output should not contain "example 9"
+ And the output should not contain "example 10"
+ And the output should not contain "example 11"
+
+ Scenario: Using `--no-profile` overrules config options
+ Given a file named "spec/spec_helper.rb" with:
+ """ruby
+ RSpec.configure { |c| c.profile_examples = true }
+ """
+ When I run `rspec spec --no-profile`
+ Then the examples should all pass
+ And the output should not contain "example 1"
+ And the output should not contain "example 2"
+ And the output should not contain "example 3"
+ And the output should not contain "example 4"
+ And the output should not contain "example 5"
+ And the output should not contain "example 6"
+ And the output should not contain "example 7"
+ And the output should not contain "example 8"
+ And the output should not contain "example 9"
+ And the output should not contain "example 10"
+ And the output should not contain "example 11"
+
@@ -80,3 +80,22 @@ Feature: explicit subject
"""
When I run `rspec nil_subject_spec.rb`
Then the examples should all pass
+
+ Scenario: subject bang method
+ Given a file named "subject_bang_spec.rb" with:
+ """ruby
+ describe Array do
+ describe '#pop' do
+ let(:prepared_array) { [1,2,3] }
+ subject! { prepared_array.pop }
+ it "removes the last value from the array" do
+ prepared_array.should eq([1,2])
+ end
+ it "returns the last value of the array" do
+ subject.should eq(3)
+ end
+ end
+ end
+ """
+ When I run `rspec subject_bang_spec.rb`
+ Then the examples should all pass
View
@@ -47,7 +47,7 @@ def consolidate_failures(failed)
# Overrides Autotest's implementation to generate the rspec command to run
def make_test_cmd(files_to_test)
files_to_test.empty? ? '' :
- "#{prefix}'#{ruby}'#{suffix} -S '#{RSPEC_EXECUTABLE}' --tty #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
+ %|#{prefix}"#{ruby}"#{suffix} -S "#{RSPEC_EXECUTABLE}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
end
# Generates a map of filenames to Arrays for Autotest
@@ -122,7 +122,8 @@ def self.add_setting(name, opts={})
# Load files matching this pattern (default: `'**/*_spec.rb'`)
add_setting :pattern, :alias_with => :filename_pattern
- # Report the times for the 10 slowest examples (default: `false`).
+ # Report the times for the slowest examples (default: `false`).
+ # Use this to specify the number of examples to include in the profile.
add_setting :profile_examples
# Run all examples if none match the configured filters (default: `false`).
@@ -185,7 +186,7 @@ def self.add_setting(name, opts={})
/\/lib\d*\/ruby\//,
/org\/jruby\//,
/bin\//,
- /gems/,
+ %r|/gems/|,
/spec\/spec_helper\.rb/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
@@ -210,6 +211,7 @@ def initialize
@default_color = :white
@fixed_color = :blue
@detail_color = :cyan
+ @profile_examples = false
end
# @private
@@ -521,6 +523,19 @@ def reporter
end
end
+ # @api private
+ #
+ # Defaults `profile_examples` to 10 examples when `@profile_examples` is `true`.
+ #
+ def profile_examples
+ profile = value_for(:profile_examples, @profile_examples)
+ if profile && !profile.is_a?(Integer)
+ 10
+ else
+ profile
+ end
+ end
+
# @private
def files_or_directories_to_run=(*files)
files = files.flatten
@@ -30,7 +30,7 @@ def deprecate(method, alternate_method=nil, version=nil)
#
# Used internally to print deprecation warnings
def warn_deprecation(message)
- send :warn, message
+ warn message
end
end
end
@@ -43,8 +43,7 @@ def colorise_summary(summary)
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
- # Don't print out profiled info if there are failures, it just clutters the output
- dump_profile if profile_examples? && failure_count == 0
+ dump_profile if profile_examples?
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
@@ -67,11 +66,12 @@ def dump_commands_to_rerun_failed_examples
# @api public
#
- # Outputs the 10 slowest examples in a report when using `--profile`.
+ # Outputs the slowest examples in a report when using `--profile COUNT` (default 10).
#
def dump_profile
+ number_of_examples = RSpec.configuration.profile_examples
sorted_examples = examples.sort_by {|example|
- example.execution_result[:run_time] }.reverse.first(10)
+ example.execution_result[:run_time] }.reverse.first(number_of_examples)
total, slows = [examples, sorted_examples].map {|exs|
exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }}
@@ -257,14 +257,22 @@ def dump_failure(example, index)
def dump_failure_info(example)
exception = example.execution_result[:exception]
+ exception_class_name = exception_class_name_for(exception)
output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
- output.puts "#{long_padding}#{failure_color(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
+ output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/
exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
+
if shared_group = find_shared_group(example)
dump_shared_failure_info(shared_group)
end
end
+ def exception_class_name_for(exception)
+ name = exception.class.name.to_s
+ name ="(anonymous error class)" if name == ''
+ name
+ end
+
def dump_shared_failure_info(group)
output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
"#{backtrace_line(group.metadata[:example_group][:location])}"
Oops, something went wrong.

0 comments on commit 4eb7ebe

Please sign in to comment.