Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 帮助为my helper方法测试清除对象_Ruby On Rails_Ruby_Rspec - Fatal编程技术网

Ruby on rails 帮助为my helper方法测试清除对象

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助手

我的应用程序\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
这对你有帮助吗

相关答案可以是