Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use custom include_method matcher to deal with difference in ruby 1.8…

… vs 1.9.
  • Loading branch information...
commit 347ee039eac6ea8b9c64d41bc7eae28b257a5207 1 parent c546573
@myronmarston myronmarston authored
Showing with 7 additions and 30 deletions.
  1. +3 −18 spec/rspec/mocks/partial_mock_spec.rb
  2. +4 −12 spec/spec_helper.rb
View
21 spec/rspec/mocks/partial_mock_spec.rb
@@ -134,34 +134,19 @@ def private_method; end
it 'keeps public methods public' do
@object.should_receive(:public_method)
- with_ruby('1.9') do
- @object.public_methods.should include(:public_method)
- end
- with_ruby('1.8') do
- @object.public_methods.should include('public_method')
- end
+ @object.public_methods.should include_method(:public_method)
@object.public_method
end
it 'keeps private methods private' do
@object.should_receive(:private_method)
- with_ruby('1.9') do
- @object.private_methods.should include(:private_method)
- end
- with_ruby('1.8') do
- @object.private_methods.should include('private_method')
- end
+ @object.private_methods.should include_method(:private_method)
@object.public_method
end
it 'keeps protected methods protected' do
@object.should_receive(:protected_method)
- with_ruby('1.9') do
- @object.protected_methods.should include(:protected_method)
- end
- with_ruby('1.8') do
- @object.protected_methods.should include('protected_method')
- end
+ @object.protected_methods.should include_method(:protected_method)
@object.public_method
end
View
16 spec/spec_helper.rb
@@ -5,12 +5,7 @@
module Macros
def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
it "has method_missing as private" do
- with_ruby 1.8 do
- self.class.describes.private_instance_methods.should include("method_missing")
- end
- with_ruby 1.9 do
- self.class.describes.private_instance_methods.should include(:method_missing)
- end
+ self.class.describes.private_instance_methods.should include_method(:method_missing)
end
it "does not respond_to? method_missing (because it's private)" do
@@ -32,11 +27,9 @@ def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
end
end
-module RSpec
- module Matchers
- def with_ruby(version)
- yield if RUBY_VERSION =~ Regexp.compile("^#{version.to_s}")
- end
+RSpec::Matchers.define :include_method do |expected|
+ match do |actual|
+ actual.map { |m| m.to_s }.include?(expected.to_s)
end
end
@@ -44,6 +37,5 @@ def with_ruby(version)
config.mock_with :rspec
config.color_enabled = true
config.extend(Macros)
- config.include(RSpec::Matchers)
config.include(RSpec::Mocks::Methods)
end
Please sign in to comment.
Something went wrong with that request. Please try again.