0
我正在寫一些現有的Ruby代碼測試它看起來像注入變量爲Ruby的功能
module Foo
module Bar
private
def function_i_want_to_test (a, b)
if controller.is_something? a, b
puts a
else
puts b
end
end
end
end
的varaible controller
奇蹟般地插入函數從別的地方。要從我的測試中訪問這個函數,我可以在我的測試類中執行include Foo::Bar
,然後正常調用該函數。不幸的是,這不起作用,因爲controller
沒有設置。任何想法如何從我的測試中設置controller
變量?
我不明白你的問題。您發佈的代碼中沒有'controller'變量。只有一個'controller'方法調用。那麼,你的問題是什麼?如何定義一個名爲'controller'的方法?這很簡單:'def controller; end'。 –