Skip to content

RFC: proposal to add assertions for list of map-likes #39

@idlehands

Description

@idlehands

I have been playing around with the idea of extending CheckerCab to use the same assertion system for lists of map-likes (map, struct, ecto schema). Overall, I don't think it's too hard, but coming up with a clear API is the challenge. I have thrown out a couple passes on what it could look like, but am open to new ideas as well as different terms.

option 1 - new function

The main question is whether or not it should be a new function or an extension of the behavior of the existing function. I'm leaning towards a new one, though naming, as usual, is hard.

      assert_values_for_in_list(
        expected_list: {[thing_1, thing_1], :string_keys},
        actual_list: return_value, # is list in all the examples
        ordered: true,
        fields: fields_for(Thing)
      )

      assert_values_for_in_list(
        expected_list: [thing_2, thing_1],
        actual_list: return_value,
        ordered: false,
        identifier_key: :id, # this would have to be required when ordered is false
        fields: fields_for(Thing)
      )

option 2 - add an optional key to existing function

Alternatively, we could add a new key to the existing function. I'm concerned that this might leave it hard to distinguish the behavior.

     assert_values_for(
       type: :ordered_list, # default would be something like :single_map, leaving this backwards compatible
       expected: [thing_1, thing_2],
       actual: return_value,
       fields: fields_for(Thing)
     )

     assert_values_for(
       type: :unordered_list,
       unique_identifier: :id,
       expected: [thing_2, thing_1],
       actual: return_value,
       fields: fields_for(Thing)
     )

I would love feedback and any other suggestions.

Metadata

Metadata

Assignees

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