这是我在Rails测试中的第一天,我有一个工作项目,但根本没有添加任何测试。首先,我想rake
看看一切是否正常(为了一个良好的开端),但是......
[37/38] UsermailerTest#test_notifyadmin = 0.00 s
25) Error:
test_notifyadmin(UsermailerTest):
NameError: uninitialized constant UsermailerTest::Usermailer
/Users/linus/Documents/Work/Coding/Rails/project/test/functional/usermailer_test.rb:5:in `block in <class:UsermailerTest>'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit/testcase.rb:17:in `run'
/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:447:in `_run__1175861498219140925__setup__3741829296426871776__callbacks'
/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:919:in `block in _run_suite'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:912:in `map'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:912:in `_run_suite'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:657:in `block in _run_suites'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:655:in `each'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:655:in `_run_suites'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:867:in `_run_anything'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1060:in `run_tests'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1047:in `block in _run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1046:in `each'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1046:in `_run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1035:in `run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:21:in `run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:774:in `run'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:366:in `block (2 levels) in autorun'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:27:in `run_once'
/Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:365:in `block in autorun'
[38/38] UsersControllerTest#test_should_get_show = 0.00 s
26) Failure:
test_should_get_show(UsersControllerTest) [/Users/linus/Documents/Work/Coding/Rails/project/test/functional/users_controller_test.rb:6]:
Expected response to be a <:success>, but was <302>
Finished tests in 0.763938s, 49.7423 tests/s, 27.4891 assertions/s.
38 tests, 21 assertions, 8 failures, 18 errors, 0 skips
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
Errors running test:functionals! #<RuntimeError: Command failed with status (26): [ruby -I"lib:test" -I"/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib" "/Users/linus/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/functional/**/*_test.rb" ]>
我完全不知道这里有什么问题(对我而言是新的领域),它来自哪里或我如何解决它所以我真的希望有人可以提供帮助。如果这很重要,我会为用户管理做好准备。
注意:上面的这个错误并不是唯一的,有很多,都差不多,所以我想我只是为了清晰起见而添加一个。
[37/38] UsermailerTest#test_notifyadmin = 0.00 s
25) Error:
test_notifyadmin(UsermailerTest):
NameError: uninitialized constant UsermailerTest::Usermailer
依旧......
更新
以下是test / functional / usermailer_test.rb
的代码要求'test_helper'
class UsermailerTest < ActionMailer::TestCase
test "notifyadmin" do
mail = Usermailer.notifyadmin
assert_equal "Notifyadmin", mail.subject
assert_equal ["to@example.org"], mail.to
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end
end
答案 0 :(得分:0)
事实证明,有一些测试控制器的版本。有些被命名为复数,有些是单数。奇异的命名控制器导致错误消息,因为它们与我对mvc控制器的最后更改不一致。另外,我将Usermailer等一些控制器重命名为UserMailer,这导致了无法找到的问题。