Ruby on rails 帮助为my helper方法测试清除对象
我的应用程序\u控制器有一个方法Ruby on rails 帮助为my helper方法测试清除对象,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我的应用程序\u控制器有一个方法 def current_user end 这将返回一个用户对象 现在使用rspec,我正在应用程序_helper.rb中测试一个助手 def test_this_method(some_object) .. .. = some_other_method( current_user ) end def some_other_method .. user.age user.height end 因此,我想在应用程序\u助手
def current_user
end
这将返回一个用户对象
现在使用rspec,我正在应用程序_helper.rb中测试一个助手
def test_this_method(some_object)
..
.. = some_other_method( current_user )
end
def some_other_method
..
user.age
user.height
end
因此,我想在应用程序\u助手
中测试这个方法
但由于它调用了其他方法,因此必须对其进行存根/模拟。而且当前的用户对象也必须被模拟,因为它也被引用**
我该怎么做呢?这应该是直截了当的
require File.dirname(__FILE__) + '/../spec_helper'
describe ApplicationHelper do
describe "test_this_method" do
describe "when test_this_method do foo bar" do
it "should show nothing" do
helper.stub(:some_other_method)
helper.test_this_method.should == ""
end
end
end
end
这对你有帮助吗
相关答案可以是 这应该是直截了当的
require File.dirname(__FILE__) + '/../spec_helper'
describe ApplicationHelper do
describe "test_this_method" do
describe "when test_this_method do foo bar" do
it "should show nothing" do
helper.stub(:some_other_method)
helper.test_this_method.should == ""
end
end
end
end
这对你有帮助吗
相关答案可以是