Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.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 FactoryGirl创建用户,但在测试开始之前释放保存点_Ruby On Rails_Rspec_Factory Bot - Fatal编程技术网

Ruby on rails FactoryGirl创建用户,但在测试开始之前释放保存点

Ruby on rails FactoryGirl创建用户,但在测试开始之前释放保存点,ruby-on-rails,rspec,factory-bot,Ruby On Rails,Rspec,Factory Bot,我正在为规范/请求/用户页面\u规范运行rspec测试: require 'spec_helper' describe "User pages" do subject { page } describe "home page" do before { visit root_path } it { should have_content('Sign up with Facebook') } it { should have_title(full_title(

我正在为规范/请求/用户页面\u规范运行rspec测试:

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "home page" do
    before { visit root_path }

    it { should have_content('Sign up with Facebook') }
    it { should have_title(full_title('')) }
  end

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    before { visit user_path(user.id) }

    it { should have_content(user.name) }
    it { should have_title(user.name) }
  end
end
如您所见,我正在使用FactoryGirl创建一个用户。当我运行相同的命令时(即,
FactoryGirl.create(:user)
)是
rails控制台测试--sandbox
,用户被正确创建和保存

但是,当我运行测试时,FactoryGirl会在数据库中创建用户,然后在测试实际运行之前释放它。我可以从test.log中看到这一点:

[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m  [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
  [1m[35m (0.1ms)[0m  begin transaction
  [1m[36m (0.1ms)[0m  [1mSAVEPOINT active_record_1[0m
  [1m[35mUser Exists (0.1ms)[0m  SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('test@foobar.com') LIMIT 1
  [1m[36mSQL (2.0ms)[0m  [1mINSERT INTO "users" ("created_at", "email", "name", "oauth_expires_at", "oauth_token", "provider", "uid", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?)[0m  [["created_at", Wed, 23 Apr 2014 16:17:16 UTC +00:00], ["email", "test@foobar.com"], ["name", "Test User"], ["oauth_expires_at", Wed, 23 Apr 2014 00:00:00 UTC +00:00], ["oauth_token", "10987654321ABCDEFG"], ["provider", "facebook"], ["uid", "12345"], ["updated_at", Wed, 23 Apr 2014 16:17:16 UTC +00:00]]
  [1m[35m (0.0ms)[0m  RELEASE SAVEPOINT active_record_1
Started GET "/users/1" for 127.0.0.1 at 2014-04-23 10:17:16 -0600
Processing by UsersController#show as HTML
  Parameters: {"id"=>"1"}
  [1m[36mUser Load (0.1ms)[0m  [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m  [["id", "1"]]

为什么会发生这种情况?我如何阻止它在测试之后才发布?

您所说的“发布”用户是什么意思。。。你的考试不及格吗?如果是,你能告诉我们错误信息吗?我想你已经同时解决了这个问题。。。你能把它添加为“答案”吗?这样这个问题就可以在“未回答”队列中显示更长的时间了我也面临同样的问题。你找到解决这个问题的办法了吗?