我想將我的開發sqlite3數據庫導出到我的測試數據庫中。爲了做到這一點,我首先在rails控制檯中導出了我的模型並將其保存到文件中。to_yaml文件在rspec中沒有正確加載(rails項目)
> MyModel.all.to_yaml # this was saved to mymodels.yml
現在,當我運行rspec它嘗試解析mymodels.yml時失敗。我得到的錯誤是:
Failure/Error: Unable to find matching line from backtrace a YAML error occurred parsing /Users/MakeM/MyProject1/spec/fixtures/mymodels.yml.
Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: NoMethodError: undefined method `keys' for nil:NilClass
任何想法爲什麼我得到這個錯誤?我應該提到的一件事是,to_yaml輸出的yaml對我來說看起來有點奇怪。這裏是它的一部分:
---
- !ruby/object:MyModel
attributes:
id: 133
book: FirstBook
chapters: 50
created_at: 2010-10-06 05:03:15.709931
updated_at: 2010-10-06 05:03:15.709931
abbr: FB
attributes_cache: {}
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: false
previously_changed: {}
readonly: false
謝謝! .map(&:屬性)到底是做什麼的?我嘗試了谷歌搜索,但沒有拿出任何東西來幫助我理解。 – MakeM 2010-11-20 11:44:23
這似乎也不起作用。我得到相同的「失敗/錯誤:無法找回匹配線回溯 錯誤的數據...」錯誤。雖然yaml看起來更接近它應該看起來的樣子。 – MakeM 2010-11-20 11:59:48
map(&:attributes)調用所有模型的屬性方法並生成一個結果數組 – shingara 2010-11-20 12:19:57