3

Hi I am working on RoR project with ruby-2.5.0 and Rails 5. I have a method on controller which returns an array and the array contains a string and an object of a Reciept Model as follows:

["IGA", #<Reciept id: 1, name: "IGA", reciept_date: "2006-02-18 16:25:00", user_id: 1, created_at: "2018-04-07 11:53:33", updated_at: "2018-04-07 11:53:33">]

In my rspec i want to compare this array as follows:-

it { expect(described_class.find_store(params,user_id)).to eq(["IGA", #<Reciept id: 1, name: "IGA", reciept_date: "2006-02-18 16:25:00", user_id: 1, created_at: "2018-04-07 11:53:33", updated_at: "2018-04-07 11:53:33">]) }

It given syntax error as inside the array there is a '#' symbol so it comments my code. Please help me how can i compare this array. Thanks in advance.

2 Answers 2

1

Try to the following:

it { expect(described_class.find_store(params,user_id)).to eq(["IGA", Reciept.find(1)]) }
Sign up to request clarification or add additional context in comments.

Comments

1

For comparing arrays regardless of ordering, try match_array.

it { expect(described_class.find_store(params,user_id)).to match_array(["IGA", Reciept.find(1)]) }

This will pass whether "IGA" or Receipt comes first.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.