hybridgroup.gobot/robot_test.go

59 lines
1.6 KiB
Go
Raw Normal View History

2013-12-02 14:16:02 +08:00
package gobot
import (
2013-12-03 09:10:36 +08:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
2013-12-02 14:16:02 +08:00
)
var _ = Describe("Robot", func() {
2013-12-03 09:10:36 +08:00
var (
someRobot Robot
)
2013-12-02 14:16:02 +08:00
2013-12-03 09:10:36 +08:00
BeforeEach(func() {
2014-01-01 05:16:25 +08:00
someRobot = newTestRobot("")
2013-12-03 09:10:36 +08:00
})
2013-12-02 14:16:02 +08:00
2013-12-03 09:10:36 +08:00
Context("when valid", func() {
It("initName should not change name when already set", func() {
someRobot.Name = "Bumblebee"
someRobot.initName()
Expect(someRobot.Name).To(Equal("Bumblebee"))
})
It("initName should set random name when not set", func() {
someRobot.initName()
Expect(someRobot.Name).NotTo(BeNil())
Expect(someRobot.Name).NotTo(Equal("Bumblebee"))
})
2013-12-31 08:51:21 +08:00
It("initCommands should set RobotCommands equal to Commands Key", func() {
someRobot.initCommands()
Expect(someRobot.RobotCommands).To(Equal([]string{"Command1", "Command2"}))
2013-12-03 09:10:36 +08:00
})
2013-12-31 08:51:21 +08:00
It("GetDevices should return robot devices", func() {
someRobot.initDevices()
Expect(someRobot.GetDevices).NotTo(BeNil())
2013-12-03 09:10:36 +08:00
})
2013-12-31 08:51:21 +08:00
It("GetDevice should return a robot device", func() {
someRobot.initDevices()
Expect(someRobot.GetDevice("Device 1").Name).To(Equal("Device 1"))
2013-12-03 09:10:36 +08:00
})
2013-12-31 08:51:21 +08:00
It("initConnections should initialize connections", func() {
someRobot.initConnections()
Expect(len(someRobot.connections)).To(Equal(3))
2013-12-03 09:10:36 +08:00
})
2013-12-31 08:51:21 +08:00
It("initDevices should initialize devices", func() {
someRobot.initDevices()
Expect(len(someRobot.devices)).To(Equal(3))
2013-12-03 09:10:36 +08:00
})
2013-12-31 08:51:21 +08:00
It("startConnections should connect all connections", func() {
someRobot.initConnections()
Expect(someRobot.startConnections()).To(Equal(true))
2013-12-03 09:10:36 +08:00
})
2013-12-31 08:51:21 +08:00
It("startDevices should start all devices", func() {
someRobot.initDevices()
Expect(someRobot.startDevices()).To(Equal(true))
2013-12-03 09:10:36 +08:00
})
})
2013-12-02 14:16:02 +08:00
})