异常消息:没有要在 Rails 应用程序中加载的文件
我已将 test_helper.rb
包含在我的 Rails 应用程序中的 test
下。我什至包括了 在我的 test->unit
下的 test.rb
文件中 require 'test_helper'
。当我在 RubyMine 中运行应用程序的所有测试时,出现以下错误:
我拥有所有 RubyMine 3.2、ruby 1.9.2p290 和 Rails 3.1.0 的最新版本。
/Users/im/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb
Testing started at 3:19 PM ...
Work directory: /Users/im/RubymineProjects/BackChannelApp}
Loading files....
=========================================
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/posts_helper_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/posts_helper_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/posts_helper_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/users_helper_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/users_helper_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/users_helper_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/post_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/post_test.rb:4:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/post_test.rb:4:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/user_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/user_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/user_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Creating sqlite :memory: database
-- create_table("posts", {:force=>true})
-> 0.0346s
-- create_table("users", {:force=>true})
-> 0.0010s
-- initialize_schema_migrations_table()
-> 0.0008s
-- assume_migrated_upto_version(20110926132602, ["db/migrate"])
-> 0.0005s
1. /Users/im/RubymineProjects/BackChannelApp/test/test_helper.rb:1
1 files were loaded.
=========================================
Searching test suites...
=========================================
DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixtures is deprecated! Use ActiveRecord::Fixtures instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixtures is deprecated! Use ActiveRecord::Fixtures instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixture is deprecated! Use ActiveRecord::Fixture instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixture is deprecated! Use ActiveRecord::Fixture instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
Test suite #1: ActionDispatch::IntegrationTest
Ignored because it is default rails empty test suite
=========================================
Test suite #1: ActiveSupport::TestCase
Ignored because it is default rails empty test suite
=========================================
Test suite #1: ActionController::TestCase
Ignored because it is default rails empty test suite
DEPRECATION WARNING: ActiveSupport::SecureRandom is deprecated! Use SecureRandom instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
=========================================
Test suite #1: ActiveRecord::TestCase
Ignored because it is default rails empty test suite
=========================================
0 test suites, 0 tests, 0 assertions, 0 failures, 0 errors
Process finished with exit code 0
我缺少什么? 谢谢!
I have included test_helper.rb
under test
in my rails application. I have even includedrequire 'test_helper'
in my test.rb
files under test->unit
. When I run all the test in RubyMine for the application, I get the following error:
I have the latest versions of all RubyMine 3.2, ruby 1.9.2p290 and Rails 3.1.0.
/Users/im/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb
Testing started at 3:19 PM ...
Work directory: /Users/im/RubymineProjects/BackChannelApp}
Loading files....
=========================================
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/posts_helper_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/posts_helper_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/posts_helper_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/users_helper_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/users_helper_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/helpers/users_helper_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/post_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/post_test.rb:4:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/post_test.rb:4:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/unit/user_test.rb:1
Exception message: no such file to load -- test_helper
/Users/im/RubymineProjects/BackChannelApp/test/unit/user_test.rb:1:in `require'
/Users/im/RubymineProjects/BackChannelApp/test/unit/user_test.rb:1:in `<top (required)>'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `load_scripts_to_object_space'
/Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:101:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Creating sqlite :memory: database
-- create_table("posts", {:force=>true})
-> 0.0346s
-- create_table("users", {:force=>true})
-> 0.0010s
-- initialize_schema_migrations_table()
-> 0.0008s
-- assume_migrated_upto_version(20110926132602, ["db/migrate"])
-> 0.0005s
1. /Users/im/RubymineProjects/BackChannelApp/test/test_helper.rb:1
1 files were loaded.
=========================================
Searching test suites...
=========================================
DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixtures is deprecated! Use ActiveRecord::Fixtures instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixtures is deprecated! Use ActiveRecord::Fixtures instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixture is deprecated! Use ActiveRecord::Fixture instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
DEPRECATION WARNING: Fixture is deprecated! Use ActiveRecord::Fixture instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
Test suite #1: ActionDispatch::IntegrationTest
Ignored because it is default rails empty test suite
=========================================
Test suite #1: ActiveSupport::TestCase
Ignored because it is default rails empty test suite
=========================================
Test suite #1: ActionController::TestCase
Ignored because it is default rails empty test suite
DEPRECATION WARNING: ActiveSupport::SecureRandom is deprecated! Use SecureRandom instead. (called from is_test_case_class? at /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:80)
=========================================
Test suite #1: ActiveRecord::TestCase
Ignored because it is default rails empty test suite
=========================================
0 test suites, 0 tests, 0 assertions, 0 failures, 0 errors
Process finished with exit code 0
What am I missing?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的情况下(RM 7.1 / Win7 / Rails 3.0),我必须执行以下操作:
注意:将工作目录更改为“test”对我来说不起作用。
来源:https://devnet.jetbrains.com/message/5490675#5490675
In my situation (RM 7.1 / Win7 / Rails 3.0), I had to do the following:
Note: Changing the working directory to 'test' didn't work for me.
Source: https://devnet.jetbrains.com/message/5490675#5490675
test_helper.rb 位于测试目录中。您正在从根目录运行测试,这意味着文件的路径是错误的。尝试从测试目录运行测试。
如果您想从根目录运行测试,则必须将其更改为
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
,其中 FILE 是包含此行(您的测试用例)的文件的路径,其余部分是 test_helper.rb 相对于该文件的路径。这样,您从哪里运行测试就无关紧要了。test_helper.rb is located within the test directory. You are running the tests from the root directory, which means the path to the file is wrong. Try running your tests from the test directory.
If you want to run your tests from the root directory, you would have to change this to
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
, where FILE is the path to the file that contains this line (your test case), and the rest is the path of test_helper.rb, relative to that file. This way, where you run the test from is irrelevant.