我目前正在阅读关于 RoR 教程(Hartl's)的第 6 章,以了解建模用户。而且,我在运行 rake 测试时遇到了问题 - 我经常收到如下所示的错误消息:
/u$ bundle exec rake test
rake aborted!
test_should_get_new is already defined in UsersControllerTest
/Users/joebcvan/.rvm/gems/ruby-2.2.0@global/gems/activesupport-
4.2.0/lib/active_support/testing/declarative.rb:14:in `test'
.
.
.
/Users/joebcvan/.rvm/gems/ruby-2.2.0@global/gems/railties-
4.2.0/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
/Users/joebcvan/.rvm/gems/ruby-2.2.0@global/gems/railties-
4.2.0/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)
因此,我查看了 user_Controller_test.rb 文件,并尝试在这里坐立不安,但没有运气。我的 user_controller_test.rb 如下所示。
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
我试过删除下面显示的四行代码
test "should get new" do
get :new
assert_response :success
end
并运行 rake 测试,错误消息现在显示如下:
1) Error:
SiteLayoutTest#test_should_get_home:
SyntaxError: /Users/joebcvan/workspace/sample_app/app/models/user.rb:5: syntax
error, unexpected ':', expecting keyword_end
format: { with: VALID_EMAIL_REGEX}
^
Error:
SiteLayoutTest#test_should_get_home:
NoMethodError: undefined method `each' for nil:NilClass
2) Error:
SiteLayoutTest#test_should_get_help:
SyntaxError: /Users/joebcvan/workspace/sample_app/app/models/user.rb:5: syntax
error, unexpected ':', expecting keyword_end
format: { with: VALID_EMAIL_REGEX}
^
Error:
SiteLayoutTest#test_should_get_help:
NoMethodError: undefined method `each' for nil:NilClass
.
.
.
.
12) Error:
UserTest#test_name_should_not_be_too_long:
SyntaxError: /Users/joebcvan/workspace/sample_app/app/models/user.rb:5: syntax
error, unexpected ':', expecting keyword_end
format: { with: VALID_EMAIL_REGEX}
^
13) Error:
UserTest#test_should_be_valid:
SyntaxError: /Users/joebcvan/workspace/sample_app/app/models/user.rb:5: syntax
error, unexpected ':', expecting keyword_end
format: { with: VALID_EMAIL_REGEX}
^
13 runs, 0 assertions, 0 failures, 13 errors, 0 skips
现在我被卡住了..我是RoR的初学者,我感到很无助...我不知道如何弄清楚这些错误代码。
我将非常感谢您的专家建议。
谢谢你。