Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proves issues #137 #141

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions spec/rspec/mocks/any_instance_spec.rb
Expand Up @@ -64,6 +64,17 @@ def private_method; :private_method_return_value; end
lambda{ klass.new.bar }.should raise_error(NoMethodError)
end

context "multiple return values" do
context "Array#sample" do
it "should behave like any other invocation of #any_instance" do
Array.any_instance.stub(:sample).and_return(:one, :two, :three)
[].sample.should eq(:one)
[].sample.should eq(:two)
[].sample.should eq(:three)
end
end
end

context 'multiple methods' do
it "allows multiple methods to be stubbed in a single invocation" do
klass.any_instance.stub(:foo => 'foo', :bar => 'bar')
Expand Down Expand Up @@ -273,37 +284,37 @@ class RSpec::SampleRspecTestClass;end
end.should raise_error(RSpec::Mocks::MockExpectationError, 'The method `existing_method` was not stubbed or was already unstubbed')
end
end

context "with #should_not_receive" do
it "fails if the method is called" do
klass.any_instance.should_not_receive(:existing_method)
lambda { klass.new.existing_method }.should raise_error(RSpec::Mocks::MockExpectationError)
end

it "passes if no method is called" do
lambda { klass.any_instance.should_not_receive(:existing_method) }.should_not raise_error
end

it "passes if only a different method is called" do
klass.any_instance.should_not_receive(:existing_method)
lambda { klass.new.another_existing_method }.should_not raise_error
end

context "with constraints" do
it "fails if the method is called with the specified parameters" do
klass.any_instance.should_not_receive(:existing_method_with_arguments).with(:argument_one, :argument_two)
lambda do
klass.new.existing_method_with_arguments(:argument_one, :argument_two)
klass.new.existing_method_with_arguments(:argument_one, :argument_two)
end.should raise_error(RSpec::Mocks::MockExpectationError)
end

it "passes if the method is called with different parameters" do
klass.any_instance.should_not_receive(:existing_method_with_arguments).with(:argument_one, :argument_two)
lambda { klass.new.existing_method_with_arguments(:argument_three, :argument_four) }.should_not raise_error
end
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' }
let(:existing_method_expectation_error_message) { 'Exactly one instance should have received the following message(s) but didn\'t: existing_method' }
Expand Down