我在 RSpec 中有一个与长文本字符串进行比较的测试。当测试失败时,我会收到这样的消息:
'jobs partial should render the correct format for jobs' FAILED
expected: "Job {\n\tName = \"name1-etc\"\n\tType = Backup\n\tMessages = Daemon\n\tPool = Default
\n\tSchedule = \"schedule1\"\n\tStorage = storage1\n\tClient = \"name1\"\n\tFileset = \"fileset1
\"\n\tMax Wait Time = 5m\n\tWrite Bootstrap = \"/var/lib/bacula/name1-etc.bsr\"\n}\n\n",
got: "Job {\n\tName = \"name1-etc\"\n\tType = Backup\n\tMessages = Daemon\n\tPool = Default
\n\tSchedule = \"schedule1\"\n\tStorage = storage1\n\tClient = \"name1\"\n\tFileset = \"fileset1
\"\n\tMax Wait Time = 5m\n\tWrite Bootstrap = \"/var/lib/bacula/name1-etc.bsr\"\n}\n\n" (using =
=)
如何使 RSpec 和自动测试响应格式良好的差异(如果可能,为文本之间的差异着色?像这样的东西
expected:
Job {
Name = "name1-etc"
Type = Backup
Messages = Daemon
Pool = Default
Schedule = "schedule1"
Storage = storage1
Client = "name1"
Fileset = "fileset1" <--diff
Max Wait Time = 5m
Write Bootstrap = "/var/lib/bacula/name1-etc.bsr"
}
got:
Job {
Name = "name1-etc"
Type = Backup
Messages = Daemon
Pool = Default
Schedule = "schedule1"
Storage = storage1
Client = "name1"
Fileset = "fileset2" <-- diff
Max Wait Time = 5m
Write Bootstrap = "/var/lib/bacula/name1-etc.bsr"
}