Blankman
Blankman

Reputation: 267280

Method works in rails console, but rspec says method is undefined

In my rails 3 app, I have a lib folder:

/lib
/lib/abc/some_class.rb
/lib/abc/some_class/other.rb

some_class.rb:

module ABC
  class SomeClass
  end
end

other.rb

module ABC
  class SomeClass::Other
    def self.hello(a,b,c,)
      false
    end
  end
end

If I fire up rails console I can do:

ABC::SomeClass::Other.hello(1,2,3)

and it outputs false

In my rspec test, I have the same line:

result = ABC::SomeClass::Other.hello(1,2,3)

And I get:

undefined method 'hello' for #<Class:0x.......>

Is this a namespace issue? folder issue?

Upvotes: 2

Views: 536

Answers (1)

Jim Deville
Jim Deville

Reputation: 10672

What are the require's in the rspec file? It needs to be including some_class.rb and some_class\other.rb (you may need to modify the load path to include both)

Upvotes: 1

Related Questions