5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on Rails 4.0 チュートリアル: Factory Girlの小さな問題

Posted at

Ruby on Rails 4.0 チュートリアル第9章、9.4.2「destroyアクション」
この節の destroyアクション用rspecコードは、そのままでは動作しない。rspecで以下のエラーが発生してしまう。

Failures:

  1) UserPages index delete links as an admin user
     Failure/Error: let(:admin) { FactoryGirl.create(:admin) }
     ArgumentError:
       Factory not registered: admin
     # ./spec/requests/user_pages_spec.rb:41:in `block (5 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:43:in `block (5 levels) in <top (required)>'

上で指摘されているように、以下のコードをspec/spec_helper.rb に追加する必要がある。

config.before(:all) do
	FactoryGirl.factories.clear
	FactoryGirl.sequences.clear
	FactoryGirl.find_definitions
end 
5
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?