当我做一些功能测试时,minitest-spec-rails出错了



in my Gemfile:

group :test do
  gem 'minitest-spec-rails'
end

我的测试文件在rail_root/test/functional/publisher_controller_test.rb

# -*- encoding : utf-8 -*-
describe PublisherController do
  describe "GET #signin" do
    it "responds successfully with an HTTP 200 status code" do
      get :signin
      assert_response :success
    end
  end
end

我的单元测试工作得很好,但是当我运行

ruby -Itest testfunctionalpublisher_controller_test.rb"

出错了,下面是错误:

test/functional/publisher_controller_test.rb:2:in `<main>': 
    uninitialized constant PublisherController (NameError).

我只是不知道为什么它可以找到我的模型,但不能找到控制器。

Rails期望控制器名是复数形式,像这样:

PublishersController

您的测试使用了一个不存在的单一控制器名称PublisherController。这可能是由于使用生成器时的打字错误造成的。

修改PublisherPublishers。记住也要更改文件名

最新更新