dimanche 31 juillet 2016

Test::Unit testing for Devise User::RegistrationController

I've been looking for how to setup testing for Devise 4.1.1 registration controller, I understand that this is not recommended, but for my application the registration controller has been customized particularly to pertain to our needs. We have only a few new columns to the users table that are getting saved during the sign up process, so I wouldn't assume that it is affecting the testing environment.

I also am aware that integration testing can be done to achieve this, however I am looking to do this with unit testing for now.

I have setup this section in the test_helper.rb as advised by Devise

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

I created a new file called registrations_controller.rb in the folder controllers/users/ because it did not already exist, and this is the contents:

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

When running rake test this is the output:

$ 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

What am I missing here??

Aucun commentaire:

Enregistrer un commentaire