1
我剛剛升級到Ruby 1.9.3-p0的Rails 3.2.1,我正在使用Machinist 2.0。在更新大型項目之前,所有測試都通過了。我「米遇到的問題是,當我在我的RSpec的測試中創建一個‘讓’調用中的藍圖,然後參考它在做之前塊。rails 3.2和機械師問題
let (:new_post) {Post.make!}
before do
Post.stub!(:new).and_return(new_post)
end
這用來工作的,現在我得到的以下錯誤:
1) PostsController GET index assigns all posts as @posts
Failure/Error: let (:new_post) {Post.make!}
NoMethodError:
undefined method `title=' for nil:NilClass
# ./spec/support/blueprints.rb:22:in `block in <top (required)>'
# ./spec/controllers/posts_controller_spec.rb:37:in `block (2 levels) in <top (required)>'
# ./spec/controllers/posts_controller_spec.rb:40:in `block (2 levels) in <top (required)>'
這裏是我的藍圖:
require 'machinist/active_record'
Post.blueprint do
title {"Post"}
body {"hello world"}
end
現在我的解決辦法是使用之前做塊中的實例變量來創建它們,但它會是不錯的使用「讓'呼籲,因爲它的關鍵ps我的rspec測試更清潔。
我升級到Rails 3.2.1並有同樣的問題,但現在看起來這是一個很好的解決方案。 – map7 2012-02-22 00:15:00
很高興爲你效勞。我會嘗試查看代碼並查看哪個項目需要通知該問題。 – poetmountain 2012-02-22 02:21:26