Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在我的模型中测试一些方法。例如,
在我的模型中
def name self.first_name + " " + self.last_name end
我想测试它,但我做不到。如何在我的 model_spec.rb 文件中测试此方法?
大概是这样的吧?
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
你也可以使用=~和一个正则表达式,但我觉得这有点吵。
=~