RSpec 2 に飛び込もうとしましたが、その自動生成されたコントローラー スペックは、Ruby のどのバージョンまたは Rails のどのバージョンでも、RSpec 2 のどのバージョンでも機能しません。多分私は明らかな何かを見逃していますか?
def mock_category(stubs={})
@mock_category ||= mock_model(Category, stubs).as_null_object
end
describe "GET show" do
it "assigns the requested category as @category" do
Category.stub(:find).with("37") { mock_category }
get :show, :id => "37"
assigns(:category).should be(mock_category)
end
end
これはから自動生成されますrails g scaffold Category
RSpec はこれを返します:
Failures:
1) CategoriesController GET show assigns the requested category as @category
Failure/Error: assigns(:category).should be(mock_category)
expected Category_1002, got nil
# ./spec/controllers/categories_controller_spec.rb:21
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject'
このモック/スタブが返されるのはなぜnil
ですか?
アップデート
これは、コントローラーの show メソッドからのものです。
def show
@category = Category.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @category }
end
end
ありがとう!