Closed allenwyma closed 10 years ago
It seems you have expectation on branch
instead of company
, right?
Both, kind of. I have a branch that belongs_to a company. The company has some values set on it that the branch will refer to. So I faked a a branch AND company. I tried to stub the branch fake so it would return the company fake, but it blows up, then.
It seems that Company#max_users
is not a method (probably works on method_missing
). Unfortunately there is no way for us to fake methods like that without instantiating Company behind the scenes, which in general is unacceptable.
Also, even assuming that the stubbing of company.max_users would work, there is no way that the assertion would pass. Fakes have all the same methods as real objects, but those methods do nothing, so even if real branch delegates #max_users to company, the fake one does not.
Since the test you are writing appears to be an integration test (because it integrates with ActiveRecord), it would probably be best if you used real classes here, and only stubbed the methods that contain logic. I wrote about it in another issue if you want to learn why.
Well, it's an attribute inside of AR, so I'm guessing that because it's an AR method, then it's not "stubbable" with a fake? If so, that's fine. I eventually got it going by, doing like what you said, stubbing the class itself.
is this the fix? Just confirm. Can we make a note in the readme?
Right, I forgot that's an AR attribute. Have you tried turning on the fake_ar_attributes configuration option?
Okay, will try some more with this, but it should be fine.
I have this code:
I get this error:
The puts statement returns a true value, BTW, so I know that this is not a problem.
Using Zeus, Rails 4, Rspec-rail 2.14.0, latest bogus from rubygems.org.