You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're migrating from Rails 4 to Rails 5 and we're having a problem when running the whole spec suite.
When I run rspec using the rspec (without arguments) command I randomly get LoadError: Unable to autoload constant Importer::Transformer, expected [rails_dir]/lib/importer/transformer.rb to define it
Of course, /lib/importer/transformer.rbdoes define it
For example, I get this error (sometimes) when running the whole suite LoadError: Unable to autoload constant Importer::Exceptions, expected [rails_dir]/lib/importer/exceptions.rb to define it # ./spec/transforms/any_to_ton_transform_spec.rb:76:inblock (2 levels) in <top (required)>'`
But if I then run rspec spec/transforms/any_to_ton_transform_spec.rb specifically all tests pass and there is no LoadError, so it seems something is up with the autoloader if I run the whole suite but not a single spec file. Am I doing something wrong in my spec_helper or rails_helper or is something else going on?
I have tried to add any relevant information in this post and I'm curious if anyone else has this problem or whether I did something to cause this? Any help would be appreciated, thanks :)
classAnyToTonTransformdefself.execute(value)returnvalueifvalue.is_a?(Numeric) || value.nil?value=value.gsub('.','')if%w(,.).all?{ |c| value.include?c}BigDecimal.new(value.gsub(',','.'))rescueraiseImporter::Exceptions::TransformError,'value could not be converted into number'endend
Honestly I'm not sure theres much we can do to help with this, the Rails autoloader is notorious for producing odd issues like this, but I can suggest a few things that might work as a work around:
try eager loading in the test environment (e.g. like production) so it loads things earlier on (or hopefully at least consistently?)
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
$ rails -v
Rails 5.0.0
$ rspec -v
3.5.1
We're migrating from Rails 4 to Rails 5 and we're having a problem when running the whole spec suite.
When I run rspec using the
rspec
(without arguments) command I randomly getLoadError: Unable to autoload constant Importer::Transformer, expected [rails_dir]/lib/importer/transformer.rb to define it
Of course,
/lib/importer/transformer.rb
does define itFor example, I get this error (sometimes) when running the whole suite
LoadError: Unable to autoload constant Importer::Exceptions, expected [rails_dir]/lib/importer/exceptions.rb to define it # ./spec/transforms/any_to_ton_transform_spec.rb:76:in
block (2 levels) in <top (required)>'`But if I then run
rspec spec/transforms/any_to_ton_transform_spec.rb
specifically all tests pass and there is no LoadError, so it seems something is up with the autoloader if I run the whole suite but not a single spec file. Am I doing something wrong in my spec_helper or rails_helper or is something else going on?I have tried to add any relevant information in this post and I'm curious if anyone else has this problem or whether I did something to cause this? Any help would be appreciated, thanks :)
spec_helper.rb source
rails_helper.rb source
config/application.rb source
any_to_ton_transform.rb source
any_to_ton_transform_spec.rb source
/lib/importer/exceptions.rb source
The text was updated successfully, but these errors were encountered: