Skip to content
Browse files

Add :alias_with option to configuration.add_setting and deprecate the

:alias key.
  • Loading branch information...
1 parent 8d53640 commit f87e9d777db12b1f0607eb8170897ac180586129 @dchelimsky dchelimsky committed
Showing with 43 additions and 19 deletions.
  1. +6 −1 Changelog.md
  2. +26 −14 lib/rspec/core/configuration.rb
  3. +11 −4 spec/rspec/core/configuration_spec.rb
View
7 Changelog.md
@@ -1,13 +1,18 @@
-### DEV
+### 2.8.0 (in development)
* Enhancements
* --order (Justin Ko)
* Run your examples in random order: `--order rand`
* Pass a seed: `--order random:123`
* SharedContext supports `let` (David Chelimsky)
+ * Override opposing tags from the command line (David Chelimsky)
* Bug fixes
* Make sure the `bar` in `--tag foo:bar` makes it to DRb (Aaron Gibralter)
+
+* Deprecations
+ * :alias option on `configuration.add_setting`. Use `:alias_with` on the
+ original setting declaration instead.
### 2.7.1 / 2011-10-20
View
40 lib/rspec/core/configuration.rb
@@ -14,10 +14,15 @@ def self.define_predicate_for(name)
# @api private
#
- # Delegated to by the `add_setting` instance method.
+ # Invoked by the `add_setting` instance method. Use that method on a
+ # `Configuration` instance rather than this class method.
def self.add_setting(name, opts={})
raise "Use the instance add_setting method if you want to set a default" if opts.has_key?(:default)
if opts[:alias]
+ RSpec.warn_deprecation <<-MESSAGE
+The :alias option to add_setting is deprecated. Use :alias_with on the original setting instead.
+Called from #{caller(0)[4]}
+MESSAGE
alias_method name, opts[:alias]
alias_method "#{name}=", "#{opts[:alias]}="
define_predicate_for name
@@ -25,20 +30,24 @@ def self.add_setting(name, opts={})
attr_accessor name
define_predicate_for name
end
+ if opts[:alias_with]
+ [opts[:alias_with]].flatten.each do |alias_name|
+ alias_method alias_name, name
+ alias_method "#{alias_name}=", "#{name}="
+ define_predicate_for alias_name
+ end
+ end
end
add_setting :error_stream
- add_setting :output_stream
- add_setting :output, :alias => :output_stream
- add_setting :out, :alias => :output_stream
+ add_setting :output_stream, :alias_with => [:output, :out]
add_setting :drb
add_setting :drb_port
add_setting :profile_examples
add_setting :fail_fast
add_setting :failure_exit_code
add_setting :run_all_when_everything_filtered
- add_setting :pattern
- add_setting :filename_pattern, :alias => :pattern
+ add_setting :pattern, :alias_with => :filename_pattern
add_setting :files_to_run
add_setting :include_or_extend_modules
add_setting :backtrace_clean_patterns
@@ -95,8 +104,9 @@ def reset
# can add config settings that are domain specific. For example:
#
# RSpec.configure do |c|
- # c.add_setting :use_transactional_fixtures, :default => true
- # c.add_setting :use_transactional_examples, :alias => :use_transactional_fixtures
+ # c.add_setting :use_transactional_fixtures,
+ # :default => true,
+ # :alias_with => :use_transactional_examples
# end
#
# `add_setting` creates three methods on the configuration object, a
@@ -109,16 +119,18 @@ def reset
# ### Options
#
# `add_setting` takes an optional hash that supports the keys `:default`
- # and `:alias`.
+ # and `:alias_with`.
#
# Use `:default` to set a default value for the generated getter and
# predicate methods:
#
- # :default => "default value"
+ # add_setting(:foo, :default => "default value")
#
- # Use `:alias` to alias the setter, getter, and predicate to another name:
+ # Use `:alias_with` to alias the setter, getter, and predicate to another
+ # name, or names:
#
- # :alias => :other_setting
+ # add_setting(:foo, :alias_with => :bar)
+ # add_setting(:foo, :alias_with => [:bar, :baz])
#
def add_setting(name, opts={})
default = opts.delete(:default)
@@ -204,7 +216,7 @@ def expectation_framework=(framework)
# Sets the expectation framework module(s).
#
- # `frameworks` can be :rspec, :stdlib, or both
+ # `frameworks` can be :rspec, :stdlib, or both
#
# Given :rspec, configures rspec/expectations.
# Given :stdlib, configures test/unit/assertions
@@ -610,7 +622,7 @@ def custom_formatter(formatter_ref)
end
end
end
-
+
def string_const?(str)
str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
end
View
15 spec/rspec/core/configuration_spec.rb
@@ -192,7 +192,7 @@ module RSpec::Core
config.files_to_run.should eq([file])
end
end
-
+
context "with default default_path" do
it "loads files in the default path when run by rspec" do
config.stub(:command) { 'rspec' }
@@ -296,7 +296,7 @@ module RSpec::Core
config.full_description = "foo"
config.filter.should eq({:full_description => /foo/})
end
-
+
describe "#default_path" do
it 'defaults to "spec"' do
config.default_path.should eq('spec')
@@ -434,7 +434,7 @@ def metadata_hash(*args)
after(:all) do
ENV['ANSICON'] = @original_ansicon
end
-
+
it "enables colors" do
config.output_stream = StringIO.new
config.output_stream.stub(:tty?) { true }
@@ -844,10 +844,17 @@ def metadata_hash(*args)
end
context "with :alias => " do
- before do
+ it "is deprecated" do
+ RSpec::should_receive(:warn).with /deprecated/
config.add_setting :custom_option
config.add_setting :another_custom_option, :alias => :custom_option
end
+ end
+
+ context "with :alias_with => " do
+ before do
+ config.add_setting :custom_option, :alias_with => :another_custom_option
+ end
it "delegates the getter to the other option" do
config.another_custom_option = "this value"

0 comments on commit f87e9d7

Please sign in to comment.
Something went wrong with that request. Please try again.