Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.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
TestClass(Rails)的Rspec作用域问题_Rspec_Rspec Rails - Fatal编程技术网

TestClass(Rails)的Rspec作用域问题

TestClass(Rails)的Rspec作用域问题,rspec,rspec-rails,Rspec,Rspec Rails,当我分别运行这些rspec文件时,它们都通过了,当我一起运行时,它们失败了 似乎当我运行@application\u presenter=descripted\u class.new(TestClass.new,view\u context)时,它使用了ActAsAttribute\u spec.rb中的TestClass 这似乎是一个范围问题。我认为RSpec.descripe是有名称空间的。处理这一冲突的最佳方式是什么?我可以更改TestClass的名称,但我更喜欢一种更好的方法,即确保我的

当我分别运行这些rspec文件时,它们都通过了,当我一起运行时,它们失败了

似乎当我运行
@application\u presenter=descripted\u class.new(TestClass.new,view\u context)
时,它使用了ActAsAttribute\u spec.rb中的TestClass

这似乎是一个范围问题。我认为RSpec.descripe是有名称空间的。处理这一冲突的最佳方式是什么?我可以更改TestClass的名称,但我更喜欢一种更好的方法,即确保我的类等在每个
Rspec.description
块中都有名称空间

应用程序\演示者\规范rb
# frozen_string_literal: true

require "rails_helper"

RSpec.describe ApplicationPresenter do
  class TestClass
    def checked_deligation?
      true
    end
  end

  class TestClassPresenter < ApplicationPresenter
    def test_method; end
  end  
  
  let(:view_context) { instance_double(ActionView::Base) }

  before do
    @application_presenter = described_class.new(TestClass.new, view_context)
  end
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Registration::Base::ActAsAttribute, type: :model do
  class Examplemodel1
    include ActiveModel::Model
    include ActiveModel::Attributes

    attribute :field1, :string, default: "field1_value"
  end

  class Examplemodel2
    include ActiveModel::Model
    include ActiveModel::Attributes

    attribute :field2, :string, default: "field2_value"
  end


  class TestClass
    include ActiveModel::Model
    include Registration::Base::ActAsAccessorsAndSave
    include Registration::Base::ActAsAttribute

    def self.form_fields_mapping
      [
        {name: :field1, model: :examplemodel1},
        {name: :field2, model: :examplemodel2}
      ]
    end
    setup_attributes
  end

  let(:examplemodel1) { Examplemodel1.new }
  let(:examplemodel2) { Examplemodel2.new }
  let(:instance_of_test) { TestClass.new }