做导轨教程,一切都很好,然后我的测试突然失败了。
用户数据库似乎存在问题,但我还没有触及它。
我删除了我的SQL文件并重新设置它。然后重新迁移并重新测试,结果仍然相同。
错误
rs191919:~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Run options: --seed 51875
# Running:
...................
Finished in 0.974929s, 19.4886 runs/s, 47.1829 assertions/s.
19 runs, 46 assertions, 0 failures, 0 errors, 0 skips
rs191919:~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Run options: --seed 18295
# Running:
...................
Finished in 1.007973s, 18.8497 runs/s, 51.5887 assertions/s.
19 runs, 52 assertions, 0 failures, 0 errors, 0 skips
rs191919:~/workspace/sample_app (log-in-log-out) $ rails g migration add_remember_digest_to_users remember:digest:string
invoke active_record
create db/migrate/20160110153840_add_remember_digest_to_users.rb
rs191919:~/workspace/sample_app (log-in-log-out) $ bundle exec rake db:migrate
== 20160110153840 AddRememberDigestToUsers: migrating =========================
-- add_column(:users, :remember, :digest)
-> 0.0012s
== 20160110153840 AddRememberDigestToUsers: migrated (0.0014s) ================
rs191919:~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Run options: --seed 58894
# Running:
EEEEEEEEEEEEEEEEEEE
Finished in 0.089546s, 212.1804 runs/s, 0.0000 assertions/s.
1) Error:
UsersLoginTest#test_login_with_invalid_information:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
UsersLoginTest#test_login_with_invalid_information:
NoMethodError: undefined method `each' for nil:NilClass
2) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
NoMethodError: undefined method `each' for nil:NilClass
3) Error:
SessionsControllerTest#test_should_get_new:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
SessionsControllerTest#test_should_get_new:
NoMethodError: undefined method `each' for nil:NilClass
4) Error:
UsersSignupTest#test_invalid_signup_information:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
UsersSignupTest#test_invalid_signup_information:
NoMethodError: undefined method `each' for nil:NilClass
5) Error:
UsersSignupTest#test_valid_signup_information:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
UsersSignupTest#test_valid_signup_information:
NoMethodError: undefined method `each' for nil:NilClass
6) Error:
UserTest#test_email_validation_should_reject_invalid_addresses:
ActiveRecord::StatementInvalid: Could not find table 'users'
7) Error:
UserTest#test_should_be_valid:
ActiveRecord::StatementInvalid: Could not find table 'users'
8) Error:
UserTest#test_email_validation_should_accept_valid_addresses:
ActiveRecord::StatementInvalid: Could not find table 'users'
9) Error:
UserTest#test_name_should_be_present:
ActiveRecord::StatementInvalid: Could not find table 'users'
10) Error:
UserTest#test_name_should_not_be_too_long:
ActiveRecord::StatementInvalid: Could not find table 'users'
11) Error:
UserTest#test_email_should_be_present:
ActiveRecord::StatementInvalid: Could not find table 'users'
12) Error:
UserTest#test_email_addresses_should_be_unique:
ActiveRecord::StatementInvalid: Could not find table 'users'
13) Error:
UserTest#test_email_should_not_be_too_long:
ActiveRecord::StatementInvalid: Could not find table 'users'
14) Error:
UsersControllerTest#test_should_get_new:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
UsersControllerTest#test_should_get_new:
NoMethodError: undefined method `each' for nil:NilClass
15) Error:
SiteLayoutTest#test_layout_links:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
SiteLayoutTest#test_layout_links:
NoMethodError: undefined method `each' for nil:NilClass
16) Error:
StaticPagesControllerTest#test_should_get_contact:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
StaticPagesControllerTest#test_should_get_contact:
NoMethodError: undefined method `each' for nil:NilClass
17) Error:
StaticPagesControllerTest#test_should_get_home:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
StaticPagesControllerTest#test_should_get_home:
NoMethodError: undefined method `each' for nil:NilClass
18) Error:
StaticPagesControllerTest#test_should_get_help:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
StaticPagesControllerTest#test_should_get_help:
NoMethodError: undefined method `each' for nil:NilClass
19) Error:
StaticPagesControllerTest#test_should_get_about:
ActiveRecord::StatementInvalid: Could not find table 'users'
Error:
StaticPagesControllerTest#test_should_get_about:
NoMethodError: undefined method `each' for nil:NilClass
19 runs, 0 assertions, 0 failures, 19 errors, 0 skips
rs191919:~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Run options: --seed 19458
再生固定后的第二轮错误
rs191919:~/workspace/sample_app (log-in-log-out) $ rails generate migration add_remember_digest_to_users remember_digest:string
invoke active_record
create db/migrate/20160117220806_add_remember_digest_to_users.rb
rs191919:~/workspace/sample_app (log-in-log-out) $ bundle exec rake db:migrate
== 20160117220806 AddRememberDigestToUsers: migrating =========================
-- add_column(:users, :remember_digest, :string)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "remember_digest" varchar/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:453:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_t me'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/home/ubuntu/workspace/sample_app/db/migrate/20160117220806_add_remember_digest_to_users.rb:3:in `change'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "remember_digest" varchar
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:453:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/home/ubuntu/workspace/sample_app/db/migrate/20160117220806_add_remember_digest_to_users.rb:3:in `change'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
SQLite3::SQLException: no such table: users
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:453:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/home/ubuntu/workspace/sample_app/db/migrate/20160117220806_add_remember_digest_to_users.rb:3:in `change'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
答案 0 :(得分:0)
我认为这里有一个错字:remember:digest:string
。它应该是remember_digest:string
。
答案 1 :(得分:0)
如果你在/ test / fixtures中有users.yml文件提交那里的所有行