Browse files

stub_chain with a string of methods separated by "."

e.g. stub_chain('method1.method2.method3')

Issue #8
  • Loading branch information...
1 parent 1c8d44b commit 9c67f9c343ab4ddf6dd87dfc486a7e34c721df0f @justinko committed Jul 31, 2010
Showing with 7 additions and 2 deletions.
  1. +2 −2 lib/rspec/mocks/methods.rb
  2. +5 −0 spec/rspec/mocks/stub_chain_spec.rb
View
4 lib/rspec/mocks/methods.rb
@@ -23,9 +23,9 @@ def unstub(sym)
alias_method :stub!, :stub
alias_method :unstub!, :unstub
-
+
def stub_chain(*methods)
- if methods.length > 1
+ if methods = methods.join('.').split('.') and methods.length > 1
next_in_chain = Object.new
stub!(methods.shift) {next_in_chain}
next_in_chain.stub_chain(*methods)
View
5 spec/rspec/mocks/stub_chain_spec.rb
@@ -29,6 +29,11 @@ module Mocks
@subject.msg1.msg2.msg3.msg4.should equal(:first)
@subject.msg5.msg2.msg3.msg4.should equal(:second)
end
+
+ it "returns expected value from chaining methods in a string separated by \".\"" do
+ @subject.stub_chain('msg1.msg2.msg3.msg4').and_return(:return_value)
+ @subject.msg1.msg2.msg3.msg4.should equal(:return_value)
+ end
end
end
end

1 comment on commit 9c67f9c

@txus

clean! :)

Please sign in to comment.