Skip to content

Commit

Permalink
deprecate :if and :unless as keys for RSpec.configuration.filter_run_…
Browse files Browse the repository at this point in the history
…excluding
  • Loading branch information
dchelimsky committed Nov 6, 2011
1 parent 939c765 commit 44965b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rspec/core/deprecation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module RSpec

class << self
# @api private
#
# Used internally to print deprecation warnings
def deprecate(method, alternate_method=nil, version=nil)
version_string = version ? "rspec-#{version}" : "a future version of RSpec"
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/filter_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ module BackwardCompatibility
# TODO - add deprecation warning on :if/:unless
def update(orig, opposite, *updates)
if updates.last.has_key?(:unless)
RSpec.warn_deprecation("\nDEPRECATION NOTICE: FilterManager#exclude(:unless => #{updates.last[:unless].inspect}) is deprecated with no replacement, and will be removed from rspec-3.0.")
@exclusions[:unless] = updates.last.delete(:unless)
end
if updates.last.has_key?(:if)
RSpec.warn_deprecation("\nDEPRECATION NOTICE: FilterManager#exclude(:if => #{updates.last[:if].inspect}) is deprecated with no replacement, and will be removed from rspec-3.0.")
@exclusions[:if] = updates.last.delete(:if)
end

Expand Down
14 changes: 14 additions & 0 deletions spec/rspec/core/filter_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,27 @@ module RSpec::Core
filter_manager.exclusions.description.should eq({ :foo => :bar }.inspect)
end

it 'deprecates an overridden :if filter' do
RSpec.should_receive(:warn_deprecation).with(/exclude\(:if.*is deprecated/)
filter_manager = FilterManager.new
filter_manager.exclude :if => :custom_filter
end

it 'deprecates an overridden :unless filter' do
RSpec.should_receive(:warn_deprecation).with(/exclude\(:unless.*is deprecated/)
filter_manager = FilterManager.new
filter_manager.exclude :unless => :custom_filter
end

it 'includes an overriden :if filter' do
RSpec.stub(:warn_deprecation)
filter_manager = FilterManager.new
filter_manager.exclude :if => :custom_filter
filter_manager.exclusions.description.should eq({ :if => :custom_filter }.inspect)
end

it 'includes an overriden :unless filter' do
RSpec.stub(:warn_deprecation)
filter_manager = FilterManager.new
filter_manager.exclude :unless => :custom_filter
filter_manager.exclusions.description.should eq({ :unless => :custom_filter }.inspect)
Expand Down

0 comments on commit 44965b4

Please sign in to comment.