Cursor rule
.cursor/rules/testing.mdc[object Object]
Cursor rules
Quality
52/100
Scores the file, not the repository.Length
429 words
0 headings · 2 code blocksRepository
9.3k
— · pushed 0 days agoLast changed
2 days ago
First indexed 2 days ago.123456Use this rule to learn how to write tests for the codebase.78Due to the open-source nature of this project, we have chosen Minitest + Fixtures for testing to maximize familiarity and predictability.910- **General testing rules**11 - Always use Minitest and fixtures for testing, NEVER rspec or factories12 - Keep fixtures to a minimum. Most models should have 2-3 fixtures maximum that represent the "base cases" for that model. "Edge cases" should be created on the fly, within the context of the test which it is needed.13 - For tests that require a large number of fixture records to be created, use Rails helpers to help create the records needed for the test, then inline the creation. For example, [entries_test_helper.rb](mdc:test/support/entries_test_helper.rb) provides helpers to easily do this.1415- **Write minimal, effective tests**16 - Use system tests sparingly as they increase the time to complete the test suite17 - Only write tests for critical and important code paths18 - Write tests as you go, when required19 - Take a practical approach to testing. Tests are effective when their presence _significantly increases confidence in the codebase_.2021 Below are examples of necessary vs. unnecessary tests:2223```rb24 # GOOD!!25 # Necessary test - in this case, we're testing critical domain business logic26 test "syncs balances" do27 Holding::Syncer.any_instance.expects(:sync_holdings).returns([]).once2829 @account.expects(:start_date).returns(2.days.ago.to_date)3031 Balance::ForwardCalculator.any_instance.expects(:calculate).returns(32 [33 Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),34 Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")35 ]36 )3738 assert_difference "@account.balances.count", 2 do39 Balance::Syncer.new(@account, strategy: :forward).sync_balances40 end41 end4243 # BAD!!44 # Unnecessary test - in this case, this is simply testing ActiveRecord's functionality45 test "saves balance" do46 balance_record = Balance.new(balance: 100, currency: "USD")4748 assert balance_record.save49 end50```5152- **Test boundaries correctly**53 - Distinguish between commands and query methods. Test output of query methods; test that commands were called with the correct params. See an example below:5455```rb56 class ExampleClass57 def do_something58 result = 2 + 25960 CustomEventProcessor.process_result(result)6162 result63 end64 end6566 class ExampleClass < ActiveSupport::TestCase67 test "boundaries are tested correctly" do68 result = ExampleClass.new.do_something6970 # GOOD - we're only testing that the command was received, not internal implementation details71 # The actual tests for CustomEventProcessor belong in a different test suite!72 CustomEventProcessor.expects(:process_result).with(4).once7374 # GOOD - we're testing the implementation of ExampleClass inside its own test suite75 assert_equal 4, result76 end77 end78```7980 - Never test the implementation details of one class in another classes test suite8182- **Stubs and mocks**83 - Use `mocha` gem84 - Always prefer `OpenStruct` when creating mock instances, or in complex cases, a mock class85 - Only mock what's necessary. If you're not testing return values, don't mock a return value.8687
Also in we-promise/sure
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| we-promise/sure.cursor/rules/api-endpoint-consistency.mdc · 9.3k | Cursor rules | styletesting-strategygitsecurity+2 | 57/100 | 2 days ago | |
| we-promise/sure.cursor/rules/cursor_rules.mdc · 9.3k | Cursor rules | no sections | 36/100 | 2 days ago | |
| we-promise/sure.cursor/rules/general-rules.mdc · 9.3k | Cursor rules | styledo-not | 44/100 | 2 days ago | |
| we-promise/sure.cursor/rules/project-conventions.mdc · 9.3k | Cursor rules | styledependenciesdatabaseui+2 | 59/100 | 2 days ago | |
| we-promise/sure.cursor/rules/project-design.mdc · 9.3k | Cursor rules | style | 58/100 | 2 days ago | |
| we-promise/sure.cursor/rules/self_improve.mdc · 9.3k | Cursor rules | no sections | 36/100 | 2 days ago | |
| we-promise/sure.cursor/rules/stimulus_conventions.mdc · 9.3k | Cursor rules | no sections | 44/100 | 2 days ago | |
| we-promise/sure.cursor/rules/ui-ux-design-guidelines.mdc · 9.3k | Cursor rules | styledo-not | 49/100 | 2 days ago | |
| we-promise/sure.cursor/rules/view_conventions.mdc · 9.3k | Cursor rules | style | 52/100 | 2 days ago | |
| we-promise/sure.github/copilot-instructions.md · 9.3k | Copilot instructions | setuptestlint-formatstyle+10 | 88/100 | 2 days ago | |
| we-promise/sureAGENTS.md · 9.3k | AGENTS.md | buildtestlint-formatstyle+7 | 78/100 | 2 days ago | |
| we-promise/sureCLAUDE.md · 9.3k | CLAUDE.md | setuptestlint-formatstyle+11 | 93/100 | 2 days ago |
Diff against .cursor/rules/api-endpoint-consistency.mdc Diff against .cursor/rules/cursor_rules.mdc Diff against .cursor/rules/general-rules.mdc Diff against .cursor/rules/project-conventions.mdc Diff against .cursor/rules/project-design.mdc Diff against .cursor/rules/self_improve.mdc Diff against .cursor/rules/stimulus_conventions.mdc Diff against .cursor/rules/ui-ux-design-guidelines.mdc Diff against .cursor/rules/view_conventions.mdc Diff against .github/copilot-instructions.md Diff against AGENTS.md Diff against CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/proto.mdc · 126 | Cursor rules | buildlint-formatstylearch+3 | 96/100 | 3 days ago | |
| nerds-odd-e/doughnut.cursor/rules/cli.mdc · 49 | Cursor rules | setupbuildteststyle+4 | 96/100 | 3 days ago | |
| K-Mistele/opensearch.cursor/rules/default.mdc · 30 | Cursor rules | buildtestlint-formatstyle+2 | 94/100 | 3 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/task-context-loading.mdc · 126 | Cursor rules | archtypesdatabasedo-not+1 | 93/100 | 3 days ago |
