NoMethodError when trying to access method defined in included module
Asked Answered
B

1

5

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.

Baroness answered 28/12, 2012 at 8:38 Comment(0)
M
7

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

Motherofpearl answered 28/12, 2012 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.