Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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测试在作为套件运行时失败,但在单独运行时通过,并在CI上通过_Ruby On Rails_Ruby_Testing_Minitest - Fatal编程技术网

Ruby on rails Rails测试在作为套件运行时失败,但在单独运行时通过,并在CI上通过

Ruby on rails Rails测试在作为套件运行时失败,但在单独运行时通过,并在CI上通过,ruby-on-rails,ruby,testing,minitest,Ruby On Rails,Ruby,Testing,Minitest,我正在将Rails 5.2中的minitest与Factorybot一起使用 当我单独运行测试(例如models/enhanced_object_test.rb)时,它们通过了测试,但当我运行整个套件时,“看似”不相关的测试开始在“看似”不相关的方法上失败 有很多类似的问题,但都没有帮助。我曾尝试在每次测试之间使用DatabaseCleaner,但我也有同样的问题 我怀疑我的问题与我使用工厂的方式有关,但我不知道如何调试 我遇到的错误总是与方法import\u colms\u images\u

我正在将Rails 5.2中的minitest与Factorybot一起使用

当我单独运行测试(例如models/enhanced_object_test.rb)时,它们通过了测试,但当我运行整个套件时,“看似”不相关的测试开始在“看似”不相关的方法上失败

有很多类似的问题,但都没有帮助。我曾尝试在每次测试之间使用DatabaseCleaner,但我也有同样的问题

我怀疑我的问题与我使用工厂的方式有关,但我不知道如何调试

我遇到的错误总是与方法
import\u colms\u images\u to\u s3
有关,例如:

error relating to tests/models/info_test_page.rb

test_metadata                                                   FAIL (0.43s)
        not all expectations were satisfied
        unsatisfied expectations:
        - expected exactly once, invoked twice: #<EnhancedObject:0x55652b343e20>.import_colms_images_to_s3(any_parameters)
        - expected exactly once, invoked twice: #<EnhancedObject:0x556527763e28>.import_colms_images_to_s3(any_parameters)
        - expected exactly once, invoked twice: #<EnhancedObject:0x5565289bb170>.import_colms_images_to_s3(any_parameters)

信息测试页面模型的测试为:

require 'test_helper'

class InfoPageTest < ActiveSupport::TestCase

  setup do
    @infopage = create(:info_page)
  end

 test "metadata" do
    assert @infopage.metadata.present?
    assert_equal(@infopage.title, @infopage.metadata[:title])
  end
end
需要“测试助手”
类InfoPageTest
此测试使用info_页面工厂,但它与增强的_对象和失败的方法没有连接

test/factories/info_pages.rb

FactoryBot.define do
  factory :info_page do
    sequence(:title) { |n| "Info page #{n}" }
    sequence(:slug) { |n| "info-page-#{n}" }
    body { '{"data":[{"type":"heading","data":{"text":"Test info page",'\
         '"format":"html"}},{"type":"text","data":{"text":'\
         '"<p>This is some <b>body</b> text...</p>",'\
         '"format":"html"}},{"type":"quote","data":{"text":'\
         '"<p>This is a quote</p>", "format":"html",'\
         '"cite":"By someone useful."}}]}' }
    background_image {
      fixture_file_upload(
        Rails.root.join('test', 'fixtures', 'header.jpg'),
        'image/jpg') }
    background_image_credit { 'Kermit T. Frog' }
    colour_scheme { ColourScheme::COLOUR_SCHEMES.first }
  end

  trait :without_image do
    background_image { nil }
  end
end
test/factories/info_pages.rb
FactoryBot.define do
工厂:信息页面
顺序(:title){n}“信息页{n}”
序列(:slug){n}“信息页-{n}”
正文{{“数据”:[{“类型”:“标题”,“数据”:{“文本”:“测试信息页”,'\
““格式”:“html”},{“类型”:“文本”,“数据”:{“文本”:”\
“这是一些正文…”

“,”\ ““格式”:“html”},{“类型”:“引号”,“数据”:{“文本”:”\ “这是一个引号,,“格式”:“html”\ ““引用”:“由有用的人引用。”}}]}” 背景图像{ 夹具文件上传( Rails.root.join('test','fixtures','header.jpg'), 'image/jpg')} 背景图片信用卡{'Kermit T.Frog'} 颜色方案{colorscheme::color\u SCHEMES.first} 结束 特点:没有你的形象吗 背景图像{nil} 结束 结束
就我而言,信息页面和增强对象是不相关的,所以我无法理解为什么测试会以某种方式进行交互


最后一条线索是,当测试套件在Circle CI上运行时,测试作为套件运行时通过。

确保测试中没有进行任何全局更改,例如常量。。。当整个测试套件开始以随机顺序运行时,可能会产生问题。感谢您的建议。我看不到任何这种性质的事情发生。
test/factories/info_pages.rb

FactoryBot.define do
  factory :info_page do
    sequence(:title) { |n| "Info page #{n}" }
    sequence(:slug) { |n| "info-page-#{n}" }
    body { '{"data":[{"type":"heading","data":{"text":"Test info page",'\
         '"format":"html"}},{"type":"text","data":{"text":'\
         '"<p>This is some <b>body</b> text...</p>",'\
         '"format":"html"}},{"type":"quote","data":{"text":'\
         '"<p>This is a quote</p>", "format":"html",'\
         '"cite":"By someone useful."}}]}' }
    background_image {
      fixture_file_upload(
        Rails.root.join('test', 'fixtures', 'header.jpg'),
        'image/jpg') }
    background_image_credit { 'Kermit T. Frog' }
    colour_scheme { ColourScheme::COLOUR_SCHEMES.first }
  end

  trait :without_image do
    background_image { nil }
  end
end