Przejdź do treści
Biblioteka skilli
Programowanie · Nauka i wyjaśnianie

overview

/overview

Wyjaśnia zasady pisania asercji w bibliotece Gomega dla Go i wskazuje, którego skilla gomega użyć dalej.

Repozytorium
gomega ↗
Licencja
MIT
Ostatnia zmiana repozytorium
09.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 09.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Wyjaśnia zasady pisania asercji w bibliotece Gomega dla Go i wskazuje, którego skilla gomega użyć dalej.

Oryginalny opis (EN)

The Gomega mental model for writing assertions in Go — the Expect/Ω notation, matchers-are-values, the multi-return error idiom, synchronous vs asynchronous (Eventually/Consistently) assertions, and a map of the whole library including the gstruct/ghttp/gexec/gbytes/gleak/gmeasure sub-libraries. Use this first when you start writing or reviewing Gomega assertions, or to decide which gomega:* skill to reach for. Routes to every other gomega:* skill.

Jak działa

  1. The shape of every assertion
  2. Three things to internalize
  3. Pick the most specific matcher
  4. Where to go next
Sekcje z nagłówków SKILL.md, w oryginale · 62 linii, 505 słów
Podgląd SKILL.md
---
name: overview
description: The Gomega mental model for writing assertions in Go — the Expect/Ω notation, matchers-are-values, the multi-return error idiom, synchronous vs asynchronous (Eventually/Consistently) assertions, and a map of the whole library including the gstruct/ghttp/gexec/gbytes/gleak/gmeasure sub-libraries. Use this first when you start writing or reviewing Gomega assertions, or to decide which gomega:* skill to reach for. Routes to every other gomega:* skill.
---

# Gomega: the mental model

Gomega is a matcher/assertion library for Go. It pairs best with the [Ginkgo](https://github.com/onsi/ginkgo) test framework but works with any Go test. The canonical narrative docs at <https://onsi.github.io/gomega/> are the source of truth; this skill is the orientation and the other skills go deep.

Conventionally you **dot-import** Gomega so `Expect`, `Equal`, `Eventually`, etc. are unqualified:

```go
import (
	. "github.com/onsi/gomega"
	. "github.com/onsi/ginkgo/v2" // if using Ginkgo
)
```

## The shape of every assertion

```go
Expect(ACTUAL).To(MATCHER)        //  Expect(x).To(Equal(3))
Expect(ACTUAL).NotTo(MATCHER)
```

- **`ACTUAL`** (left) is anything — the value under test.
- **`MATCHER`** (right) must satisfy the `GomegaMatcher` interface. Gomega's matchers (`Equal(3)`, `HaveLen(2)`, …) are just **functions that return a matcher value** — so you can store, pass, and compose them. → `gomega:matchers`, `gomega:composing-matchers`.
- `Ω(ACTUAL).Should(MATCHER)` / `.ShouldNot(...)` is the **exact equivalent** in the `Ω` notation (`⌥z` on macOS). `To`/`Should` and `NotTo`/`ToNot`/`ShouldNot` are interchangeable syntactic sugar — pick one notation and stay consistent.

## Three things to internalize

**1. The multi-return error idiom.** `Expect`/`Ω` accept *multiple* arguments; the match runs against the first, and **fails unless all later arguments are nil/zero**. This collapses Go's `(value, error)` pattern:

```go
Expect(DoSomethingHard()).To(Equal("foo"))   // passes only if return is ("foo", nil)
Expect(DoSomethingSimple()).To(Succeed())     // for funcs returning only error
```
Use `.Error()` to assert on the trailing error of a multi-return func while ignoring the rest. → `gomega:assertions`.

**2. Failures go through a fail handler.** Gomega calls a registered handler on failure. With Ginkgo, `RegisterFailHandler(Fail)` (auto-generated by `ginkgo bootstrap`). With plain `testing`, use `g := NewWithT(t)` and call `g.Expect(...)`. → `gomega:assertions`.

**3. Synchronous vs asynchronous.** `Expect` asserts *now*. `Eventually`/`Consistently` **poll** a value, function, or `g Gomega` callback until a matcher passes (or keeps passing). Async is its own world with timeouts, contexts, and bail-out signals. → `gomega:async`.

## Pick the most specific matcher

The single biggest quality lever: prefer the matcher that says what you mean. `Expect(err).To(MatchError(...))` over `Expect(err.Error()).To(Equal(...))`; `Expect(xs).To(ConsistOf(...))` over `Expect(len(xs)).To(Equal(3))`. Specific matchers produce far better failure messages. Browse the full catalog before reaching for `Equal` — Gomega has a deep, expressive matcher library. → `gomega:matchers`.

## Where to go next

**Core mechanics**
- **Synchronous assertions** — `Expect`/`Ω`, error handling, `Succeed`/`HaveOccurred`, negation, annotations, output tuning, asserting inside helpers → `gomega:assertions`
- **Asynchronous assertions** — `Eventually`/`Consistently`, polling functions & `g Gomega` callbacks, contexts, timeouts, `StopTrying`/`TryAgainAfter` → `gomega:async`

**Matchers**
- **The full catalog** (terse, grouped — start here to discover matchers) → `gomega:matchers`
- **Composing** — `And`/`Or`/`Not`, `SatisfyAll`/`SatisfyAny`, `WithTransform`, `HaveField`, `HaveValue` → `gomega:composing-matchers`
- **Writing your own** — the `GomegaMatcher` interface and `gcustom` → `gomega:custom-matchers`

**Sub-libraries** (each its own import; reach for them by task)
- **`gstruct`** — deep, partial matching of nested structs, slices, and maps → `gomega:gstruct`
- **`ghttp`** — a test server for asserting on and stubbing HTTP clients → `gomega:ghttp`
- **`gexec`** — build, run, signal, and assert on external processes → `gomega:gexec`
- **`gbytes`** — assert on streaming `io` buffers with the `Say` matcher → `gomega:gbytes`
- **`gleak`** — detect leaked goroutines → `gomega:gleak`
- **`gmeasure`** — benchmark and measure code → `gomega:gmeasure`

Wersje

RepozytoriumWynikLicencja
Ta strona · onsi/gomega100MIT
8beeeaaat/touchdesigner-mcp100MIT
chrishuffman5/domain-expert100MIT
chrishuffman5/domain-expert100MIT
chrishuffman5/domain-expert100MIT
chrishuffman5/domain-expert100MIT
chrishuffman5/domain-expert100MIT
chrishuffman5/domain-expert100MIT
chrishuffman5/domain-expert100MIT

Migawka bazy z 28.10.2026 · wersja paczki a40ce39f601c (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95assertions
    Pisze poprawne asercje Gomega w Go: notację Expect, obsługę błędów, opisy i czytelne komunikaty awarii.
  • 100async
    Opisuje asercje odpytujące w Gomega: Eventually i Consistently, idiom func(g Gomega), limity czasu i interwały, kontekst Ginkgo, StopTrying oraz MustPassRepeatedly dla goroutines, kanałów i spójności ostatecznej.
  • 100timeouts-and-async
    Pomaga testować asynchroniczność w Ginkgo: przerywalne specy, limity czasu, Eventually i Consistently oraz obsługę goroutin.
  • 100mocha-assertions
    Opisuje biblioteki asercji dla Mocha, w tym Chai w stylach expect, should i assert.
  • 87write-tests
    Pisze specyfikacje testów w Go Ginkgo i Gomega z Biloba, łącząc działania natychmiastowe z oczekiwaniem na stan strony.
  • 100setup
    Podłącza Ginkgo do pakietu Go: instaluje CLI i Gomega, generuje plik zestawu testów i integruje go z testami w stylu *testing.T.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.