设计集成测试

时间:2017-12-26 17:01:07

标签: ruby-on-rails devise

我使用devise进行集成测试时遇到了一些麻烦。尽管方法运行良好,但它并不是sign_in

require 'admin_test_helper'

class Admin::PagesControllerTest < ActionDispatch::IntegrationTest
  setup do
    sign_in users(:one), scope: :admin
    @page = pages(:one)
  end

  test "should get index" do
    get admin_pages_url
    assert_response :success
  end
end

测试助手

# test/admin_test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  include Devise::Test::IntegrationHelpers
  fixtures :all

  setup do
    @organization = organizations(:one)
  end
end

当我在设置中添加断点并尝试使用sign_in方法时,我注意到了一件事。它返回了一个proc。不确定是否应该返回别的东西?

我的测试将失败Expected response to be a <2XX: success>, but was a <302: Found> redirect to <http://www.example.com/users/sign_in>

我没有确认我在其他帖子中注意到的问题。

0 个答案:

没有答案