我在我的ruby腳本中使用了mysql2。 以此來測試對MySQL數據庫Mysql2響應不適用於在Ruby中收集的方法
該API響應是我的劇本的片段
test_job_by_id_5
id = $data["jobs"]["id"][i] # example 5
job = JobServices.job_by_id(id)
response = @@con.query("select * from jobs where id = #{id}") #select * from jobs where id =5
rs=response.collect #this fails
assert_match(job[0]['title'],rs[0]['title'],"The title values are equal for #{$data["jobs"]["id"][i]}")
end
所以當我用這個與ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10]
它就像一個魅力
但是當我使用ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
這是行不通的 我得到這個錯誤
NoMethodError: undefined method '[]' for
#<Enumerator: #<Mysql2::Result:0x00000012d19f18>:collect>
可不可以有一個人請^ h elp我解決這個問題?
爲了清楚起見,我首先考慮在'assert_match'行中爲你的散列索引字符串使用單引號。 –
我想我使用單引號,我不知道你的意思 – Amey
也許再次看最後一個字符串,「標題值...」現在你知道我的意思了嗎? –