ruby - remove an element in an array of Hash in rspec -
here rspec code:-
"should match valid address" :index, devise.token_authentication_key => @user.authentication_token, business_id: @business2.id expect(response.status).to eq(200) expect(response.body).to eq([@location].to_json(locationfinder::api_params.merge(:root => false))) end
expected:
"[ { \"address\":\"1120 milky way\", \"business_id\":1, \"city\":\"cupertino\", \"latitude\":\"2.4\", \"longitude\":\"2.9\", \"name\":\"joe's diner\" } ]"
got:
"[ { \"address\":\"1120 milky way\", \"business_id\":1, \"city\":\"cupertino\", \"latitude\":\"2.4\", \"longitude\":\"2.9\", \"name\":\"joe's diner\", \"distance\":712.7948793 } ]"
how can remove "distance" field array contain hash value. test success.
you can delete key
hash delete
method, instance:
require 'json' = "[ { \"address\":\"1120 milky way\", \"business_id\":1, \"city\":\"cupertino\", \"latitude\":\"2.4\", \"longitude\":\"2.9\", \"name\":\"joe's diner\", \"distance\":712.7948793 } ]" = json.parse(a) a[0].delete "distance" p #output: # [{"address"=>"1120 milky way", "business_id"=>1, "city"=>"cupertino", "latitude"=>"2.4", "longitude"=>"2.9", "name"=>"joe's diner"}]
Comments
Post a Comment