Reputation: 6612
I have a service object with a method which returns a hash with values as a result. I try to test this with rspec, but I have difficulties to check the returned values. Here is the spec:
it "calculates holiday balance for approved timesheets" do
subject = GraphBuilder.new.show_holidays(employee)
subject[:used].should eq("2.0")
end
But this returns an error:
no implicit conversion of Symbol into Integer
The method returns this hash:
[["type", "days"], ["used", 2.0], ["available", 25.0]]
What is the right way to do this? Thanks!
Upvotes: 0
Views: 112
Reputation: 160863
Your method returns an array, not a hash.
Convert this array to a hash like below:
Hash[[["type", "days"], ["used", 2.0], ["available", 25.0]]]
# => {"type"=>"days", "used"=>2.0, "available"=>25.0}
Upvotes: 1