Rspec - how can I check if a method exists?

My model has

def self.empty_building
  // stuff
end

How can I use rspec for this existing one ?, have tried:

describe "empty_building" do
  subject { Building.new }
  it { should respond_to :empty_building }
end

but getting :

Failure/Error: it { should respond_to :empty_building }  
expected #<Building id: nil, district_id: nil, name: nil, 
direct: nil, created_at: nil, updated_at: nil> to respond to :empty_building
+5
source share
1 answer

You have a class method

self.empty_building

in your model .. but your object is an instance of Building.

So it should be

def empty_building 

or it should be:

describe "empty_building" do
  it { Building.should respond_to :empty_building }
end
+9
source

All Articles