0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.