eayurt
eayurt

Reputation: 1177

RSpec method testing

I am trying to test some methods in my models. For example,

in my model

def name
    self.first_name + " " + self.last_name
  end

I want to test it but I cannot do. How can I test this method in my model_spec.rb file?

Upvotes: 0

Views: 92

Answers (1)

dogenpunk
dogenpunk

Reputation: 4382

Something like this, perhaps?

describe YourModel do
  subject { YourModel.new(first_name: "Some", last_name: "Guy) }

  its(:first_name) { should eql "Some" }
  its(:last_name) { should eql "Guy" }
  its(:name) { should eql "Some Guy" }
end

You could also use =~ and a regular expression, but I find that a little noisy.

Upvotes: 1

Related Questions