我有一个单元测试文件test/unit/salon_test.rb
。当我运行ruby -Itest test/unit/salon_test.rb
时,测试通过就好了。当我尝试bundle exec rake test:units
时,我会收到以下错误:
2) Error:
test_create_account(SalonTest):
NoMethodError: undefined method `params' for main:Object
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/controller_adapters/abstract_adapter.rb:30:in `params'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/session/params.rb:96:in `params_credentials'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/session/params.rb:72:in `params_enabled?'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/session/params.rb:66:in `persist_by_params'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:407:in `_run__2708293592470526601__persist__999583656123085136__callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_persist_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/session/callbacks.rb:88:in `persist'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/session/persistence.rb:55:in `persisting?'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/session/persistence.rb:39:in `find'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `block in get_session_information'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each'
/Users/jason/Web/snip/rake/ruby/1.9.1/bundler/gems/authlogic-309187b26594/lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `get_session_information'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:407:in `_run__852872703163537099__save__999583656123085136__callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/callbacks.rb:264:in `create_or_update'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/persistence.rb:84:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/validations.rb:50:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/attribute_methods/dirty.rb:22:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block in save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:240:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/autosave_association.rb:409:in `save_belongs_to_association'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/autosave_association.rb:209:in `block in add_autosave_association_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/autosave_association.rb:161:in `instance_eval'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/autosave_association.rb:161:in `block in define_non_cyclic_method'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:418:in `_run__3406207238143745546__save__999583656123085136__callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/callbacks.rb:264:in `create_or_update'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/persistence.rb:84:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/validations.rb:50:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/attribute_methods/dirty.rb:22:in `save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block in save'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
/Users/jason/Web/snip/rake/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:240:in `save'
/Users/jason/Web/snip/test/unit/salon_test.rb:57:in `block in <class:SalonTest>'
我见过this similar question,但据我所知,这似乎不是同一个问题。
顺便说一下,我在Rails 3.2.1上。
我对Rails单元测试知之甚少。问题可能是什么?
答案 0 :(得分:1)
我卸载了Authlogic(我用Devise替换),问题就消失了。