Question

I would normally set an instance variable in my controller, but I am unit testing a model method which depends on the value of the instance variable set in the controller.

Using rspec, is it possible to stub or set this instance variable for the test?

Everything I've seen so far makes it seem that I can only stub/set an instance variable from controller or view tests, not model tests.

Was it helpful?

Solution

I am unit testing a model method which depends on the value of the instance variable set in the controller.

That's a wrong way to go, MVC dictates that we make a strong boundary between those three components and integrate everything in controllers. If you really must go that way, can you at least show the code in which you're using a controller variable?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top