title: Error undefined constant and frozen Array during Rspec and FactoryBot
body: <p>I'm running through an error during Rspec. When I run rspec the following errors happen.</p>
  
  <p>I've seen some questions and answers here but none of them helped me. One of them included downgraded Factory Bot to 4.10 and run rubocop to modify the constants while upgrade to 5.0.</p>
  
  <p>I have no idea what is going on. What am I missing here?</p>
  
  <pre><code>NoMethodError:
  
  undefined method 'container_size_cd' in 'container_weight_limit' factory
  # ./spec/factories/container_weight_limit.rb:5:in `block (2 levels) in 
  &lt;top (required)&gt;'
  # ./spec/factories/container_weight_limit.rb:4:in `block in &lt;top 
  (required)&gt;'
  # ./spec/factories/container_weight_limit.rb:3:in `&lt;top (required)&gt;'
  # ./config/environment.rb:5:in `&lt;top (required)&gt;'
  # ./spec/rails_helper.rb:3:in `require'
  # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
  # ./spec/models/container_weight_limit_spec.rb:3:in `require'
  # ./spec/models/container_weight_limit_spec.rb:3:in `&lt;top (required)&gt;'
  
  
  
  An error occurred while loading 
  ./spec/models/logistic_process_cost_per_product_spec.rb.
  Failure/Error: require File.expand_path('../../config/environment', 
  __FILE__)
  
  FrozenError:
   can't modify frozen Array
  # ./config/environment.rb:5:in `&lt;top (required)&gt;'
  # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
  # ./spec/models/logistic_process_cost_per_product_spec.rb:3:in 
  `&lt;top          
  (required)&gt;'
  
   An error occurred while loading         
   ./spec/models/logistic_process_cost_spec.rb.
   Failure/Error: require 
   File.expand_path('../../config/environment', 
   __FILE__)
  
   FrozenError:
   can't modify frozen Array
   # ./config/environment.rb:5:in `&lt;top (required)&gt;'
   # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
   # ./spec/models/logistic_process_cost_spec.rb:3:in `&lt;top 
   (required)&gt;'
  
   An error occurred while loading 
   ./spec/models/product_freight_spec.rb.
   Failure/Error: require 
   File.expand_path('../../config/environment', 
   __FILE__)
  
   FrozenError:
   can't modify frozen Array
   # ./config/environment.rb:5:in `&lt;top (required)&gt;'
   # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
   # ./spec/models/product_freight_spec.rb:3:in `&lt;top (required)&gt;'
  
   An error occurred while loading ./spec/models/product_spec.rb.
   Failure/Error: require 
   File.expand_path('../../config/environment', 
   __FILE__)
  
   FrozenError:
   can't modify frozen Array
   # ./config/environment.rb:5:in `&lt;top (required)&gt;'
   # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
   # ./spec/models/product_spec.rb:3:in `&lt;top (required)&gt;'
  
   An error occurred while loading ./spec/models/user_spec.rb.
   Failure/Error: require 
   File.expand_path('../../config/environment', 
   __FILE__)
  
   FrozenError:
   can't modify frozen Array
   # ./config/environment.rb:5:in `&lt;top (required)&gt;'
   # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
   # ./spec/models/user_spec.rb:3:in `&lt;top (required)&gt;'
  
   An error occurred while loading 
   ./spec/services/karavel_currency_service_spec.rb.
  Failure/Error: require File.expand_path('../../config/environment', 
  __FILE__)
  
  FrozenError:
  can't modify frozen Array
  # ./config/environment.rb:5:in `&lt;top (required)&gt;'
  # ./spec/rails_helper.rb:3:in `&lt;top (required)&gt;'
  # ./spec/services/karavel_currency_service_spec.rb:3:in `&lt;top (required)&gt;'
  No examples found.
  
  Finished in 0.00035 seconds (files took 7.28 seconds to load)
  0 examples, 0 failures, 7 errors occurred outside of examples
  </code></pre>
  
  <p>/spec/factories/container_weight_limit.rb</p>
  
  <pre><code># frozen_string_literal: true
  
  FactoryBot.define do
   factory :container_weight_limit do
     container_size_cd 0
     bulk 22
     bag_25kg 25
     bag_50kg 25
     bigbag_900kg 26
     bigbag_1100kg 26
   end
  end
  </code></pre>
  
  <p>config/environment.rb</p>
  
  <pre><code> # Load the Rails application.
   require_relative 'application'
  
   # Initialize the Rails application.
   Rails.application.initialize!
  
   ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html_tag.html_safe
   end
  </code></pre>