Hi, I''m pretty new to rspec. I''m writing some spec for a Rails 3.0 app with Devise (branch omniauth), rspec 2.0.1 and factory_girl. When I run spec file by file (ex: rspec spec/models/ document_spec.rb) , it run sometimes withtout error and sometimes with some errors (duplicate entry in DB). That''s the first I don''t understand: Why it''s sometimes working and sometimes not ? How can I do to make this work all the time (except of course if there is some change in the model that really break the test) ?. I try also to run all my spec at once (rspec spec) but I have a lot of error with Devise: here is my stack error: Failure/Error: @user = Factory(:user) Could not find a valid mapping for #<User:0x10ceaf8a0> # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/lib/devise/ mapping.rb:40:in `find_scope!'' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ devise/mailer.rb:26:in `initialize_from_record'' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ devise/mailer.rb:21:in `setup_mail'' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ devise/mailer.rb:6:in `confirmation_instructions'' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ base.rb:150:in `send_action'' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ base.rb:150:in `process_action'' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ base.rb:119:in `process'' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ rendering.rb:40:in `process'' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ old_api.rb:75:in `process'' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:446:in `process'' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:441:in `initialize'' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:425:in `new'' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:425:in `method_missing'' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/lib/devise/ models/confirmable.rb:50:in `send_confirmation_instructions'' # ./lock/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/ callbacks.rb:422:in `_run_create_callbacks'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ callbacks.rb:281:in `create'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ persistence.rb:247:in `create_or_update'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ callbacks.rb:277:in `create_or_update'' # ./lock/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/ callbacks.rb:423:in `_run_save_callbacks'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ callbacks.rb:277:in `create_or_update'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ persistence.rb:56:in `save!'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ validations.rb:49:in `save!'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ attribute_methods/dirty.rb:30:in `save!'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:242:in `save!'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:289:in `with_transaction_returning_status'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ connection_adapters/abstract/database_statements.rb:139:in `transaction'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:204:in `transaction'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:287:in `with_transaction_returning_status'' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:242:in `save!'' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/proxy/ create.rb:6:in `result'' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:327:in `run'' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:270:in `create'' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:301:in `send'' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:301:in `default_strategy'' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl.rb: 20:in `Factory'' # ./spec/models/user_spec.rb:62 # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:29:in `instance_eval'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:29:in `run_in'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:60:in `run_all'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:60:in `each'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:60:in `run_all'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:106:in `run_hook'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:188:in `eval_before_eachs'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:188:in `each'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:188:in `eval_before_eachs'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:121:in `run_before_each'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:46:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:86:in `call'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:86:in `with_around_hooks'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:44:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:80:in `call'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:80:in `with_pending_capture'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:79:in `catch'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:79:in `with_pending_capture'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:43:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:260:in `run_examples'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:256:in `map'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:256:in `run_examples'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:230:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:231:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:231:in `map'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:231:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:26:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:26:in `map'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:26:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/reporter.rb:11:in `report'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:23:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/runner.rb:55:in `run_in_process'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/runner.rb:46:in `run'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/runner.rb:10:in `autorun'' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/bin/rspec:19 So, what can I do to avoid this error and make my test running ? Thanks a lot for your help ! Jonathan
On Oct 19, 2010, at 4:49 AM, Jbiolaz wrote:> Hi, > > I''m pretty new to rspec. I''m writing some spec for a Rails 3.0 app > with Devise (branch omniauth), rspec 2.0.1 and factory_girl. > > When I run spec file by file (ex: rspec spec/models/ > document_spec.rb) , it run sometimes withtout error and sometimes with > some errors (duplicate entry in DB).Make sure you''ve got config.use_transactional_fixtures = true in spec/spec_helper.rb and that you are not setting up any models in before(:all) blocks.> That''s the first I don''t > understand: Why it''s sometimes working and sometimes not ? How can I > do to make this work all the time (except of course if there is some > change in the model that really break the test) ?. > > I try also to run all my spec at once (rspec spec) but I have a lot of > error with Devise: > > here is my stack error: > > Failure/Error: @user = Factory(:user) > Could not find a valid mapping for #<User:0x10ceaf8a0> > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/lib/devise/ > mapping.rb:40:in `find_scope!'' > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ > devise/mailer.rb:26:in `initialize_from_record'' > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ > devise/mailer.rb:21:in `setup_mail'' > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ > devise/mailer.rb:6:in `confirmation_instructions''<snip/>> So, what can I do to avoid this error and make my test running ? > > Thanks a lot for your help ! > JonathanNot sure about the Devise issue. I''d recommend checking http://groups.google.com/group/plataformatec-devise for that one. Good luck, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101021/2fdf3e42/attachment.html>