user2272408
user2272408

Reputation: 71

Rspec tests fail when run in a certain order

Let's say I have two test files. File_A_spec.rb and File_B_spec.rb. When the tests in File_A run before the tests in File_B everything passes. But when tests in File_B run before File_A then tests in File_A fail.

Both files are request specs. The tests in File_A and File_B are unrelated and should have no dependencies. What could be causing this?

Upvotes: 1

Views: 301

Answers (2)

user2272408
user2272408

Reputation: 71

Fixed. The error the failing tests were returning was "undefined method 'locked'."

There was a scope named 'locked' in one of the models and I guess ActiveRecord did not like this. Similar to what was happening here: https://github.com/rails/rails/issues/7421

The scope was renamed and now everything is passing.

Upvotes: 1

John Hinnegan
John Hinnegan

Reputation: 5962

You most likely have static variables or before :all clauses.

Note that before :all actions don't get cleaned up. You're expected to clean them up in after :all

Upvotes: 0

Related Questions