Permalink
Browse files

stub_chain accepts a dot-separated string as an argument

- Closes #8.
  • Loading branch information...
1 parent 1c8d44b commit bf883154954248c427490de10c9999ed79caad4d @txus txus committed with dchelimsky Jul 29, 2010
Showing with 8 additions and 1 deletion.
  1. +2 −1 lib/rspec/mocks/methods.rb
  2. +6 −0 spec/rspec/mocks/stub_chain_spec.rb
@@ -25,7 +25,8 @@ def unstub(sym)
alias_method :unstub!, :unstub
def stub_chain(*methods)
- if methods.length > 1
+ if methods.length > 1 or (methods.length == 1 and methods.first.is_a?(String) and (string_chain = methods.first))
+ methods = string_chain.split('.').map{|x|x.to_sym} if string_chain
next_in_chain = Object.new
stub!(methods.shift) {next_in_chain}
next_in_chain.stub_chain(*methods)
@@ -29,6 +29,12 @@ module Mocks
@subject.msg1.msg2.msg3.msg4.should equal(:first)
@subject.msg5.msg2.msg3.msg4.should equal(:second)
end
+
+ it "returns expected value when chain is a dot separated string, like stub_chain('msg1.msg2.msg3')" do
+ @subject.stub_chain("msg1.msg2.msg3").and_return(:return_value)
+ @subject.msg1.msg2.msg3.should equal(:return_value)
+ end
+
end
end
end

0 comments on commit bf88315

Please sign in to comment.