Skip to content

Cop idea: HaveAttributes #1057

@Darhazer

Description

@Darhazer

If a test checks few attributes in a row, it probably deserve to use have_attributes
bad:

expect(obj.foo).to eq(bar)
expect(obj.fu).to eq(bax)
expect(obj.name).to eq(baz)

good:

expect(obj).to have_attributes(
foo: bar,
fu: bax
name: baz

Things to consider:
the used matches. Initially, only eq could be used, as it could turn out to be quite complex to detect what can be converted to have_attributes and what not. We need a list of matching matchers.
An initial list:

be < 2 => a_value < 2
be > 2 => a_value > 2
be_an_instance_of => an_instance_of
be_within => a_value_within
contain_exactly => a_collection_containing_exactly
end_with => a_string_ending_with, ending_with
match => a_string_matching
start_with => a_string_starting_with

Check only direct method calls, no method chains
The method calls should be without arguments

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions