NoMethodError when trying to access method defined in included module

匿名 (未验证) 提交于 2019-12-03 00:51:01

问题:

I'm trying to access a method from a module in one of my spec helpers

I include the module in the test helper

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 

But I keep getting a NoMethodError when I run my spec:

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

Here is my module code:

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

It seems to work fine when I test it in the rails console

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

What am I missing? Why can't I access the method from the test helper?

Any help will be much appreciated.

回答1:

As I remember, include adds module methods as instance methods, extend adds them as class methods.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!