Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError when trying to access method defined in included module

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.

like image 333
Martinffx Avatar asked Dec 28 '12 08:12

Martinffx


1 Answers

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

like image 98
Alex Teut Avatar answered Nov 15 '22 05:11

Alex Teut