learn-go-with-tests icon indicating copy to clipboard operation
learn-go-with-tests copied to clipboard

context.md assertWasCancelled() and assertWasNotCancelled

Open bodowd opened this issue 3 years ago • 1 comments

Hello, Not sure if I'm simply misunderstanding the following. The text reads:

type SpyStore struct {
	response  string
	cancelled bool
	t         *testing.T
}

func (s *SpyStore) assertWasCancelled() {
	s.t.Helper()
	if !s.cancelled {
		s.t.Error("store was not told to cancel")
	}
}

func (s *SpyStore) assertWasNotCancelled() {
	s.t.Helper()
	if s.cancelled {
		s.t.Error("store was told to cancel")
	}
}

Should the Errors be reversed? In the text, it seems like it is saying "if not cancelled, throw an error because the store was not told to cancel". Is it intended to say: "if not cancelled, throw an error because the store was told to cancel"?

type SpyStore struct {
	response  string
	cancelled bool
	t         *testing.T
}

func (s *SpyStore) assertWasCancelled() {
	s.t.Helper()
	if !s.cancelled {
		s.t.Error("store was told to cancel")
	}
}

func (s *SpyStore) assertWasNotCancelled() {
	s.t.Helper()
	if s.cancelled {
		s.t.Error("store was not told to cancel")
	}
}

Thanks for your time

bodowd avatar Dec 11 '22 07:12 bodowd

I don't think so? If I have assertWasCancelled in my test, and it didn't, I'd expect to see store was not told to cancel

quii avatar Mar 03 '23 07:03 quii