Full stack testing
or: How to ensure a proper conversation with your Rails API
"Ordinary" Tests
- Run within the same process as the server and therefore "see" things an ordinary client would not
-
But we need to test external behaviour, not internals
- Run in a Database Transaction and are rolled back before any actual database storage is done
-
Since we need to test from another process, we cannot use these transactions (other processes don't see the data)
- Allow stubbing and mocking
-
We need to check the actual behaviour, not an isolated unit - mocking and stubbing is not allowed
Data-synching
We cannot use the default Unit Testing strategies.
Instead, we use DatabaseCleaner and configure it to truncate all our tables after each test.
Data-synching (2)
Then, we just store stuff in the database from our tests.
Authentication
Baked authentication into our testing "framework" => move complex setup away from tests themselves
Result
Pro-tip
Make descriptions match your documentation