> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/assert-two-arrays-have-the-same-items-with-rspec.md).

# Assert Two Arrays Have The Same Items With RSpec

Methods that return arrays of values with inconsistent orderings can be annoying to test with the `#eq` matcher. To keep your test from fickering, you'd have to ensure the comparison is the same every time.

```ruby
it "has the correct values" do
  expect(fetch_colors(params).sort).to eq(["blue", "green", "yellow"])
end
```

It'd be better if we could keep our test focused and simple. If sort order isn't something we care about, then it shouldn't be part of our test. RSpec has a matcher for this kind of scenario -- [`#match_array`](https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers:match_array).

```ruby
it "has the correct values" do
  expect(fetch_colors(params)).to match_array(["blue", "green", "yellow"])
end
```

This allows us to ensure that each side of the comparison has the same set values, irrespective of ordering.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/assert-two-arrays-have-the-same-items-with-rspec.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
