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

Adding new feature - stubbing with arguments #80

Merged
merged 1 commit into from Oct 9, 2011
Merged
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
70 changes: 70 additions & 0 deletions features/method_stubs/stub_with_arguments.feature
@@ -0,0 +1,70 @@
Feature: stub with arguments

You can set up more specific stubs by explicitly declaring the arguments the
method stub can be invoked with.

Scenario: the stub argument is not defined
Given a file named "stub_with_arguments_spec.rb" with:
"""
class Account
def open(logger)
logger.log :open
end
end

describe Account do
subject { Account.new }

it "can open an account" do
logger = double('logger')
logger.stub(:log)
subject.open logger
end
end
"""
When I run `rspec stub_with_arguments_spec.rb`
Then the examples should all pass

Scenario: the stub argument is defined
Given a file named "stub_with_arguments_spec.rb" with:
"""
class Account
def open(logger)
logger.log :open
end
end

describe Account do
subject { Account.new }

it "can open an account" do
logger = double('logger')
logger.stub(:log).with(:open)
subject.open logger
end
end
"""
When I run `rspec stub_with_arguments_spec.rb`
Then the examples should all pass

Scenario: the stub argument is defined but it's other than the actual value
Given a file named "stub_with_arguments_spec.rb" with:
"""
class Account
def open(logger)
logger.log :open
end
end

describe Account do
subject { Account.new }

it "can open an account" do
logger = double('logger')
logger.stub(:log).with(:something_different)
subject.open logger
end
end
"""
When I run `rspec stub_with_arguments_spec.rb`
Then the output should contain "1 example, 1 failure"