bundle exec rake test:模型抛出Errno :: EACCES:权限被拒绝

时间:2014-09-28 21:23:30

标签: ruby-on-rails sqlite rake

我正在执行railstutorial的草稿版本,当我尝试运行bundle exec rake test:models时收到此错误消息:

rake aborted!
Errno::EACCES: Permission denied - C:/Users/Alex/Desktop/Workspace/Rails/sample_
app/db/test.sqlite3
C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/test_helper.rb:3:in `<top
(required)>'
C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/helpers/application_helper
_test.rb:1:in `<top (required)>'
Tasks: TOP => test:run => test:units
(See full trace by running task with --trace)

使用--trace:

** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Execute test:prepare
** Execute test:units
rake aborted!
Errno::EACCES: Permission denied - C:/Users/Alex/Desktop/Workspace/Rails/sample_
app/db/test.sqlite3
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1432:in `unlink'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1432:in `block in remove
_file'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1440:in `platform_suppor
t'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1431:in `remove_file'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:785:in `remove_file'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:563:in `block in rm'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:562:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:562:in `rm'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/sqlite_database_tasks.rb:22:in `drop'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/sqlite_database_tasks.rb:26:in `purge'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:159:in `purge'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:201:in `load_schema_for'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:216:in `block in load_schema_current'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:255:in `block in each_current_configurat
ion'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:254:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:254:in `each_current_configuration'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/tasks/database_tasks.rb:215:in `load_schema_current'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/migration.rb:402:in `load_schema_if_pending!'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/migration.rb:409:in `block in maintain_test_schema!'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/migration.rb:637:in `suppress_messages'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/migration.rb:414:in `method_missing'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta1/li
b/active_record/migration.rb:409:in `maintain_test_schema!'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_help.rb:19:in `<top (required)>'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `block in require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:233:in `load_dependency'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `require'
C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/test_helper.rb:3:in `<top
(required)>'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `block in require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:233:in `load_dependency'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `require'
C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/helpers/application_helper
_test.rb:1:in `<top (required)>'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `block in require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:233:in `load_dependency'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta1/l
ib/active_support/dependencies.rb:248:in `require'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/sub_test_task.rb:114:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/sub_test_task.rb:113:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/sub_test_task.rb:113:in `block in define'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:240:in `call'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:240:in `block in execute'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:235:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:235:in `execute'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:179:in `block in invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:172:in `invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:201:in `block in invoke_prerequisites'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:199:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:199:in `invoke_prerequisites'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:178:in `block in invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:172:in `invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:165:in `invoke'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta1/lib/ra
ils/test_unit/testing.rake:8:in `block in <top (required)>'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:240:in `call'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:240:in `block in execute'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:235:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:235:in `execute'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:179:in `block in invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:172:in `invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.r
b:165:in `invoke'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:150:in `invoke_task'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:106:in `block (2 levels) in top_level'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:106:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:106:in `block in top_level'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:115:in `run_with_threads'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:100:in `top_level'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:78:in `block in run'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:176:in `standard_exception_handling'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/applic
ation.rb:75:in `run'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.3.2/bin/rake:33:in
`<top (required)>'
C:/RailsInstaller/Ruby2.0.0/bin/rake:23:in `load'
C:/RailsInstaller/Ruby2.0.0/bin/rake:23:in `<main>'
Tasks: TOP => test:run => test:units

我已经尝试检查我的db文件夹的权限,并尝试重新启动所有内容。我在Windows上使用rails版本4.2.0beta1。当我制作“用户”模型时,问题就出现了。我尝试回滚并再次迁移。

编辑: 似乎我的测试数据库在某种程度上被破坏了。如果我将/config/database.yml测试更改为/db/development.sqlite,则测试可以正常工作。

4 个答案:

答案 0 :(得分:7)

我删除了旧的test.sqlite3并将其替换为development.sqlite3的副本并将其重命名为test.sqlite3,这似乎解决了这个问题。

答案 1 :(得分:6)

在运行测试之前运行rake db:migrate RAILS_ENV=test

我不是专家,所以我不知道在迁移开发数据库时是否应该自动迁移测试数据库,但这会迁移它,并解决了我类似的问题。

注意:我的操作系统是Windows 8.1

答案 2 :(得分:0)

是的,问题出在Windows上。当您读取railsinstaller目录中找到的fileutils.rb的代码时。它希望取消链接并希望授予权限700(在unix / linux中找到)但不在Windows中。所以不行。

以下是fileutil.rb文件的片段。

def remove_file
  platform_support {
    File.unlink path
  }
end

def platform_support
  return yield unless fu_windows?
  first_time_p = true
  begin
    yield
  rescue Errno::ENOENT
    raise
  rescue => err
    if first_time_p
      first_time_p = false
      begin
        File.chmod 0700, path()   # Windows does not have symlink
        retry
      rescue SystemCallError
      end
    end
    raise err
  end
end

答案 3 :(得分:0)

我注意到如果我有一个终端打开运行rails服务器而另一个终端要工作,就会发生这种情况。我的工作终端是我尝试删除或重置数据库时给我的问题。我关闭服务器并再次尝试,它工作正常。