aboutsummaryrefslogtreecommitdiffstats
path: root/src/exercises/exercises_suite_test.go
blob: c916326566625bb3471efdf936f3b526efbc740a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package exercises_test

import (
	"os"
	"testing"

	"github.com/mauricioabreu/golings/src/exercises"
	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

func TestExercises(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Exercises Suite")
}

var _ = Describe("Exercises", func() {
	Describe("Checking exercise state", func() {
		When("'I AM NOT DONE' comment is still there", func() {
			It("has the Pending state", func() {
				file, err := os.CreateTemp("/tmp", "exercise*.go")
				file.Write([]byte(`// exercise1.go
				// I AM NOT DONE
				package main

				func main() {

				}
				`))
				Expect(err).To(BeNil())

				defer os.Remove(file.Name())

				ex := exercises.Exercise{Path: file.Name()}

				Expect(ex.State()).To(Equal(exercises.Pending))
			})
		})

		When("'I AM NOT DONE' comment is not there", func() {
			It("has the Done state", func() {
				file, err := os.CreateTemp("/tmp", "exercise*.go")
				Expect(err).To(BeNil())

				defer os.Remove(file.Name())

				ex := exercises.Exercise{Path: file.Name()}

				Expect(ex.State()).To(Equal(exercises.Done))
			})
		})
	})
})