Skip to content

Commit

Permalink
Fixed the tests. Now passing!
Browse files Browse the repository at this point in the history
  • Loading branch information
codegangsta authored and zankich committed Apr 29, 2014
1 parent eb2dff6 commit 43d5a7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
10 changes: 7 additions & 3 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ type Robot struct {
Work func() `json:"-"`
connections []*connection `json:"-"`
devices []*device `json:"-"`
master *Master `json:"-"`
}

func (r *Robot) Start() {
m := NewMaster()
m.Robots = []*Robot{r}
m.Start()
if r.master == nil {
r.master = NewMaster()
}

r.master.Robots = []*Robot{r}
r.master.Start()
}

func (r *Robot) startRobot() {
Expand Down
23 changes: 12 additions & 11 deletions robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,39 @@ import (
var _ = Describe("Robot", func() {

var (
someRobot *Robot
r *Robot
)

Context("when valid", func() {
BeforeEach(func() {
someRobot = newTestRobot("")
trap = func(c chan os.Signal) {
r = newTestRobot("")
r.master = NewMaster()
r.master.trap = func(c chan os.Signal) {
c <- os.Interrupt
}
someRobot.Start()
r.Start()
})

It("should set random name when not set", func() {
Expect(someRobot.Name).NotTo(BeNil())
Expect(r.Name).NotTo(BeNil())
})
It("GetDevice should return nil if device doesn't exist", func() {
Expect(someRobot.GetDevice("Device 4")).To(BeNil())
Expect(r.GetDevice("Device 4")).To(BeNil())
})
It("GetDevice should return device", func() {
Expect(someRobot.GetDevice("Device 1").Name).To(Equal("Device 1"))
Expect(r.GetDevice("Device 1").Name).To(Equal("Device 1"))
})
It("GetDevices should return devices", func() {
Expect(len(someRobot.GetDevices())).To(Equal(3))
Expect(len(r.GetDevices())).To(Equal(3))
})
It("GetConnection should return nil if connection doesn't exist", func() {
Expect(someRobot.GetConnection("Connection 4")).To(BeNil())
Expect(r.GetConnection("Connection 4")).To(BeNil())
})
It("GetConnection should return connection", func() {
Expect(someRobot.GetConnection("Connection 1").Name).To(Equal("Connection 1"))
Expect(r.GetConnection("Connection 1").Name).To(Equal("Connection 1"))
})
It("GetConnections should return connections", func() {
Expect(len(someRobot.GetConnections())).To(Equal(3))
Expect(len(r.GetConnections())).To(Equal(3))
})
})
})

0 comments on commit 43d5a7c

Please sign in to comment.