1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
require 'spec_helper'
module RSpec
module Mocks
describe "only stashing the original method" do
let(:klass) do
Class.new do
def self.foo(arg)
:original_value
end
end
end
it "keeps the original method intact after multiple expectations are added on the same method" do
klass.should_receive(:foo).with(:fizbaz).and_return(:wowwow)
klass.should_receive(:foo).with(:bazbar).and_return(:okay)
klass.foo(:fizbaz)
klass.foo(:bazbar)
verify klass
reset klass
expect(klass.foo(:yeah)).to equal(:original_value)
end
end
describe "when a class method is aliased on a subclass and the method is mocked" do
it "restores the original aliased public method" do
klass = Class.new do
class << self
alias alternate_new new
end
end
klass.should_receive(:alternate_new)
expect(klass.alternate_new).to be_nil
verify klass
reset klass
expect(klass.alternate_new).to be_an_instance_of(klass)
end
end
end
end
|