diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 4c8f2a9cb1..4ed63c64c8 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -76,11 +76,6 @@ def #{name} add_setting :show_failures_in_pending_blocks add_setting :order - DEFAULT_EXCLUSION_FILTERS = { - :if => lambda { |value, metadata| metadata.has_key?(:if) && !value }, - :unless => lambda { |value| value } - } - DEFAULT_BACKTRACE_PATTERNS = [ /\/lib\d*\/ruby\//, /org\/jruby\//, @@ -102,7 +97,6 @@ def initialize @backtrace_clean_patterns = DEFAULT_BACKTRACE_PATTERNS.dup @default_path = 'spec' @filter = Filter.new - @filter.exclude DEFAULT_EXCLUSION_FILTERS.dup @preferred_options = {} @seed = srand % 0xFFFF end @@ -111,6 +105,14 @@ def force(hash) @preferred_options.merge!(hash) end + def force_include(hash) + @filter.include hash + end + + def force_exclude(hash) + @filter.exclude hash + end + def reset @reporter = nil @formatters.clear @@ -474,7 +476,7 @@ def filter_run_including(*args) elsif contains_standalone_filter?(filter) @filter.inclusions.replace(filter) else - @filter.include filter + @filter.include :late, filter end end @@ -484,7 +486,7 @@ def filter_run_including(*args) # want any inclusion filter at all. def inclusion_filter=(filter) filter = build_metadata_hash_from([filter]) - filter.empty? ? @filter.inclusions.clear : @filter.inclusions.replace(filter) + filter.empty? ? inclusion_filter.clear : inclusion_filter.replace(filter) end alias_method :filter=, :inclusion_filter= @@ -492,7 +494,7 @@ def inclusion_filter=(filter) # Returns the `inclusion_filter`. If none has been set, returns an empty # hash. def inclusion_filter - value_for(:inclusion_filter, @filter.inclusions) || {} + @filter.inclusions end alias_method :filter, :inclusion_filter @@ -508,20 +510,20 @@ def inclusion_filter # # with treat_symbols_as_metadata_keys_with_true_values = true # filter_run_excluding :foo # results in {:foo => true} def filter_run_excluding(*args) - @filter.exclude build_metadata_hash_from(args) + @filter.exclude :late, build_metadata_hash_from(args) end # Clears and reassigns the `exclusion_filter`. Set to `nil` if you don't # want any exclusion filter at all. def exclusion_filter=(filter) filter = build_metadata_hash_from([filter]) - filter.empty? ? @filter.exclusions.clear : @filter.exclusions.replace(filter) + filter.empty? ? exclusion_filter.clear : exclusion_filter.replace(filter) end # Returns the `exclusion_filter`. If none has been set, returns an empty # hash. def exclusion_filter - value_for(:exclusion_filter, @filter.exclusions) || {} + @filter.exclusions end STANDALONE_FILTERS = [:line_numbers, :full_description] @@ -598,14 +600,7 @@ def order=(type) private def value_for(key, default=nil) - if [:inclusion_filter, :exclusion_filter].any? {|k| key == k} - local = { :inclusion_filter => @filter.inclusions, :exclusion_filter => @filter.exclusions } - Configuration.reconcile_opposing_filters(local, @preferred_options, :inclusion_filter, :exclusion_filter) - Configuration.reconcile_opposing_filters(local, @preferred_options, :exclusion_filter, :inclusion_filter) - @preferred_options.has_key?(key) ? default.merge(@preferred_options[key]) : default - else - @preferred_options.has_key?(key) ? @preferred_options[key] : default - end + @preferred_options.has_key?(key) ? @preferred_options[key] : default end def add_location(file_path, line_numbers) diff --git a/lib/rspec/core/configuration_options.rb b/lib/rspec/core/configuration_options.rb index c6924f2fb4..ecb2aae31a 100644 --- a/lib/rspec/core/configuration_options.rb +++ b/lib/rspec/core/configuration_options.rb @@ -12,6 +12,9 @@ def initialize(args) def configure(config) formatters = options.delete(:formatters) + config.force_exclude options.delete(:exclusion_filter) || {} + config.force_include options.delete(:inclusion_filter) || {} + order(options.keys, :libs, :requires, :default_path, :pattern).each do |key| force?(key) ? config.force(key => options[key]) : config.send("#{key}=", options[key]) end diff --git a/lib/rspec/core/example.rb b/lib/rspec/core/example.rb index b15684927f..45e3100644 100644 --- a/lib/rspec/core/example.rb +++ b/lib/rspec/core/example.rb @@ -132,6 +132,10 @@ def fail_with_exception(reporter, exception) finish(reporter) end + def any_apply?(filters) + metadata.any_apply?(filters) + end + private def with_around_hooks(&block) diff --git a/lib/rspec/core/filter.rb b/lib/rspec/core/filter.rb index 8b87f4402e..e11b75b61a 100644 --- a/lib/rspec/core/filter.rb +++ b/lib/rspec/core/filter.rb @@ -1,17 +1,63 @@ module RSpec module Core class Filter + DEFAULT_EXCLUSIONS = { + :if => lambda { |value, metadata| metadata.has_key?(:if) && !value }, + :unless => lambda { |value| value } + } + + module Describable + PROC_HEX_NUMBER = /0x[0-9a-f]+@/ + PROJECT_DIR = File.expand_path('.') + + def description + reject { |k, v| RSpec::Core::Filter::DEFAULT_EXCLUSIONS[k] == v }.inspect.gsub(PROC_HEX_NUMBER, '').gsub(PROJECT_DIR, '.').gsub(' (lambda)','') + end + + def empty_without_conditional_filters? + reject { |k, v| RSpec::Core::Filter::DEFAULT_EXCLUSIONS[k] == v }.empty? + end + + def reject + super rescue {} + end + + def empty? + super rescue false + end + end + + module BackwardCompatibility + # This is to support a use case that probably doesn't exist: overriding + # the if/unless procs. + # + # TODO - add deprecation warning on :if/:unless + def update(orig, opposite, *updates) + if updates.last.has_key?(:unless) + @exclusions[:unless] = updates.last.delete(:unless) + end + if updates.last.has_key?(:if) + @exclusions[:if] = updates.last.delete(:if) + end + + super + end + end + attr_reader :exclusions, :inclusions def initialize - @exclusions = {} - @inclusions = {} + @exclusions = DEFAULT_EXCLUSIONS.dup.extend(Describable) + @inclusions = {}.extend(Describable) + extend(BackwardCompatibility) end - def filter(examples) + def prune(examples) examples.select {|e| !exclude?(e) && include?(e)} end + alias_method :filter, :prune + def exclude?(example) @exclusions.empty? ? false : example.any_apply?(@exclusions) end @@ -21,15 +67,21 @@ def include?(example) end def exclude(*args) - @exclusions = update(@exclusions, *args) + @exclusions = update(@exclusions, @inclusions, *args) end def include(*args) - @inclusions = update(@inclusions, *args) + @inclusions = update(@inclusions, @exclusions, *args) end - def update(orig, *updates) - updates.length == 2 ? updates.last.merge(orig) : orig.merge(updates.last) + def update(orig, opposite, *updates) + if updates.length == 2 + updated = updates.last.merge(orig) + opposite.each_key {|k| updated.delete(k)} + orig.replace(updated) + else + orig.merge!(updates.last).each_key {|k| opposite.delete(k)} + end end end end diff --git a/lib/rspec/core/world.rb b/lib/rspec/core/world.rb index 7b349fe3d5..1759655683 100644 --- a/lib/rspec/core/world.rb +++ b/lib/rspec/core/world.rb @@ -2,27 +2,6 @@ module RSpec module Core class World - module Describable - PROC_HEX_NUMBER = /0x[0-9a-f]+@/ - PROJECT_DIR = File.expand_path('.') - - def description - reject { |k, v| RSpec::Core::Configuration::DEFAULT_EXCLUSION_FILTERS[k] == v }.inspect.gsub(PROC_HEX_NUMBER, '').gsub(PROJECT_DIR, '.').gsub(' (lambda)','') - end - - def empty_without_conditional_filters? - reject { |k, v| RSpec::Core::Configuration::DEFAULT_EXCLUSION_FILTERS[k] == v }.empty? - end - - def reject - super rescue {} - end - - def empty? - super rescue false - end - end - include RSpec::Core::Hooks attr_reader :example_groups, :filtered_examples, :wants_to_quit @@ -31,13 +10,10 @@ def empty? def initialize(configuration=RSpec.configuration) @configuration = configuration @example_groups = [].extend(Extensions::Ordered) - @configuration.inclusion_filter.extend(Describable) - @configuration.exclusion_filter.extend(Describable) @filtered_examples = Hash.new { |hash,group| hash[group] = begin examples = group.examples.dup - examples = apply_exclusion_filters(examples, exclusion_filter) - examples = apply_inclusion_filters(examples, inclusion_filter) + examples = filter.filter(examples) examples.uniq examples.extend(Extensions::Ordered) end @@ -48,17 +24,22 @@ def reset example_groups.clear end + # TODO - fix me + def filter + @configuration.instance_variable_get("@filter") + end + def register(example_group) example_groups << example_group example_group end def inclusion_filter - @configuration.inclusion_filter.extend(Describable) + @configuration.inclusion_filter end def exclusion_filter - @configuration.exclusion_filter.extend(Describable) + @configuration.exclusion_filter end def configure_group(group) @@ -73,16 +54,6 @@ def example_count example_groups.collect {|g| g.descendants}.flatten.inject(0) { |sum, g| sum += g.filtered_examples.size } end - def apply_inclusion_filters(examples, filters) - filters.empty? ? examples : examples.select {|e| e.metadata.any_apply?(filters)} - end - - alias_method :find, :apply_inclusion_filters - - def apply_exclusion_filters(examples, filters) - filters.empty? ? examples : examples.reject {|e| e.metadata.any_apply?(filters)} - end - def preceding_declaration_line(filter_line) declaration_line_numbers.sort.inject(nil) do |highest_prior_declaration_line, line| line <= filter_line ? line : highest_prior_declaration_line @@ -99,7 +70,7 @@ def announce_filters if @configuration.run_all_when_everything_filtered? && example_count.zero? reporter.message( "No examples matched #{inclusion_filter.description}. Running all.") filtered_examples.clear - @configuration.inclusion_filter.clear + inclusion_filter.clear end announce_inclusion_filter filter_announcements diff --git a/spec/rspec/core/command_line_spec.rb b/spec/rspec/core/command_line_spec.rb index 52f3c70921..5d029c009a 100644 --- a/spec/rspec/core/command_line_spec.rb +++ b/spec/rspec/core/command_line_spec.rb @@ -96,7 +96,6 @@ def config_options(argv=[]) config.should_receive(:error_stream=).ordered config.should_receive(:output_stream=).ordered config.should_receive(:force).with(:default_path => anything).ordered - config.should_receive(:force).with(:exclusion_filter => anything).ordered config.should_receive(:force).with(:color => true).ordered command_line.run(err, out) rescue nil end diff --git a/spec/rspec/core/configuration_options_spec.rb b/spec/rspec/core/configuration_options_spec.rb index c6e2512d88..6377bee6ae 100644 --- a/spec/rspec/core/configuration_options_spec.rb +++ b/spec/rspec/core/configuration_options_spec.rb @@ -65,14 +65,14 @@ it "forces inclusion_filter" do opts = config_options_object(*%w[--tag foo:bar]) config = RSpec::Core::Configuration.new - config.should_receive(:force).with(:inclusion_filter => {:foo => 'bar'}) + config.should_receive(:force_include).with(:foo => 'bar') opts.configure(config) end it "forces exclusion_filter" do opts = config_options_object(*%w[--tag ~foo:bar]) config = RSpec::Core::Configuration.new - config.should_receive(:force).with(:exclusion_filter => {:foo => 'bar'}) + config.should_receive(:force_exclude).with(:foo => 'bar') opts.configure(config) end diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 08777d4050..3eebc218f1 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -651,7 +651,7 @@ def metadata_hash(*args) end it "gets overrided by forced options" do - config.force :exclusion_filter => { :foo => true } + config.force_exclude :foo => true config.filter_run_including :foo => true config.inclusion_filter.should eq({}) end @@ -704,7 +704,7 @@ def metadata_hash(*args) it "gets overrided by forced options" do config.exclusion_filter.clear - config.force :inclusion_filter => { :foo => true } + config.force_include :foo => true config.filter_run_excluding :foo => true config.exclusion_filter.should eq({}) end diff --git a/spec/rspec/core/example_group_spec.rb b/spec/rspec/core/example_group_spec.rb index 7c24d6e031..17dc63cfe9 100644 --- a/spec/rspec/core/example_group_spec.rb +++ b/spec/rspec/core/example_group_spec.rb @@ -121,7 +121,11 @@ def metadata_hash(*args) shared_examples "matching filters" do context "inclusion" do - before { world.stub(:inclusion_filter).and_return(filter_metadata) } + before do + filter = Filter.new + filter.include filter_metadata + world.stub(:filter => filter) + end it "includes examples in groups matching filter" do group = ExampleGroup.describe("does something", spec_metadata) @@ -145,7 +149,12 @@ def metadata_hash(*args) end context "exclusion" do - before { world.stub(:exclusion_filter).and_return(filter_metadata) } + before do + filter = Filter.new + filter.exclude filter_metadata + world.stub(:filter => filter) + end + it "excludes examples in groups matching filter" do group = ExampleGroup.describe("does something", spec_metadata) group.stub(:world) { world } @@ -245,7 +254,9 @@ def metadata_hash(*args) context "with no examples or groups that match filters" do it "returns none" do - world.stub(:inclusion_filter).and_return({ :awesome => false }) + filter = Filter.new + filter.include :awesome => false + world.stub(:filter => filter) group = ExampleGroup.describe group.stub(:world) { world } group.example("does something") diff --git a/spec/rspec/core/filter_spec.rb b/spec/rspec/core/filter_spec.rb index 3db7fdce21..84e70b90ee 100644 --- a/spec/rspec/core/filter_spec.rb +++ b/spec/rspec/core/filter_spec.rb @@ -5,6 +5,7 @@ module RSpec::Core %w[inclusions include exclusions exclude].each_slice(2) do |type, name| it "merges #{type}" do filter = Filter.new + filter.exclusions.clear # defaults filter.send name, :foo => :bar filter.send name, :baz => :bam filter.send(type).should eq(:foo => :bar, :baz => :bam) @@ -12,6 +13,7 @@ module RSpec::Core it "overrides previous #{type} (via merge)" do filter = Filter.new + filter.exclusions.clear # defaults filter.send name, :foo => 1 filter.send name, :foo => 2 filter.send(type).should eq(:foo => 2) @@ -19,35 +21,120 @@ module RSpec::Core it "ignores new #{type} if same key exists and priority is low" do filter = Filter.new + filter.exclusions.clear # defaults filter.send name, :foo => 1 filter.send name, :weak, :foo => 2 filter.send(type).should eq(:foo => 1) end end - it "includes objects with tags matching inclusions" do - included = RSpec::Core::Metadata.new({:foo => :bar}) - excluded = RSpec::Core::Metadata.new - filter = Filter.new - filter.include :foo => :bar - filter.filter([included, excluded]).should eq([included]) + describe "#prune" do + it "includes objects with tags matching inclusions" do + included = RSpec::Core::Metadata.new({:foo => :bar}) + excluded = RSpec::Core::Metadata.new + filter = Filter.new + filter.include :foo => :bar + filter.prune([included, excluded]).should eq([included]) + end + + it "excludes objects with tags matching exclusions" do + included = RSpec::Core::Metadata.new + excluded = RSpec::Core::Metadata.new({:foo => :bar}) + filter = Filter.new + filter.exclude :foo => :bar + filter.prune([included, excluded]).should eq([included]) + end + + it "prefers exclusion when matches previously set inclusion" do + included = RSpec::Core::Metadata.new + excluded = RSpec::Core::Metadata.new({:foo => :bar}) + filter = Filter.new + filter.include :foo => :bar + filter.exclude :foo => :bar + filter.filter([included, excluded]).should eq([included]) + end + + it "prefers inclusion when matches previously set exclusion" do + included = RSpec::Core::Metadata.new({:foo => :bar}) + excluded = RSpec::Core::Metadata.new + filter = Filter.new + filter.exclude :foo => :bar + filter.include :foo => :bar + filter.filter([included, excluded]).should eq([included]) + end + + it "prefers previously set inclusion when exclusion matches but has lower priority" do + included = RSpec::Core::Metadata.new({:foo => :bar}) + excluded = RSpec::Core::Metadata.new + filter = Filter.new + filter.include :foo => :bar + filter.exclude :low, :foo => :bar + filter.filter([included, excluded]).should eq([included]) + end + + it "prefers previously set exclusion when inclusion matches but has lower priority" do + included = RSpec::Core::Metadata.new + excluded = RSpec::Core::Metadata.new({:foo => :bar}) + filter = Filter.new + filter.exclude :foo => :bar + filter.include :low, :foo => :bar + filter.filter([included, excluded]).should eq([included]) + end end - it "excludes objects with tags matching exclusions" do - included = RSpec::Core::Metadata.new - excluded = RSpec::Core::Metadata.new({:foo => :bar}) - filter = Filter.new - filter.exclude :foo => :bar - filter.filter([included, excluded]).should eq([included]) + describe "#inclusions#description" do + it 'cleans up the description' do + project_dir = File.expand_path('.') + lambda { }.inspect.should include(project_dir) + lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9' + lambda { }.inspect.should include('0x') + + filter = Filter.new + filter.include :foo => lambda { } + + filter.inclusions.description.should_not include(project_dir) + filter.inclusions.description.should_not include(' (lambda)') + filter.inclusions.description.should_not include('0x') + end end - it "excludes objects matching exclusion and inclusion" do - included = RSpec::Core::Metadata.new({:foo => :bar}) - excluded = RSpec::Core::Metadata.new({:foo => :bar, :baz => :bam}) - filter = Filter.new - filter.include :foo => :bar - filter.exclude :baz => :bam - filter.filter([included, excluded]).should eq([included]) + describe "#exclusions#description" do + it 'cleans up the description' do + project_dir = File.expand_path('.') + lambda { }.inspect.should include(project_dir) + lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9' + lambda { }.inspect.should include('0x') + + filter = Filter.new + filter.exclude :foo => lambda { } + + filter.exclusions.description.should_not include(project_dir) + filter.exclusions.description.should_not include(' (lambda)') + filter.exclusions.description.should_not include('0x') + end + + it 'returns `{}` when it only contains the default filters' do + filter = Filter.new + filter.exclusions.description.should eq({}.inspect) + end + + it 'includes other filters' do + filter = Filter.new + filter.exclude :foo => :bar + filter.exclusions.description.should eq({ :foo => :bar }.inspect) + end + + it 'includes an overriden :if filter' do + filter = Filter.new + filter.exclude :if => :custom_filter + filter.exclusions.description.should eq({ :if => :custom_filter }.inspect) + end + + it 'includes an overriden :unless filter' do + filter = Filter.new + filter.exclude :unless => :custom_filter + filter.exclusions.description.should eq({ :unless => :custom_filter }.inspect) + end end end end diff --git a/spec/rspec/core/world_spec.rb b/spec/rspec/core/world_spec.rb index 37be56d898..a11e5c6da2 100644 --- a/spec/rspec/core/world_spec.rb +++ b/spec/rspec/core/world_spec.rb @@ -17,138 +17,11 @@ module RSpec::Core end end - describe "#apply_inclusion_filters" do - let(:group1) { - RSpec::Core::ExampleGroup.describe(Bar, "find group-1", - { :foo => 1, :color => 'blue', :feature => 'reporting' } - ) {} - } - - let(:group2) { - RSpec::Core::ExampleGroup.describe(Bar, "find group-2", - { :pending => true, :feature => 'reporting' } - ) {} - } - - let(:group3) { - RSpec::Core::ExampleGroup.describe(Bar, "find group-3", - { :array => [1,2,3,4], :color => 'blue' } - ) {} - } - - let(:group4) { - RSpec::Core::ExampleGroup.describe(Foo, "find these examples") do - it('I have no options') {} - it("this is awesome", :awesome => true) {} - it("this is too", :awesome => true) {} - it("not so awesome", :awesome => false) {} - it("I also have no options") {} - end - } - - let(:example_groups) { [group1, group2, group3, group4] } - - it "finds no groups when given no search parameters" do - world.apply_inclusion_filters([],{}).should eq([]) - end - - it "finds matching groups when filtering on :describes (described class or module)" do - world.apply_inclusion_filters(example_groups, :example_group => { :describes => Bar }).should eq([group1, group2, group3]) - end - - it "finds matching groups when filtering on :description with text" do - world.apply_inclusion_filters(example_groups, :example_group => { :description => 'Bar find group-1' }).should eq([group1]) - end - - it "finds matching groups when filtering on :description with a lambda" do - world.apply_inclusion_filters(example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should eq([group1, group3]) - end - - it "finds matching groups when filtering on :description with a regular expression" do - world.apply_inclusion_filters(example_groups, :example_group => { :description => /find group/ }).should eq([group1, group2, group3]) - end - - it "finds one group when searching for :pending => true" do - world.apply_inclusion_filters(example_groups, :pending => true ).should eq([group2]) - end - - it "finds matching groups when filtering on arbitrary metadata with a number" do - world.apply_inclusion_filters(example_groups, :foo => 1 ).should eq([group1]) - end - - it "finds matching groups when filtering on arbitrary metadata with an array" do - world.apply_inclusion_filters(example_groups, :array => [1,2,3,4]).should eq([group3]) - end - - it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do - world.apply_inclusion_filters(example_groups, :array => [4,3,2,1]).should be_empty - end - - it "finds matching examples when filtering on arbitrary metadata" do - world.apply_inclusion_filters(group4.examples, :awesome => true).should eq([group4.examples[1], group4.examples[2]]) - end - - it "finds matching examples for example that match any of the filters" do - world.apply_inclusion_filters(group4.examples, :awesome => true, :something => :else).should eq([group4.examples[1], group4.examples[2]]) - end - end - - describe "#apply_exclusion_filters" do - - it "finds nothing if all describes match the exclusion filter" do - options = { :network_access => true } - - group1 = ExampleGroup.describe(Bar, "find group-1", options) do - it("foo") {} - it("bar") {} - end - - world.register(group1) - - world.apply_exclusion_filters(group1.examples, :network_access => true).should eq([]) - - group2 = ExampleGroup.describe(Bar, "find group-1") do - it("foo", :network_access => true) {} - it("bar") {} - end - - world.register(group2) - - world.apply_exclusion_filters(group2.examples, :network_access => true).should eq([group2.examples.last]) - end - - it "finds nothing if a regexp matches the exclusion filter" do - group = ExampleGroup.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do - it("foo") {} - it("bar") {} - end - world.register(group) - world.apply_exclusion_filters(group.examples, :name => /exclude/).should eq([]) - world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should eq([]) - world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => { - :describes => lambda { |b| b == Bar } } ).should eq([]) - - world.apply_exclusion_filters(group.examples, :name => /exclude not/).should eq(group.examples) - world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should eq([]) - world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should eq([]) - end - - it "finds all if filters are empty" do - group = ExampleGroup.describe(Bar) do - example("foo") {} - example("bar") {} - end - world.register(group) - world.apply_exclusion_filters(group.examples, {}).should eq(group.examples) - end - end - describe "#preceding_declaration_line (again)" do - let(:group) do RSpec::Core::ExampleGroup.describe("group") do - example("example") {} + example("example") {} end end @@ -219,7 +92,7 @@ module RSpec::Core context "with an inclusion filter" do it "announces" do - configuration.inclusion_filter = { :foo => 'bar' } + configuration.filter_run_including :foo => 'bar' reporter.should_receive(:message). with("No examples matched #{{ :foo => 'bar' }.inspect}.") world.announce_filters @@ -229,7 +102,7 @@ module RSpec::Core context "with an inclusion filter and run_all_when_everything_filtered" do it "announces" do configuration.stub(:run_all_when_everything_filtered?) { true } - configuration.inclusion_filter = { :foo => 'bar' } + configuration.filter_run_including :foo => 'bar' reporter.should_receive(:message). with("No examples matched #{{ :foo => 'bar' }.inspect}. Running all.") world.announce_filters @@ -238,7 +111,7 @@ module RSpec::Core context "with an exclusion filter" do it "announces" do - configuration.exclusion_filter = { :foo => 'bar' } + configuration.filter_run_excluding :foo => 'bar' reporter.should_receive(:message). with("No examples were matched. Perhaps #{{ :foo => 'bar' }.inspect} is excluding everything?") world.announce_filters @@ -257,59 +130,5 @@ module RSpec::Core end end end - - describe "#inclusion_filter" do - describe "#description" do - it 'cleans up the description' do - # check the assumptions of this example - project_dir = File.expand_path('.') - lambda { }.inspect.should include(project_dir) - lambda { }.inspect.should include('0x') - lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9' - - configuration.filter_run :foo => lambda { } - world.inclusion_filter.description.should_not include('0x') - world.inclusion_filter.description.should_not include(project_dir) - world.inclusion_filter.description.should_not include(' (lambda)') - end - end - end - - describe "#exclusion_filter" do - describe "#description" do - it 'returns `{}` when it only contains the default filters' do - world.exclusion_filter.description.should eq({}.inspect) - end - - it 'includes other filters' do - configuration.exclusion_filter[:foo] = :bar - world.exclusion_filter.description.should eq({ :foo => :bar }.inspect) - end - - it 'includes an overriden :if filter' do - configuration.exclusion_filter[:if] = :custom_filter - world.exclusion_filter.description.should eq({ :if => :custom_filter }.inspect) - end - - it 'includes an overriden :unless filter' do - configuration.exclusion_filter[:unless] = :custom_filter - world.exclusion_filter.description.should eq({ :unless => :custom_filter }.inspect) - end - - it 'cleans up the description' do - # check the assumptions of this example - project_dir = File.expand_path('.') - lambda { }.inspect.should include(project_dir) - lambda { }.inspect.should include('0x') - lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9' - - configuration.exclusion_filter[:foo] = lambda { } - configuration.filter_run_excluding :bar => lambda { } - world.exclusion_filter.description.should_not include('0x') - world.exclusion_filter.description.should_not include(project_dir) - world.exclusion_filter.description.should_not include(' (lambda)') - end - end - end end end