Unit testing 是否可以更改对象上的Rspec输出?

Unit testing 是否可以更改对象上的Rspec输出?,unit-testing,rspec,rspec-rails,Unit Testing,Rspec,Rspec Rails,鉴于以下规范: describe Person describe "scopes and class methods" do let!(:sixty_older) { FactoryGirl.create :person, birthdate: 60.years.ago } describe ".senior" do subject { Person.senior } it { should include(sixty_older) }

鉴于以下规范:

describe Person
  describe "scopes and class methods" do
    let!(:sixty_older)     { FactoryGirl.create :person, birthdate: 60.years.ago }

    describe ".senior" do
      subject { Person.senior }
      it { should include(sixty_older) }
    end
  end
end
其在CLI中的输出使用格式--文档:

Person
  scopes and class methods
    .senior
      should include #<Person person_id: 466, gender: "M", birthdate: "1953-02-07 19:44:22", birthdate_estimated: 0, dead: 0, death_date: nil, cause_of_death: nil, creator: 0, date_created: "0002-11-30 00:00:00", changed_by: nil, date_changed: nil, voided: 0, voided_by: nil, date_voided: nil, void_reason: nil, uuid: "key_4">
人
作用域和类方法
级别高的
应包括#
我是否可以将
#
更改为其他内容

比如说,只显示个人id、生日和uuid


此外,如果可以在每个测试的基础上进行自定义,而不是在类级别上进行更改。

您可以向大多数rspec匹配器传递自定义失败消息,如下所示:

describe ".senior" do
  subject { Person.senior }
  it { should include(sixty_older), "should include #{person.person_id}:#{person.uuid}" }
end

您可以向大多数rspec匹配器传递自定义失败消息,如下所示:

describe ".senior" do
  subject { Person.senior }
  it { should include(sixty_older), "should include #{person.person_id}:#{person.uuid}" }
end

在每个示例或上下文或任何您喜欢的内容之前,尝试重写模型类的inspect实例方法。我同样需要用Rspec测试ActiveRecord模型,它也能工作

在每个示例或上下文或任何您喜欢的内容之前,尝试重写模型类的inspect实例方法。我同样需要用Rspec测试ActiveRecord模型,它也能工作