5

My model has

def self.empty_building // stuff end 

How can I rspec for this existing?, 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 
1
  • 2
    Not to be a dick, but imo, these kinds of tests aren't worth writing. Every time you call the method in, you will implicitly assert this. The only real reason I can think of to do this kind of thing is to ensure interface integrity, and there are generally better tools for that. Commented Jul 8, 2012 at 6:06

1 Answer 1

9

You have a class method

self.empty_building 

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

So either, it should be

def empty_building 

or it should be:

describe "empty_building" do it { Building.should respond_to :empty_building } end 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that's what I thought, yet this answer still gives an error - ` Failure/Error: it { Building.should respond_to :empty_building } {│ expected building(id: integer, district_id: integer, name: string, direct: boolean, created_at: datetime, updated A│_at: datetime) to respond to :empty_building `
btw I want it to be a class level method.
This gave me a false positive. empty_building could be anything in { Building.should respond_to :empty_building } and it would pass.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.