spec/rspec/mocks/any_instance_spec.rb in rspec-mocks-2.14.0.rc1 vs spec/rspec/mocks/any_instance_spec.rb in rspec-mocks-2.14.0
- old
+ new
@@ -179,10 +179,30 @@
klass.any_instance.stub(:foo).and_yield(yielded_value)
klass.new.foo{|value| expect(value).to be(yielded_value)}
end
end
+ context 'with #and_call_original and competing #with' do
+ let(:klass) { Struct.new(:a_method) }
+
+ it 'can combine and_call_original, with, and_return' do
+ allow_any_instance_of(klass).to receive(:a_method).and_call_original
+ allow_any_instance_of(klass).to receive(:a_method).with(:arg).and_return('value')
+
+ expect(klass.new('org').a_method).to eq 'org'
+ expect(klass.new.a_method(:arg)).to eq 'value'
+ end
+
+ it 'can combine and_call_original, with, and_return (old syntax)' do
+ klass.any_instance.stub(:a_method).and_call_original
+ klass.any_instance.stub(:a_method).with(:arg).and_return('value')
+
+ expect(klass.new('org').a_method).to eq 'org'
+ expect(klass.new.a_method(:arg)).to eq 'value'
+ end
+ end
+
context "with #and_raise" do
it "stubs a method that doesn't exist" do
klass.any_instance.stub(:foo).and_raise(CustomErrorForAnyInstanceSpec)
expect { klass.new.foo}.to raise_error(CustomErrorForAnyInstanceSpec)
end
@@ -324,9 +344,15 @@
klass.any_instance.should_receive(:foo)
klass.any_instance.should_not_receive(:bar)
klass.new.foo
RSpec::Mocks.space.verify_all
end
+ end
+
+ it "prevents confusing double-negative expressions involving `never`" do
+ expect {
+ klass.any_instance.should_not_receive(:not_expected).never
+ }.to raise_error(/trying to negate it again/)
end
end
context "with #should_receive" do
let(:foo_expectation_error_message) { 'Exactly one instance should have received the following message(s) but didn\'t: foo' }