I was struggling with testing module's def self.method
. I found a great thread here with a very helpful answer. My code is:
module MyModule
def self.method
groups = Posts.group :name
end
end
describe Class.new { include MyModule } do
its (:method) { should be_a(ActiveRecord::Relation) }
end
The problem is, that the question is about including a module, and not extending it. As the author of the answer mentioned, he tested it with RSpec 2. I tested it with RSpec 3.0.0 and the only thing that worked was when the method was an instance's method. Otherwise I'm getting the following error:
undefined method `method' for #<#<Class:0x0000000..>:0x00000006..>
How can I test the MyModule.method
?