Skip to content

Commit

Permalink
Use metadata/filtering to filter out Ruby-version dependent examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Mar 4, 2010
1 parent 47f0b2a commit a7a8b4f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module Rspec
module Core
class Configuration
# Control what examples are run by filtering
attr_reader :filter
attr_accessor :filter

# Control what examples are not run by filtering
attr_reader :exclusion_filter
attr_accessor :exclusion_filter

# Run all examples if the run is filtered, and no examples were found.
attr_writer :run_all_when_everything_filtered
Expand Down
13 changes: 6 additions & 7 deletions spec/rspec/core/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,12 @@ def stub_example_group
@before_all_top_level.should == 'before_all_top_level'
end

it "should be able to access the before all ivars in the before_all_ivars hash" do
with_ruby('1.8') do
running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
end
with_ruby('1.9') do
running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
end
it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
end

it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
end

describe "but now I am nested" do
Expand Down
24 changes: 15 additions & 9 deletions spec/rspec/core/shared_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,28 @@ def cleanup_shared_example_groups
Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
end

it "should make any shared example_group available at the correct level" do
it "should make any shared example_group available at the correct level", :ruby => 1.8 do
group = ExampleGroup.create('fake group')
block = lambda {
def self.class_helper; end
def extra_helper; end
}
Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
group.it_should_behave_like :shared_example_group
with_ruby(1.8) do
group.instance_methods.should include('extra_helper')
group.singleton_methods.should include('class_helper')
end
with_ruby(1.9) do
group.instance_methods.should include(:extra_helper)
group.singleton_methods.should include(:class_helper)
end
group.instance_methods.should include('extra_helper')
group.singleton_methods.should include('class_helper')
end

it "should make any shared example_group available at the correct level", :ruby => 1.9 do
group = ExampleGroup.create('fake group')
block = lambda {
def self.class_helper; end
def extra_helper; end
}
Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
group.it_should_behave_like :shared_example_group
group.instance_methods.should include(:extra_helper)
group.singleton_methods.should include(:class_helper)
end

it "should raise when named shared example_group can not be found"
Expand Down
9 changes: 3 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)

def with_ruby(version)
yield if RUBY_VERSION.to_s =~ Regexp.compile("^#{version}")
end

module Rspec
module Core
module Matchers
Expand Down Expand Up @@ -40,7 +36,8 @@ def in_editor?

Rspec.configure do |c|
c.mock_framework = :rspec
c.filter_run :focused => true
c.run_all_when_everything_filtered = true
c.color_enabled = !in_editor?
c.exclusion_filter = { :ruby => lambda {|version|
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
}}
end

0 comments on commit a7a8b4f

Please sign in to comment.