0

这是我在 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
4

1 回答 1

0

事实证明,一些测试控制器有 2 个版本。有些被命名为复数,有些被命名为单数。单数命名的控制器会导致错误消息,因为它们不是最新的我对 mvc 控制器所做的最后更改。此外,我将一些控制器(如 Usermailer)重命名为 UserMailer,导致无法找到它们。

于 2013-09-06T07:32:24.020 回答