Closed allenwyma closed 10 years ago
If you want to stub on a constant, just stub it: stub(Company).new { company }
Your snipped doesn't work because fake(:company_class, new:company, as: :class)
creates a fake of class, but it doesn't replace the constant.
If your fake name matches class name, you don't have to pass the class in a block. fake(:company)
does the same as fake(:company, as: :instance) { Company }
Hmm, I did try that, before, but was having an issue with something. When I stub the new method of Company and then try to stub the returning company's save method, then I get an error of SystemStackError: stack level too deep
We'll take a look, sounds like a bug in bogus. Thanks for reporting.
I have similar problem. E.g:
object_class = fake(Object, as: :class)
object_instance = fake(Object)
stub(object_class).new { object_instance }
object_class.new == object_instance # FALSE
I'm trying to stub the
new
method on a class, but cannot figure out how to do that. All in all, I want to return an object that is stubbed, so I can check to see in my controller (Rails project) what the responses will be if it can or cannot be saved.Here's what I have tried, but are no use: