context = &fakes.Context{} linkFactory = &fakes.LinkFactory{} context.LinkFactoryReturns(linkFactory) setLinkMaster = commands.SetLinkMaster{ Master: "master-dev", Slave: "slave-dev", } }) It("assigns a master to the slave", func() { err := setLinkMaster.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(linkFactory.SetMasterCallCount()).To(Equal(1)) slave, master := linkFactory.SetMasterArgsForCall(0) Expect(slave).To(Equal("slave-dev")) Expect(master).To(Equal("master-dev")) }) Context("when the master setter fails", func() { BeforeEach(func() { linkFactory.SetMasterReturns(errors.New("you're not a slave")) }) It("wraps and propogates the error", func() { err := setLinkMaster.Execute(context) Expect(err).To(MatchError("set link master: you're not a slave")) }) })