Describe("Turning light off", func() { BeforeEach(func() { u, err := url.Parse("/?state=off") Expect(err).ShouldNot(HaveOccurred()) dummyRequest.URL = u expectedLightState.StateKnown = true expectedLightState.LightOn = false expectedReturn, err = json.Marshal(expectedLightState) Expect(err).NotTo(HaveOccurred()) }) Context("When turning off light command returns with error", func() { BeforeEach(func() { expectedError := errors.New(fmt.Sprintf("gpio write error")) fakeGpio.WriteLowReturns(expectedError) expectedLightState.StateKnown = false expectedLightState.LightOn = false expectedLightState.ErrorMsg = expectedError.Error() expectedReturn, err = json.Marshal(expectedLightState) Expect(err).NotTo(HaveOccurred()) }) It("Should write low to light pin", func() { lh.HandleSet(fakeResponseWriter, dummyRequest) Expect(fakeGpio.WriteLowCallCount()).To(Equal(1)) actualGpioPin := fakeGpio.WriteLowArgsForCall(0) Expect(actualGpioPin).To(Equal(gpioLightPin))