Skip to content

be_a() and --verbose #49

@emiltin

Description

@emiltin

When using is_a() or be == to verify that an object is a specific class, for example:

expect(collector.messages).to be_a(Array)
expect(collector.messages).to be == Array

Then the --verbose output shows the entire object:

expect [#<RSMP::Alarm:1304, @timestamp: 2026-05-04 11:12:43.832505 +0200, @attributes: {"mType" => "rSMsg", "type" => "Alarm", "ntsOId" => "", "xNId" => "", "xACId" => "", "xNACId" => "", "cId" => "DL1", "aCId" => "A0302", "aSp" => "Issue", "ack" => "Acknowledged", "aS" => "Active", "sS" => "notSuspended", "aTs" => 2026-05-04 11:11:43.832492 +0200, "cat" => "D", "pri" => "1", "rvs" => [{"n" => "color", "v" => "green"}], "mId" => "62638e29-4e82-4294-baf9-0548baeba8af"}>, #<RSMP::Alarm:1312, @timestamp: 2026-05-04 11:12:43.832597 +0200, @attributes: {"mType" => "rSMsg", "type" => "Alarm", "ntsOId" => "", "xNId" => "", "xACId" => "", "xNACId" => "", "cId" => "TC", "aCId" => "A0303", "aSp" => "Suspend", "ack" => "notAcknowledged", "aS" => "inActive", "sS" => "Suspended", "aTs" => 2026-05-04 11:11:43.832593 +0200, "cat" => "T", "pri" => "2", "rvs" => [{"n" => "color", "v" => "red"}], "mId" => "73c7f777-67e1-493c-a715-604aa625f9ec"}>] to
be == [#<RSMP::Alarm:1304, @timestamp: 2026-05-04 11:12:43.832505 +0200, @attributes: {"mType" => "rSMsg", "type" => "Alarm", "ntsOId" => "", "xNId" => "", "xACId" => "", "xNACId" => "", "cId" => "DL1", "aCId" => "A0302", "aSp" => "Issue", "ack" => "Acknowledged", "aS" => "Active", "sS" => "notSuspended", "aTs" => 2026-05-04 11:11:43.832492 +0200, "cat" => "D", "pri" => "1", "rvs" => [{"n" => "color", "v" => "green"}], "mId" => "62638e29-4e82-4294-baf9-0548baeba8af"}>, #<RSMP::Alarm:1312, @timestamp: 2026-05-04 11:12:43.832597 +0200, @attributes: {"mType" => "rSMsg", "type" => "Alarm", "ntsOId" => "", "xNId" => "", "xACId" => "", "xNACId" => "", "cId" => "TC", "aCId" => "A0303", "aSp" => "Suspend", "ack" => "notAcknowledged", "aS" => "inActive", "sS" => "Suspended", "aTs" => 2026-05-04 11:11:43.832593 +0200, "cat" => "T", "pri" => "2", "rvs" => [{"n" => "color", "v" => "red"}], "mId" => "73c7f777-67e1-493c-a715-604aa625f9ec"}>]
✓ assertion passed test/rsmp/alarm_collector_spec.rb:43

I find this a bit noisy (especially for arrays), as the expectation is really only about the class. I think something this like would be enough:

expect Array to
be is_a? Array
✓ assertion passed test/rsmp/alarm_collector_spec.rb:85

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions