Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use anonymous classes rather than leaking constants.

  • Loading branch information...
commit 664bc24d53727c2364ed26d52a67104e624bb727 1 parent 454fd67
Myron Marston myronmarston authored
Showing with 22 additions and 18 deletions.
  1. +22 −18 spec/rspec/mocks/partial_mock_spec.rb
40 spec/rspec/mocks/partial_mock_spec.rb
View
@@ -113,36 +113,40 @@ def self.to_s
stub("existing mock", :foo => :foo)
end
- class PartiallyMockedEquals
- attr_reader :val
- def initialize(val)
- @val = val
- end
+ let(:klass) do
+ Class.new do
+ attr_reader :val
+ def initialize(val)
+ @val = val
+ end
- def ==(other)
- @val == other.val
+ def ==(other)
+ @val == other.val
+ end
end
end
it "does not raise an error when stubbing the object" do
- o = PartiallyMockedEquals.new :foo
- lambda { o.stub(:bar) }.should_not raise_error(NoMethodError)
+ o = klass.new :foo
+ expect { o.stub(:bar) }.not_to raise_error(NoMethodError)
end
end
describe "Method visibility when using partial mocks" do
- class MockableClass
- def public_method
- private_method
- protected_method
+ let(:klass) do
+ Class.new do
+ def public_method
+ private_method
+ protected_method
+ end
+ protected
+ def protected_method; end
+ private
+ def private_method; end
end
- protected
- def protected_method; end
- private
- def private_method; end
end
- let(:object) { MockableClass.new }
+ let(:object) { klass.new }
it 'keeps public methods public' do
object.should_receive(:public_method)
Please sign in to comment.
Something went wrong with that request. Please try again.