0

I am trying the RR double framework for the first time and am a bit stuck on how to convert my existing RSpec stubs. I see how I can use double graphs in the documentation for the same result as RSpec's stub_chain, but how do create a stub/mock that just responds to defined methods?

For instance, in RSpec, I could do admin = stub(admin?: true) and then use admin. Can I do this in RR, without having to first have admin defined? admin = User.new; stub(admin).admin? { true }

I was able to do something like admin = stub; stub(admin).admin? { true }, but that double stub seems odd.

Eric M.
  • 5,399
  • 6
  • 41
  • 67

1 Answers1

1
admin = stub(User.new).admin? { true }

seems enough to have want you want.

shingara
  • 46,608
  • 11
  • 99
  • 105
  • It does. However, I am writing tests that do not include all of my Rails models, so anything like User would have to be redefined as empty classes in order for me to do this. Is there no way to drop the User.new piece? I don't care what the stub is an instance of, so long as it responds to admin? with true. – Eric M. Mar 02 '12 at 12:50
  • Do it on Object so : `admin = stub(Object.new).admin? { true }` – shingara Mar 02 '12 at 15:03