0
我一直在尋找如何設置Devise 4.1.1註冊控制器的測試,我知道這不是建議的,但對於我的應用程序,註冊控制器已經定製特別是關係到我們的需求。在註冊過程中,我們只有很少的用戶表中有新的列被保存,所以我不會認爲它會影響測試環境。測試::設計用戶的單元測試:: RegistrationController
我也意識到可以完成集成測試來實現這一點,但是我現在正在用單元測試來做這件事。
/我已經安裝此節中的test_helper.rb中的建議通過制定
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
#This is what I added:
class ActionController::TestCase
include Devise::TestHelpers
end
我創建了一個名爲registrations_controller.rb新文件夾控制器/用戶,因爲它沒有已經存在了,這是內容:
require 'test_helper'
class Users::RegistrationsControllerTest < ActionController::TestCase
setup do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
test "sign_up view" do
get :new
assert_response :success
flunk("test flunk")
end
end
當運行rake test
這是輸出:
$ rake test
(in /home/www/dev)
Run options: --seed 163
# Running:
Finished in 0.010214s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
我在這裏錯過了什麼?