2011-06-01 10 views
1

私application_controllerこれはUserオブジェクトを返します方法ヘルプ

def current_user 
end 

を持っています。今RSpecのを使用して

、私はだから私はapplication_helpertest_this_methodをテストしたいapplication_helper.rb

def test_this_method(some_object) 

    .. 
    .. = some_other_method(current_user) 

end 


def some_other_method 
    .. 
    user.age 
    user.height 
end 

でヘルパーをテストしています。

B ** utはsome_other_methodを呼び出すので、これはスタブ/モックされなければなりません。また、current_userオブジェクトも参照されているので、mockされなければなりません。**

どうすればいいですか?

答えて

4

これは簡単です。

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 

これは役に立ちますか?

関連することができます。 Stub a controller helper method in a template helper spec