uninitialized constant ActionView::TestCase::Behavior with rspec

Viewed 1474

In rails 5.2.1.1 when running rspec spec/services, I get the following error for each file in spec/services:

NameError:
#   uninitialized constant ActionView::TestCase::Behavior

In view of this discussion I checked for something strange in my helper, but can find nothing to cause this. How do I fix this?

2 Answers

I had a bunch of the same errors (uninitialized constant ActionView::TestCase::Behavior) pop up at random when I changed an else … if block to an elsif inside a helper; turned out all I'd done was forget to delete the matching end.

So for anyone else coming across this, it could easily be a case of a syntax error that just happens to be in a helper.

It turned out that the issue was caused by using 'loaded' as a category in an enum. I found this by running an individual file in the spec/services folder, and instead of the ActionView::TestCase::Behavior error I get the following error:

You tried to define an enum named "status" on the model "User", but this will generate a class method "loaded", which is already defined by ActiveRecord::Relation.

The enum declaration was

enum status: [:not_loaded, :loaded, :loading, :paused]

By changing :loaded to something else all the tests in rspec/services passed other than those that actually used :loaded.

Related