2012-12-28 19 views
5

我試圖從一個模塊訪問的方法在我的規格的一個助手,NoMethodError試圖訪問包含模塊中定義

我在測試中包括輔助模塊方法時

module Support 
    class RestHelper 
    include Rest::Rest 

    def create_rest_client_for_ifa 
     # Call method from module 
     create_rest_client(uname, pword) 
    end 
    end 
end 

但我不斷收到一個NoMethodError當我運行我的規格:

Failure/Error: @rest_client = Support::RestHelper.create_rest_client_for_ifa 
NoMethodError: 
    undefined method `create_rest_client' for Support::RestHelper:Class 

這裏是我的模塊代碼:

module Rest 
    module Rest 
    . 
    . 
    def create_rest_client(uname, pword) 
     # code 
    end 
    . 
    . 
    end 
end 

看來,當我在鐵軌控制檯

$ RAILS_ENV=test rails c 
irb> include Rest::Rest 
=> Object 
irb> create_rest_client(uname, pword) 

我缺少的是測試它工作得很好?爲什麼我無法從測試助手訪問該方法?

任何幫助將不勝感激。

回答

7

我記得,include增加了模塊方法作爲實例方法,extend增加了它們作爲類方法。

+0

謝謝,解決了我的問題 – Martinffx