is it possible to stub an instance variable in rspec in a non controller test?

StackOverflow https://stackoverflow.com/questions/9334673

  •  27-10-2019
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top