Topic: flexmock gotcha - multiple class mocks per test suite
I have a test suite that mocks a class method in multiple test methods using flexmock. Unfortunately, class methods appear to have a mock-once-per-environment-load limitation. Meaning, when I run a test in isolation it works, but when I run it as part of a suite of tests one of the tests with the mocked class method will fail. Which test fails depends on alphabetical order within the tests file.
So at its base I have three tests, all mocking the same class method with different return values. This happens to be a helper unit test. I've stripped things down for readability.
flexmock(Project, :accessible? => false)
flexmock(Project, :accessible? => true)
assert ! locked
So in this case, when running all tests in the file, the second test executes last and fails. Project.accessible? returns false due to the mock that was created in the first test, which executed prior.
Is there a way to reset mocking or force a mock of a mock? Nothing stands out to me in the doc.