Skip to content

Commit

Permalink
Merge 2c58a00 into 8e7ce9f
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Mar 30, 2014
2 parents 8e7ce9f + 2c58a00 commit e28e262
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 47 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -51,6 +51,10 @@ Deprecations:
just `shared_examples`. (Myron Marston)
* Deprecate `RSpec::Core::CommandLine` in favor of
`RSpec::Core::Runner`. (Myron Marston)
* Deprecate `#color_enabled` (and ? and =) in favour of `#color` and friends.
(Jon Rowe)
* Deprecate `#filename_pattern` in favour of `#pattern`. (Jon Rowe)
* Deprecate `#backtrace_cleaner` in favour of `#backtrace_formatter`. (Jon Rowe)

Bug Fixes:

Expand Down
6 changes: 3 additions & 3 deletions features/configuration/read_options_from_file.feature
Expand Up @@ -19,7 +19,7 @@ Feature: read command line configuration options from files
"""
And a file named "spec/example_spec.rb" with:
"""ruby
describe "color_enabled" do
describe "color" do
context "when set with RSpec.configure" do
before do
# color is disabled for non-tty output, so stub the output stream
Expand All @@ -28,7 +28,7 @@ Feature: read command line configuration options from files
end
it "is true" do
RSpec.configuration.should be_color_enabled
RSpec.configuration.should be_color
end
end
end
Expand Down Expand Up @@ -66,7 +66,7 @@ Feature: read command line configuration options from files
"""ruby
describe "custom options file" do
it "causes .rspec to be ignored" do
RSpec.configuration.color_enabled.should be_falsey
RSpec.configuration.color.should be_falsey
end
end
"""
Expand Down
66 changes: 49 additions & 17 deletions lib/rspec/core/configuration.rb
Expand Up @@ -160,15 +160,27 @@ def out=(value)
end

# Load files matching this pattern (default: `'**/*_spec.rb'`)
add_setting :pattern, :alias_with => :filename_pattern
add_setting :pattern

def filename_pattern
RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern`",
:replacement => "`RSpec::Core::Configuration#pattern`"
pattern
end

def pattern= value
if @spec_files_loaded
Kernel.warn "WARNING: Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files. Called from #{CallerFilter.first_non_rspec_line}"
end
@pattern = value
end
alias :filename_pattern= :pattern=

def filename_pattern=(value)
RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern=`",
:replacement => "`RSpec::Core::Configuration#pattern=`"
self.pattern = value
end


# Report the times for the slowest examples (default: `false`).
# Use this to specify the number of examples to include in the profile.
Expand Down Expand Up @@ -258,7 +270,13 @@ def treat_symbols_as_metadata_keys_with_true_values=(value)
# @private
attr_accessor :filter_manager

attr_reader :backtrace_cleaner
attr_reader :backtrace_formatter

def backtrace_cleaner
RSpec.deprecate "`RSpec::Core::Configuration#backtrace_cleaner`",
:replacement => "`RSpec::Core::Configuration#backtrace_formatter`"
@backtrace_formatter
end

def initialize
@expectation_frameworks = []
Expand All @@ -272,7 +290,7 @@ def initialize
@failure_exit_code = 1
@spec_files_loaded = false

@backtrace_cleaner = BacktraceCleaner.new
@backtrace_formatter = BacktraceCleaner.new

@default_path = 'spec'
@deprecation_stream = $stderr
Expand Down Expand Up @@ -382,13 +400,13 @@ def mock_framework=(framework)
def backtrace_clean_patterns
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
@backtrace_cleaner.exclusion_patterns
@backtrace_formatter.exclusion_patterns
end

def backtrace_clean_patterns=(patterns)
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
@backtrace_cleaner.exclusion_patterns = patterns
@backtrace_formatter.exclusion_patterns = patterns
end

# The patterns to always include to backtraces.
Expand All @@ -399,11 +417,11 @@ def backtrace_clean_patterns=(patterns)
# One can replace the list by using the setter or modify it through the
# getter
def backtrace_inclusion_patterns
@backtrace_cleaner.inclusion_patterns
@backtrace_formatter.inclusion_patterns
end

def backtrace_inclusion_patterns=(patterns)
@backtrace_cleaner.inclusion_patterns = patterns
@backtrace_formatter.inclusion_patterns = patterns
end

# The patterns to discard from backtraces.
Expand All @@ -417,11 +435,11 @@ def backtrace_inclusion_patterns=(patterns)
# `--backtrace`on the command line, in a `.rspec` file, or in the
# `rspec_options` attribute of RSpec's rake task.
def backtrace_exclusion_patterns
@backtrace_cleaner.exclusion_patterns
@backtrace_formatter.exclusion_patterns
end

def backtrace_exclusion_patterns=(patterns)
@backtrace_cleaner.exclusion_patterns = patterns
@backtrace_formatter.exclusion_patterns = patterns
end

# Sets the mock framework adapter module.
Expand Down Expand Up @@ -558,11 +576,11 @@ def expect_with(*frameworks)
end

def full_backtrace?
@backtrace_cleaner.full_backtrace?
@backtrace_formatter.full_backtrace?
end

def full_backtrace=(true_or_false)
@backtrace_cleaner.full_backtrace = true_or_false
@backtrace_formatter.full_backtrace = true_or_false
end

def color(output=output_stream)
Expand All @@ -584,11 +602,25 @@ def color=(bool)
end
end

# TODO - deprecate color_enabled - probably not until the last 2.x
# release before 3.0
alias_method :color_enabled, :color
alias_method :color_enabled=, :color=
define_predicate_for :color_enabled, :color
define_predicate_for :color

def color_enabled(output=output_stream)
RSpec.deprecate "RSpec::Core::Configuration#color_enabled",
:replacement => "RSpec::Core::Configuration#color"
color output_stream
end

def color_enabled=(bool)
RSpec.deprecate "RSpec::Core::Configuration#color_enabled=",
:replacement => "RSpec::Core::Configuration#color="
self.color = bool
end

def color_enabled?(output=output_stream)
RSpec.deprecate "RSpec::Core::Configuration#color_enabled?",
:replacement => "RSpec::Core::Configuration#color?"
color? output_stream
end

def libs=(libs)
libs.map do |lib|
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/base_formatter.rb
Expand Up @@ -233,7 +233,7 @@ def fail_fast?
end

def color_enabled?
configuration.color_enabled?(output)
configuration.color?(output)
end

def mute_profile_output?(failure_count)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/console_codes.rb
Expand Up @@ -29,7 +29,7 @@ def console_code_for(code_or_symbol)
end

def wrap(text, code_or_symbol)
if RSpec.configuration.color_enabled?
if RSpec.configuration.color?
"\e[#{console_code_for(code_or_symbol)}m#{text}\e[0m"
else
text
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/helpers.rb
Expand Up @@ -18,7 +18,7 @@ def format_backtrace(backtrace, options = {})
protected

def backtrace_line(line)
return nil if RSpec.configuration.backtrace_cleaner.exclude?(line)
return nil if RSpec.configuration.backtrace_formatter.exclude?(line)
RSpec::Core::Metadata::relative_path(line)
rescue SecurityError
nil
Expand Down
4 changes: 2 additions & 2 deletions spec/autotest/failed_results_re_spec.rb
Expand Up @@ -29,15 +29,15 @@ def run_example

context "with color enabled" do
before do
RSpec.configuration.stub(:color_enabled? => true)
RSpec.configuration.stub(:color? => true)
end

include_examples "autotest failed_results_re"
end

context "with color disabled " do
before do
RSpec.configuration.stub(:color_enabled? => false)
RSpec.configuration.stub(:color? => false)
end

include_examples "autotest failed_results_re"
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/configuration_options_spec.rb
Expand Up @@ -75,7 +75,7 @@
expect(config.exclusion_filter).to have_key(:slow)
end

it "forces color_enabled" do
it "forces color" do
opts = config_options_object(*%w[--color])
config = RSpec::Core::Configuration.new
config.should_receive(:force).with(:color => true)
Expand Down
45 changes: 36 additions & 9 deletions spec/rspec/core/configuration_spec.rb
Expand Up @@ -598,8 +598,20 @@ def specify_consistent_ordering_of_files_to_run
end
end

specify "#filename_pattern is deprecated" do
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
config.filename_pattern
end

specify "#filename_pattern= is deprecated" do
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
config.filename_pattern = "/whatever"
end

%w[pattern= filename_pattern=].each do |setter|
describe "##{setter}" do
before { allow_deprecation } if setter == "filename_pattern="

context "with single pattern" do
before { config.send(setter, "**/*_foo.rb") }
it "loads files following pattern" do
Expand Down Expand Up @@ -815,8 +827,16 @@ def metadata_hash(*args)
end
end


%w[color color_enabled].each do |color_option|
describe "##{color_option}=" do
before { allow_deprecation } if color_option == 'color_enabled'

specify "color_enabled is deprecated" do
expect_deprecation_with_call_site __FILE__, __LINE__+1
config.color_enabled = true
end

context "given true" do
before { config.send "#{color_option}=", true }

Expand Down Expand Up @@ -1206,7 +1226,7 @@ def metadata_hash(*args)
RSpec.stub(:deprecate)
config = Configuration.new
config.backtrace_clean_patterns = [/.*/]
expect(config.backtrace_cleaner.exclude? "this").to be_truthy
expect(config.backtrace_formatter.exclude? "this").to be_truthy
end
end

Expand All @@ -1233,33 +1253,40 @@ def metadata_hash(*args)
it "can be appended to" do
config = Configuration.new
config.backtrace_clean_patterns << /.*/
expect(config.backtrace_cleaner.exclude? "this").to be_truthy
expect(config.backtrace_formatter.exclude? "this").to be_truthy
end
end

describe ".backtrace_cleaner#exclude? defaults" do
specify "#backtrace_cleaner is deprecated" do
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
config.backtrace_cleaner
end

describe ".backtrace_formatter#exclude? defaults" do
before { allow_deprecation }

it "returns true for rspec files" do
expect(config.backtrace_cleaner.exclude?("lib/rspec/core.rb")).to be_truthy
expect(config.backtrace_formatter.exclude?("lib/rspec/core.rb")).to be_truthy
end

it "returns true for spec_helper" do
expect(config.backtrace_cleaner.exclude?("spec/spec_helper.rb")).to be_truthy
expect(config.backtrace_formatter.exclude?("spec/spec_helper.rb")).to be_truthy
end

it "returns true for java files (for JRuby)" do
expect(config.backtrace_cleaner.exclude?("org/jruby/RubyArray.java:2336")).to be_truthy
expect(config.backtrace_formatter.exclude?("org/jruby/RubyArray.java:2336")).to be_truthy
end

it "returns true for files within installed gems" do
expect(config.backtrace_cleaner.exclude?('ruby-1.8.7-p334/gems/mygem-2.3.0/lib/mygem.rb')).to be_truthy
expect(config.backtrace_formatter.exclude?('ruby-1.8.7-p334/gems/mygem-2.3.0/lib/mygem.rb')).to be_truthy
end

it "returns false for files in projects containing 'gems' in the name" do
expect(config.backtrace_cleaner.exclude?('code/my-gems-plugin/lib/plugin.rb')).to be_falsey
expect(config.backtrace_formatter.exclude?('code/my-gems-plugin/lib/plugin.rb')).to be_falsey
end

it "returns false for something in the current working directory" do
expect(config.backtrace_cleaner.exclude?("#{Dir.getwd}/arbitrary")).to be_falsey
expect(config.backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be_falsey
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/rspec/core/formatters/base_text_formatter_spec.rb
Expand Up @@ -34,7 +34,7 @@
describe "#dump_failures" do
let(:group) { RSpec::Core::ExampleGroup.describe("group name") }

before { RSpec.configuration.stub(:color_enabled?) { false } }
before { RSpec.configuration.stub(:color?) { false } }

def run_all_and_dump_failures
group.run(formatter)
Expand Down Expand Up @@ -194,7 +194,7 @@ def run_all_and_dump_failures
describe "#dump_pending" do
let(:group) { RSpec::Core::ExampleGroup.describe("group name") }

before { RSpec.configuration.stub(:color_enabled?) { false } }
before { RSpec.configuration.stub(:color?) { false } }

def run_all_and_dump_pending
group.run(formatter)
Expand Down Expand Up @@ -446,7 +446,7 @@ def run_all_and_dump_pending
describe "custom_colors" do
it "uses the custom success color" do
RSpec.configure do |config|
config.color_enabled = true
config.color = true
config.tty = true
config.success_color = :cyan
end
Expand All @@ -457,7 +457,7 @@ def run_all_and_dump_pending

describe "#colorize" do
before do
allow(RSpec.configuration).to receive(:color_enabled?) { true }
allow(RSpec.configuration).to receive(:color?) { true }
end

it "accepts a VT100 integer code and formats the text with it" do
Expand Down Expand Up @@ -495,7 +495,7 @@ def run_all_and_dump_pending

describe "##{name}" do
before do
allow(RSpec.configuration).to receive(:color_enabled?) { true }
allow(RSpec.configuration).to receive(:color?) { true }
allow(RSpec).to receive(:deprecate)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/formatters/console_codes_spec.rb
Expand Up @@ -26,7 +26,7 @@

describe "#wrap" do
before do
allow(RSpec.configuration).to receive(:color_enabled?) { true }
allow(RSpec.configuration).to receive(:color?) { true }
end

context "when given a VT100 integer code" do
Expand Down

0 comments on commit e28e262

Please sign in to comment.