Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding new feature - stubbing with arguments #80

Merged
merged 1 commit into from

2 participants

@adomokos

Documenting stubbing with arguments.

@adomokos

Hi David, is this something you'd pull in? Thanks!

@dchelimsky dchelimsky merged commit fb854a6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 2, 2011
  1. @adomokos
This page is out of date. Refresh to see the latest.
Showing with 70 additions and 0 deletions.
  1. +70 −0 features/method_stubs/stub_with_arguments.feature
View
70 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"
Something went wrong with that request. Please try again.