Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 设计在rails集成测试中不能正常工作_Ruby On Rails_Ruby On Rails 3_Devise_Integration Testing - Fatal编程技术网

Ruby on rails 设计在rails集成测试中不能正常工作

Ruby on rails 设计在rails集成测试中不能正常工作,ruby-on-rails,ruby-on-rails-3,devise,integration-testing,Ruby On Rails,Ruby On Rails 3,Devise,Integration Testing,首先,我使用的是Rails附带的内置集成测试套件,而不是cucumber、webrat等。在切换到其他测试套件之前,我希望掌握内置套件 使用Desive 1.4.2和rails 3.1 无论如何,我正在编写一个集成测试,模拟用户注册帐户、确认帐户、重新登录并填写表单。这就是事情似乎变得越来越糟的地方。据我所知,Desive与我的控制器create action存在问题,由于Desive存在这些问题,当前用户为零。以下是一个片段: require 'test_helper' class Sign

首先,我使用的是Rails附带的内置集成测试套件,而不是cucumber、webrat等。在切换到其他测试套件之前,我希望掌握内置套件

使用Desive 1.4.2和rails 3.1

无论如何,我正在编写一个集成测试,模拟用户注册帐户、确认帐户、重新登录并填写表单。这就是事情似乎变得越来越糟的地方。据我所知,Desive与我的控制器create action存在问题,由于Desive存在这些问题,当前用户为零。以下是一个片段:

require 'test_helper'

class SignupTest < ActionDispatch::IntegrationTest

test "new signup and application" do

  go_to_signup_page
  create_new_account :user => {:email => "kjsdfkjksjdf@sdfsdf.com", :user_name => "dfdfdf",     
  :password => "dfdfdfdfdfdf", :password_confirmation => "dfdfdfdfdfdf"}
  confirm_account_creation
  go_to_signin_page
  log_in
  go_to_form
  submit_form
end
在我的控制器里我有

  before_filter :authenticate_user!
根据我的判断,“def go_to_form”可以通过。但当我尝试在“def submit_form”中发布时,它会告诉我需要“请先登录或注册”,这是您在尚未登录的情况下尝试访问函数时出现的典型设计错误。 我认为这个问题也会导致当前用户为零

如果我删除before_过滤器,我将发布,但当前_用户仍然为零


我无法解释这里发生了什么事。除此创建操作外,所有其他操作都以出色的成绩通过

这是我正在使用的FactoryGirl的工作代码,通过这段代码,您可以成功登录,确保您输入了准确的电子邮件和密码。但Desive gem中也有内置测试用例,请看一下

  setup do
    @user = FactoryGirl.create(:user)
  end

  def do_login
    visit '/'
    click_link "Sign in"
    fill_in 'user_email', :with => 'xxx@xxx.com'
    fill_in 'user_password', :with => 'xxxx'
    click_on('sign_in')
  end

  test 'should go to section index' do
    do_login
    assert page.has_content?('Signed in successfully.')
  end
这是一个工厂:

FactoryGirl.define do
  factory :user do

    email "xxx@xxx.com"
    password "xxxx"
    password_confirmation "xxxx"
    :user_name "admin"
    confirmed_at "#{Time.now }"
  end
end

这是我正在使用的FactoryGirl的工作代码,通过这段代码,您可以成功登录,确保您输入了准确的电子邮件和密码。但Desive gem中也有内置测试用例,请看一下

  setup do
    @user = FactoryGirl.create(:user)
  end

  def do_login
    visit '/'
    click_link "Sign in"
    fill_in 'user_email', :with => 'xxx@xxx.com'
    fill_in 'user_password', :with => 'xxxx'
    click_on('sign_in')
  end

  test 'should go to section index' do
    do_login
    assert page.has_content?('Signed in successfully.')
  end
这是一个工厂:

FactoryGirl.define do
  factory :user do

    email "xxx@xxx.com"
    password "xxxx"
    password_confirmation "xxxx"
    :user_name "admin"
    confirmed_at "#{Time.now }"
  end
end