RoR и RSpec: Как к переменным экземпляра контроллера доступа, не определяя средства доступа?

Очевидный способ, чтобы сделать это должен был бы переопределить все операторы (+ и * в особенности) и проверка на переполнение прежде perorming операции.

20
задан molf 18 July 2009 в 13:29
поделиться

1 ответ

controller.instance_variable_get(:var)

if you find yourself doing this, you might want to rethink your approach to information hiding so that you are testing essential behavior rather than incidental implementation details. Your tests should ensure that the "thing" functions as it should without being too tightly bound to the particular implementation.

EDIT: Isn't assigns(:var) the rails testing magic for doing the same thing with controllers?

44
ответ дан 29 November 2019 в 23:37
поделиться
Другие вопросы по тегам:

Похожие вопросы: