...
Exercise boundary conditions, error handling, and varying inputs at the unit or functional level.
Integration specs tests should demonstrate user-visible system behavior.
Remember that integration tests run much more slowly than unit tests, so prefer to test more thoroughly at the unit level.
Integration tests should be placed in the "spec/features/" folder. All other tests should go in the default locations generated by Rails (e.g. "spec/models/")
...
The chain of RSpec Jest "describe" and " context" blocks leading up to the final "ittest" block should form a human-readable sentence. This is particularly true for integration specs where we are documenting system behavior spec names.
Consider an example where we don't use this style.
Bad Example:
describe "('Account creation" do', () => {
…
context "messages" dodescribe('messages', () => {
…
it "test('should display success messages"', () => { … })
it "test('should display failure messages"', () => { … })
end})
it "test('recovers passwords"', () => { … }
it "test('should send emails to users"', () => { … }
end})
Consider the sentences produced by the above:
The spec test fails to describe the system. Reading the sentences, we don't know why a particular behavior might happen. Some of the sentences don't entirely make sense.
We fix the problem by using more descriptive contexts and paying attention to the sentences we're constructing with our specstests.
Improved Example:
describe ("Account creation" do
…
context "describe('for users providing valid information" do', () => {
it "test('displays a success message"', () => { … }
it "test('sends an email to the user"', () => { … }
end})
context "describe('for users providing duplicate user names" do', () => {
it "test('displays an informative error message"', () => { … }
it "test('prompts users to recover their passwords"', () => { … }
end})
end})
Consider the sentences produced by the above:
...
...
If you see a failure and you suspect it was caused by some intermittent problem, e.g. a timeout that is too short or an external service being down, it is not enough to simply re-run the tests. Fix the problem. If a problem truly cannot be fixed, document why, catch the specific error that cannot be fixed, and throw a more meaningful one.
the Pattern Portfolio
Factor non-trivial HTML into partials and helpers and demonstrate its use in the Pattern Portfolio. This allows other developers to find and reuse partials and ensure that new code does not break existing code.
Catalog custom Javascript components in the Pattern Portfolio. Show examples of configuration options, if appropriate.
Create offline pages, similar to the Pattern Portfolio, to exercise Javascript components in their various states. Avoid requiring a running application instance or performing server communication in Jasmine specs.
Integration specs should still perform simple checks on Javascript components, but the bulk of Javascript testing should be performed offline.
...