I can't use the match_array to match agains an empty array in one of my tests. I have the following message:
Failure/Error: expect(subject.custom_text_locations).to be match_array([])
expected #<RSpec::Matchers::BuiltIn::MatchArray:105810100> => #<RSpec::Matchers::BuiltIn::MatchArray:0xc9d1168 @expected=[]>
got #<Array:105810180> => []
Here is my test:
context 'when there is no custom text locations' do
subject { create(:service, custom_text_locations: nil) }
it 'returns empty list' do
expect(subject.custom_text_locations).to match_array([])
end
end
If I change the match_array([]) by be_empty, my code works. Also, as pointed by @PeterAlfvin, change custom_text_locations initialization on the subject to [] seems to work.
This is my method:
def custom_text_locations
self[:custom_text_locations] || []
end
Question: What is wrong with my test?
subject.custom_text_locationswith[]does it pass? If you printsubject.custom_text_locations.inspectbefore theexpect, what do you get?[]it works. rspec version2.14.7. I'm adding the method also, since it seems to be involved the problem.