hacky_hal 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/hacky_hal.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "hacky_hal"
5
- gem.version = "0.2.4"
5
+ gem.version = "0.2.5"
6
6
 
7
7
  gem.authors = ["Nick Ewing"]
8
8
  gem.email = ["nick@nickewing.net"]
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(/^spec/)
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.license = 'MIT'
21
+ gem.license = "MIT"
22
22
  end
@@ -78,11 +78,11 @@ module HackyHAL
78
78
  @model = options[:model]
79
79
  end
80
80
 
81
- def on
81
+ def power
82
82
  power_status == :on
83
83
  end
84
84
 
85
- def on=(value)
85
+ def set_power(value)
86
86
  value = value ? "ON" : "OFF"
87
87
  write_command("PWR #{value}")
88
88
  read_command(1)
@@ -109,7 +109,7 @@ module HackyHAL
109
109
  {id: source_id, name: source_name}
110
110
  end
111
111
 
112
- def source=(source_id)
112
+ def set_source(source_id)
113
113
  write_command("SOURCE #{source_id}")
114
114
  read_command(SOURCE_COMMAND_TIMEOUT)
115
115
  end
@@ -124,7 +124,7 @@ module HackyHAL
124
124
  {id: color_mode_id, name: color_mode_name}
125
125
  end
126
126
 
127
- def color_mode=(color_mode_id)
127
+ def set_color_mode(color_mode_id)
128
128
  write_command("CMODE #{color_mode_id}")
129
129
  read_command
130
130
  end
@@ -139,7 +139,7 @@ module HackyHAL
139
139
  {id: aspect_ratio_id, name: aspect_ratio_name}
140
140
  end
141
141
 
142
- def aspect_ratio=(aspect_ratio_id)
142
+ def set_aspect_ratio(aspect_ratio_id)
143
143
  write_command("ASPECT #{aspect_ratio_id}")
144
144
  read_command
145
145
  end
@@ -1,4 +1,4 @@
1
- require 'net/ssh'
1
+ require "net/ssh"
2
2
  require_relative "base"
3
3
 
4
4
  module HackyHAL
@@ -50,7 +50,7 @@ module HackyHAL
50
50
  end
51
51
 
52
52
  def connected?
53
- @ssh && !@ssh.closed?
53
+ !!(@ssh && !@ssh.closed?)
54
54
  end
55
55
 
56
56
  def disconnect
@@ -17,7 +17,7 @@ module HackyHAL
17
17
  super(options)
18
18
  end
19
19
 
20
- def input=(value)
20
+ def set_input(value)
21
21
  unless value.is_a?(Fixnum)
22
22
  raise ArgumentError, "Input value must be an integer."
23
23
  end
@@ -41,7 +41,7 @@ module HackyHAL
41
41
  read_command
42
42
  end
43
43
 
44
- def power_on_detection=(value)
44
+ def set_power_on_detection(value)
45
45
  value = value ? "on" : "off"
46
46
  write_command("pod #{value}")
47
47
  read_command
@@ -104,7 +104,7 @@ module HackyHAL
104
104
  response.elements["YAMAHA_AV/Main_Zone/Input/Input_Sel"].text
105
105
  end
106
106
 
107
- def input=(input_name)
107
+ def set_input(input_name)
108
108
  put_request(%|<Main_Zone><Input><Input_Sel>#{input_name}</Input_Sel></Input></Main_Zone>|)
109
109
  end
110
110
 
@@ -118,12 +118,12 @@ module HackyHAL
118
118
  put_request(%|<System><Sound_Video><HDMI><Output><#{output_name}>#{value}</#{output_name}></Output></HDMI></Sound_Video></System>|)
119
119
  end
120
120
 
121
- def on
121
+ def power
122
122
  response = get_request("<Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone>")
123
123
  response.elements["YAMAHA_AV/Main_Zone/Power_Control/Power"].text == "On"
124
124
  end
125
125
 
126
- def on=(value)
126
+ def set_power(value)
127
127
  value = value ? "On" : "Standby"
128
128
  put_request("<Main_Zone><Power_Control><Power>#{value}</Power></Power_Control></Main_Zone>")
129
129
  end
@@ -133,7 +133,7 @@ module HackyHAL
133
133
  element_volume_value(response.elements["YAMAHA_AV/Main_Zone/Volume/Lvl/Val"])
134
134
  end
135
135
 
136
- def volume=(value)
136
+ def set_volume(value)
137
137
  value = (value * 10.0).to_i.to_s
138
138
  response = put_request("<Main_Zone><Volume><Lvl><Val>#{value}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone>")
139
139
  end
@@ -143,7 +143,7 @@ module HackyHAL
143
143
  element_on?(response.elements["YAMAHA_AV/Main_Zone/Volume/Mute"])
144
144
  end
145
145
 
146
- def mute=(value)
146
+ def set_mute(value)
147
147
  value = case value
148
148
  when true then "On"
149
149
  when false then "Off"
@@ -158,7 +158,7 @@ module HackyHAL
158
158
  response.elements["YAMAHA_AV/Main_Zone/Surround/Program_Sel/Current/Sound_Program"].text
159
159
  end
160
160
 
161
- def sound_program=(program_name)
161
+ def set_sound_program(program_name)
162
162
  response = put_request("<Main_Zone><Surround><Program_Sel><Current><Sound_Program>#{program_name}</Sound_Program></Current></Program_Sel></Surround></Main_Zone>")
163
163
  puts response
164
164
  # response.elements["YAMAHA_AV/Main_Zone/Surround/Program_Sel/Current/Sound_Program"].text
@@ -1,4 +1,5 @@
1
1
  require "singleton"
2
+ require "yaml"
2
3
  require_relative "util"
3
4
 
4
5
  module HackyHAL
@@ -3,13 +3,13 @@ require "hacky_hal/device_controllers/base"
3
3
 
4
4
  describe HackyHAL::DeviceControllers::Base do
5
5
  it "should include Options" do
6
- described_class.ancestors.should include(HackyHAL::Options)
6
+ expect(described_class.ancestors).to include(HackyHAL::Options)
7
7
  end
8
8
 
9
9
  describe "#log" do
10
10
  it "should log to HackyHAL::Log with device name" do
11
11
  controller = described_class.new(name: "dummy device")
12
- HackyHAL::Log.instance.should_receive(:info).with("dummy device: dummy message")
12
+ expect(HackyHAL::Log.instance).to receive(:info).with("dummy device: dummy message")
13
13
  controller.log("dummy message", :info)
14
14
  end
15
15
  end
@@ -4,51 +4,51 @@ require "hacky_hal/device_controllers/generic_serial_port"
4
4
  describe HackyHAL::DeviceControllers::GenericSerialPort do
5
5
  before(:each) do
6
6
  @serial_port = double("serial port")
7
- @serial_port.stub(:read_timeout=)
8
- @serial_port.stub(:baud=)
9
- @serial_port.stub(:data_bits=)
10
- @serial_port.stub(:stop_bits=)
11
- @serial_port.stub(:parity=)
12
- @serial_port.stub(:flow_control=)
7
+ allow(@serial_port).to receive(:read_timeout=)
8
+ allow(@serial_port).to receive(:baud=)
9
+ allow(@serial_port).to receive(:data_bits=)
10
+ allow(@serial_port).to receive(:stop_bits=)
11
+ allow(@serial_port).to receive(:parity=)
12
+ allow(@serial_port).to receive(:flow_control=)
13
13
 
14
14
  @serial_device_path = "/dev/foo0"
15
15
  @generic_serial_port = described_class.new(serial_device_path: @serial_device_path)
16
16
 
17
- SerialPort.stub(:new).and_return(@serial_port)
17
+ allow(SerialPort).to receive(:new).and_return(@serial_port)
18
18
  end
19
19
 
20
20
  describe "#write_command" do
21
21
  before(:each) do
22
- @serial_port.stub(:flush)
22
+ allow(@serial_port).to receive(:flush)
23
23
  end
24
24
 
25
25
  it "should write to the serial port" do
26
- @serial_port.should_receive(:write).with("foobar\r\n")
26
+ expect(@serial_port).to receive(:write).with("foobar\r\n")
27
27
  @generic_serial_port.write_command("foobar")
28
28
  end
29
29
 
30
30
  it "should return true on successful run" do
31
- @serial_port.should_receive(:write)
32
- @generic_serial_port.write_command("foobar").should be_true
31
+ expect(@serial_port).to receive(:write)
32
+ expect(@generic_serial_port.write_command("foobar")).to be true
33
33
  end
34
34
 
35
35
  it "should retry after rescuing from an Errno::EIO" do
36
- @generic_serial_port.should_receive(:disconnect)
36
+ expect(@generic_serial_port).to receive(:disconnect)
37
37
 
38
38
  retries = 0
39
- @serial_port.stub(:write) do
39
+ allow(@serial_port).to receive(:write) do
40
40
  if retries < HackyHAL::DeviceControllers::GenericSerialPort::MAX_READ_WRITE_RETRIES
41
41
  retries += 1
42
42
  raise Errno::EIO
43
43
  end
44
44
  end
45
45
 
46
- @generic_serial_port.write_command("foobar").should be_true
46
+ expect(@generic_serial_port.write_command("foobar")).to be true
47
47
  end
48
48
 
49
49
  it "should raise Errno::EIO if retry failed" do
50
- @serial_port.stub(:write) { raise Errno::EIO }
51
- @serial_port.stub(:close)
50
+ allow(@serial_port).to receive(:write) { raise Errno::EIO }
51
+ allow(@serial_port).to receive(:close)
52
52
 
53
53
  expect {
54
54
  @generic_serial_port.write_command("foobar")
@@ -56,47 +56,47 @@ describe HackyHAL::DeviceControllers::GenericSerialPort do
56
56
  end
57
57
 
58
58
  it "should log debug message" do
59
- @serial_port.stub(:write)
60
- @generic_serial_port.should_receive(:log).with("Wrote: \"foobar\\r\\n\"", :debug)
59
+ allow(@serial_port).to receive(:write)
60
+ expect(@generic_serial_port).to receive(:log).with("Wrote: \"foobar\\r\\n\"", :debug)
61
61
  @generic_serial_port.write_command("foobar")
62
62
  end
63
63
  end
64
64
 
65
65
  describe "#read_command" do
66
66
  it "should return read string on successful run" do
67
- @serial_port.stub(:readline).and_return("a return string")
68
- @generic_serial_port.read_command.should == "a return string"
67
+ allow(@serial_port).to receive(:readline).and_return("a return string")
68
+ expect(@generic_serial_port.read_command).to eq "a return string"
69
69
  end
70
70
 
71
71
  it "should set the serial port read timeout to given value" do
72
- @serial_port.stub(:readline)
73
- @serial_port.should_receive(:read_timeout=).with(12000)
72
+ allow(@serial_port).to receive(:readline)
73
+ expect(@serial_port).to receive(:read_timeout=).with(12000)
74
74
  @generic_serial_port.read_command(12)
75
75
  end
76
76
 
77
77
  it "should call handle_error if error_response?(response) is true" do
78
- @serial_port.stub(:readline)
79
- @generic_serial_port.stub(:error_response?).and_return(true)
80
- @generic_serial_port.should_receive(:handle_error)
78
+ allow(@serial_port).to receive(:readline)
79
+ allow(@generic_serial_port).to receive(:error_response?).and_return(true)
80
+ expect(@generic_serial_port).to receive(:handle_error)
81
81
  @generic_serial_port.read_command
82
82
  end
83
83
 
84
84
  it "should rescue EOFError and return nil" do
85
- @serial_port.stub(:readline) { raise EOFError }
86
- @generic_serial_port.read_command.should be_nil
85
+ allow(@serial_port).to receive(:readline) { raise EOFError }
86
+ expect(@generic_serial_port.read_command).to be nil
87
87
  end
88
88
 
89
89
  it "should rescue EOFError and log warn message" do
90
- @serial_port.stub(:readline) { raise EOFError }
91
- @generic_serial_port.should_receive(:log).with("Read EOFError", :warn)
90
+ allow(@serial_port).to receive(:readline) { raise EOFError }
91
+ expect(@generic_serial_port).to receive(:log).with("Read EOFError", :warn)
92
92
  @generic_serial_port.read_command
93
93
  end
94
94
 
95
95
  it "should retry after rescuing from an Errno::EIO" do
96
- @generic_serial_port.should_receive(:disconnect)
96
+ expect(@generic_serial_port).to receive(:disconnect)
97
97
 
98
98
  retries = 0
99
- @serial_port.stub(:readline) do
99
+ allow(@serial_port).to receive(:readline) do
100
100
  if retries < HackyHAL::DeviceControllers::GenericSerialPort::MAX_READ_WRITE_RETRIES
101
101
  retries += 1
102
102
  raise Errno::EIO
@@ -105,12 +105,12 @@ describe HackyHAL::DeviceControllers::GenericSerialPort do
105
105
  end
106
106
  end
107
107
 
108
- @generic_serial_port.read_command.should == "a return string"
108
+ expect(@generic_serial_port.read_command).to eq "a return string"
109
109
  end
110
110
 
111
111
  it "should raise Errno::EIO if retry failed" do
112
- @serial_port.stub(:readline) { raise Errno::EIO }
113
- @serial_port.stub(:close)
112
+ allow(@serial_port).to receive(:readline) { raise Errno::EIO }
113
+ allow(@serial_port).to receive(:close)
114
114
 
115
115
  expect {
116
116
  @generic_serial_port.read_command
@@ -118,8 +118,8 @@ describe HackyHAL::DeviceControllers::GenericSerialPort do
118
118
  end
119
119
 
120
120
  it "should log debug message" do
121
- @serial_port.stub(:readline).and_return("response")
122
- @generic_serial_port.should_receive(:log).with("Read: \"response\"", :debug)
121
+ allow(@serial_port).to receive(:readline).and_return("response")
122
+ expect(@generic_serial_port).to receive(:log).with("Read: \"response\"", :debug)
123
123
  @generic_serial_port.read_command
124
124
  end
125
125
  end
@@ -127,41 +127,41 @@ describe HackyHAL::DeviceControllers::GenericSerialPort do
127
127
  describe "#disconnect" do
128
128
  it "should close serial port if serial port is set" do
129
129
  @generic_serial_port.serial_port # make sure serial port is set
130
- @serial_port.should_receive(:close)
130
+ expect(@serial_port).to receive(:close)
131
131
  @generic_serial_port.disconnect
132
132
  end
133
133
 
134
134
  it "should not attempt to close serial port if serial port is not set" do
135
- @generic_serial_port.stub(:serial_port).and_return(nil)
135
+ allow(@generic_serial_port).to receive(:serial_port).and_return(nil)
136
136
  @generic_serial_port.disconnect
137
137
  end
138
138
 
139
139
  it "should set serial_port to nil" do
140
140
  @generic_serial_port.serial_port # make sure serial port is set
141
- @serial_port.should_receive(:close)
141
+ expect(@serial_port).to receive(:close)
142
142
  @generic_serial_port.disconnect
143
- SerialPort.should_receive(:new)
143
+ expect(SerialPort).to receive(:new)
144
144
  @generic_serial_port.serial_port
145
145
  end
146
146
  end
147
147
 
148
148
  describe "#serial_port" do
149
149
  it "should create new SerialPort" do
150
- SerialPort.should_receive(:new).with(@serial_device_path).and_return(@serial_port)
151
- @generic_serial_port.stub(:serial_options).and_return(
150
+ expect(SerialPort).to receive(:new).with(@serial_device_path).and_return(@serial_port)
151
+ allow(@generic_serial_port).to receive(:serial_options).and_return(
152
152
  baud_rate: 50,
153
153
  data_bits: 5,
154
154
  stop_bits: 2,
155
155
  parity: SerialPort::EVEN,
156
156
  flow_control: SerialPort::HARD
157
157
  )
158
- @serial_port.should_receive(:baud=).with(50)
159
- @serial_port.should_receive(:data_bits=).with(5)
160
- @serial_port.should_receive(:stop_bits=).with(2)
161
- @serial_port.should_receive(:parity=).with(SerialPort::EVEN)
162
- @serial_port.should_receive(:flow_control=).with(SerialPort::HARD)
158
+ expect(@serial_port).to receive(:baud=).with(50)
159
+ expect(@serial_port).to receive(:data_bits=).with(5)
160
+ expect(@serial_port).to receive(:stop_bits=).with(2)
161
+ expect(@serial_port).to receive(:parity=).with(SerialPort::EVEN)
162
+ expect(@serial_port).to receive(:flow_control=).with(SerialPort::HARD)
163
163
 
164
- @generic_serial_port.serial_port.should == @serial_port
164
+ expect(@generic_serial_port.serial_port).to eq @serial_port
165
165
  end
166
166
  end
167
167
  end
@@ -22,60 +22,60 @@ describe HackyHAL::DeviceControllers::GenericSsh do
22
22
  )
23
23
 
24
24
  @ssh = double("ssh connection")
25
- @ssh.stub(:exec!).and_yield(nil, nil, "dummy output")
26
- @ssh.stub(:close)
27
- @ssh.stub(:closed?).and_return(false)
28
- Net::SSH.stub(:start).and_return(@ssh)
25
+ allow(@ssh).to receive(:exec!).and_yield(nil, nil, "dummy output")
26
+ allow(@ssh).to receive(:close)
27
+ allow(@ssh).to receive(:closed?).and_return(false)
28
+ allow(Net::SSH).to receive(:start).and_return(@ssh)
29
29
  end
30
30
 
31
31
  describe "#exec" do
32
32
  it "should pass command to ssh.exec!" do
33
- @ssh.should_receive(:exec!).with("dummy_command")
33
+ expect(@ssh).to receive(:exec!).with("dummy_command")
34
34
  @generic_ssh.exec("dummy_command")
35
35
  end
36
36
 
37
37
  it "should connect if not connected" do
38
- @generic_ssh.should_receive(:connected?).and_return(false)
39
- @generic_ssh.should_receive(:connect)
40
- @generic_ssh.stub(:ssh_exec)
41
- @generic_ssh.stub(:disconnect)
38
+ expect(@generic_ssh).to receive(:connected?).and_return(false)
39
+ expect(@generic_ssh).to receive(:connect)
40
+ allow(@generic_ssh).to receive(:ssh_exec)
41
+ allow(@generic_ssh).to receive(:disconnect)
42
42
  @generic_ssh.exec("dummy_command")
43
43
  end
44
44
 
45
45
  it "should not connect if already connected" do
46
- @generic_ssh.should_receive(:connected?).and_return(true)
47
- @generic_ssh.should_not_receive(:connect)
48
- @generic_ssh.stub(:ssh_exec)
49
- @generic_ssh.stub(:disconnect)
46
+ expect(@generic_ssh).to receive(:connected?).and_return(true)
47
+ expect(@generic_ssh).not_to receive(:connect)
48
+ allow(@generic_ssh).to receive(:ssh_exec)
49
+ allow(@generic_ssh).to receive(:disconnect)
50
50
  @generic_ssh.exec("dummy_command")
51
51
  end
52
52
 
53
53
  it "should join output from ssh.exec!" do
54
- @ssh.stub(:exec!).and_yield(nil, nil, "foo").and_yield(nil, nil, "bar")
55
- @generic_ssh.exec("dummy_command").should == "foobar"
54
+ allow(@ssh).to receive(:exec!).and_yield(nil, nil, "foo").and_yield(nil, nil, "bar")
55
+ expect(@generic_ssh.exec("dummy_command")).to eq "foobar"
56
56
  end
57
57
 
58
58
  it "should log debug message" do
59
- @generic_ssh.should_receive(:log).with("Command: \"dummy_command\"", :debug)
60
- @generic_ssh.should_receive(:log).with("Output: \"dummy output\"", :debug)
59
+ expect(@generic_ssh).to receive(:log).with("Command: \"dummy_command\"", :debug)
60
+ expect(@generic_ssh).to receive(:log).with("Output: \"dummy output\"", :debug)
61
61
  @generic_ssh.exec("dummy_command")
62
62
  end
63
63
 
64
64
  describe "on command failure" do
65
65
  before(:each) do
66
- @generic_ssh.stub(:ssh_exec).and_raise(EOFError.new("foo"))
66
+ allow(@generic_ssh).to receive(:ssh_exec).and_raise(EOFError.new("foo"))
67
67
  end
68
68
 
69
69
  it "should log warn message" do
70
- @generic_ssh.should_receive(:log).with("Command: \"dummy_command\"", :debug).twice
71
- @generic_ssh.should_receive(:log).with("Command failed: EOFError - foo", :warn).twice
72
- @generic_ssh.should_receive(:log).with("Retrying last command", :warn).once
70
+ expect(@generic_ssh).to receive(:log).with("Command: \"dummy_command\"", :debug).twice
71
+ expect(@generic_ssh).to receive(:log).with("Command failed: EOFError - foo", :warn).twice
72
+ expect(@generic_ssh).to receive(:log).with("Retrying last command", :warn).once
73
73
  @generic_ssh.exec("dummy_command")
74
74
  end
75
75
 
76
76
  it "should retry once after reconnecting" do
77
- @generic_ssh.should_receive(:disconnect).twice
78
- @generic_ssh.should_receive(:connect).twice
77
+ expect(@generic_ssh).to receive(:disconnect).twice
78
+ expect(@generic_ssh).to receive(:connect).twice
79
79
  @generic_ssh.exec("dummy_command")
80
80
  end
81
81
  end
@@ -84,18 +84,18 @@ describe HackyHAL::DeviceControllers::GenericSsh do
84
84
  describe "#connect" do
85
85
  it "should disconnect if already connected" do
86
86
  @generic_ssh.connect
87
- @generic_ssh.should_receive(:disconnect)
87
+ expect(@generic_ssh).to receive(:disconnect)
88
88
  @generic_ssh.connect
89
89
  end
90
90
 
91
91
  it "should open a new Net:SSH connection" do
92
- Net::SSH.should_receive(:start)
92
+ expect(Net::SSH).to receive(:start)
93
93
  @generic_ssh.connect
94
94
  end
95
95
 
96
96
  it "should log warn message on error" do
97
- Net::SSH.should_receive(:start).and_raise(SocketError.new("dummy message"))
98
- @generic_ssh.should_receive(:log).with("Failed to connect: SocketError - dummy message", :warn)
97
+ expect(Net::SSH).to receive(:start).and_raise(SocketError.new("dummy message"))
98
+ expect(@generic_ssh).to receive(:log).with("Failed to connect: SocketError - dummy message", :warn)
99
99
  @generic_ssh.connect
100
100
  end
101
101
  end
@@ -103,38 +103,38 @@ describe HackyHAL::DeviceControllers::GenericSsh do
103
103
  describe "disconnect" do
104
104
  it "should close the ssh connection if connected" do
105
105
  @generic_ssh.connect
106
- @ssh.should_receive(:close)
107
- @generic_ssh.disconnect.should be_nil
106
+ expect(@ssh).to receive(:close)
107
+ expect(@generic_ssh.disconnect).to be nil
108
108
  end
109
109
 
110
110
  it "should not close the ssh connection if not connected" do
111
- @generic_ssh.should_receive(:connected?).and_return(false)
112
- @ssh.should_not_receive(:close)
113
- @generic_ssh.disconnect.should be_nil
111
+ expect(@generic_ssh).to receive(:connected?).and_return(false)
112
+ expect(@ssh).not_to receive(:close)
113
+ expect(@generic_ssh.disconnect).to be nil
114
114
  end
115
115
 
116
116
  it "should return nil on Net::SSH::Disconnect" do
117
117
  @generic_ssh.connect
118
- @ssh.should_receive(:close).and_raise(Net::SSH::Disconnect)
119
- @generic_ssh.disconnect.should be_nil
118
+ expect(@ssh).to receive(:close).and_raise(Net::SSH::Disconnect)
119
+ expect(@generic_ssh.disconnect).to be nil
120
120
  end
121
121
 
122
122
  it "should still disconnect on Net::SSH::Disconnect" do
123
123
  @generic_ssh.connect
124
- @ssh.should_receive(:close).and_raise(Net::SSH::Disconnect)
124
+ expect(@ssh).to receive(:close).and_raise(Net::SSH::Disconnect)
125
125
  @generic_ssh.disconnect
126
- @generic_ssh.connected?.should be_false
126
+ expect(@generic_ssh.connected?).to be false
127
127
  end
128
128
  end
129
129
 
130
130
  describe "connect?" do
131
131
  it "should return true if connected" do
132
132
  @generic_ssh.connect
133
- @generic_ssh.connected?.should be_true
133
+ expect(@generic_ssh.connected?).to be true
134
134
  end
135
135
 
136
136
  it "should return false if not connected" do
137
- @generic_ssh.connected?.should be_false
137
+ expect(@generic_ssh.connected?).to be false
138
138
  end
139
139
  end
140
140
  end
@@ -19,12 +19,12 @@ describe HackyHAL::DeviceControllers::Roku do
19
19
  # FIXME: identical in YamahaAvReceiver spec
20
20
  it "should resolve host through device resolver" do
21
21
  resolved_uri = double("resolved URI")
22
- resolved_uri.stub(:path=)
23
- resolved_uri.stub(:port=)
22
+ allow(resolved_uri).to receive(:path=)
23
+ allow(resolved_uri).to receive(:port=)
24
24
  device_resolver = double("device resolver")
25
- device_resolver.should_receive(:uri).and_return(resolved_uri)
26
- HackyHAL::DeviceResolvers::Dummy.should_receive(:new).with(foo: 1).and_return(device_resolver)
27
- controller = described_class.new(device_resolver: {type: 'Dummy', foo: 1})
28
- controller.host_uri.should == resolved_uri
25
+ expect(device_resolver).to receive(:uri).and_return(resolved_uri)
26
+ expect(HackyHAL::DeviceResolvers::Dummy).to receive(:new).with(foo: 1).and_return(device_resolver)
27
+ controller = described_class.new(device_resolver: {type: "Dummy", foo: 1})
28
+ expect(controller.host_uri).to eq resolved_uri
29
29
  end
30
30
  end
@@ -18,12 +18,12 @@ describe HackyHAL::DeviceControllers::YamahaAvReceiver do
18
18
 
19
19
  it "should resolve host through device resolver" do
20
20
  resolved_uri = double("resolved URI")
21
- resolved_uri.stub(:path=)
22
- resolved_uri.stub(:port=)
21
+ allow(resolved_uri).to receive(:path=)
22
+ allow(resolved_uri).to receive(:port=)
23
23
  device_resolver = double("device resolver")
24
- device_resolver.should_receive(:uri).and_return(resolved_uri)
25
- HackyHAL::DeviceResolvers::Dummy.should_receive(:new).with(foo: 1).and_return(device_resolver)
26
- controller = described_class.new(device_resolver: {type: 'Dummy', foo: 1})
27
- controller.host_uri.should == resolved_uri
24
+ expect(device_resolver).to receive(:uri).and_return(resolved_uri)
25
+ expect(HackyHAL::DeviceResolvers::Dummy).to receive(:new).with(foo: 1).and_return(device_resolver)
26
+ controller = described_class.new(device_resolver: {type: "Dummy", foo: 1})
27
+ expect(controller.host_uri).to eq resolved_uri
28
28
  end
29
29
  end
@@ -3,6 +3,6 @@ require "hacky_hal/device_resolvers/base"
3
3
 
4
4
  describe HackyHAL::DeviceResolvers::Base do
5
5
  it "should include Options" do
6
- described_class.ancestors.should include(HackyHAL::Options)
6
+ expect(described_class.ancestors).to include(HackyHAL::Options)
7
7
  end
8
8
  end
@@ -11,7 +11,7 @@ describe HackyHAL::DeviceResolvers::SSDP do
11
11
 
12
12
  it "should default to search for root devices" do
13
13
  resolver = described_class.new(usn: "dummy-usn")
14
- resolver.options[:search].should == "upnp:rootdevice"
14
+ expect(resolver.options[:search]).to eq "upnp:rootdevice"
15
15
  end
16
16
 
17
17
  describe "instance" do
@@ -20,27 +20,27 @@ describe HackyHAL::DeviceResolvers::SSDP do
20
20
  end
21
21
 
22
22
  it "should return uri resolved via SSDP" do
23
- UPnP::SSDP.stub(:search).and_return([
23
+ allow(UPnP::SSDP).to receive(:search).and_return([
24
24
  {location: "http://resolved-host/path", usn: "dummy-usn"}
25
25
  ])
26
- @resolver.uri.host.should == "resolved-host"
26
+ expect(@resolver.uri.host).to eq "resolved-host"
27
27
  end
28
28
 
29
29
  it "should raise SsdpUnresolvedDevice if no device found" do
30
- UPnP::SSDP.stub(:search).and_return([])
30
+ allow(UPnP::SSDP).to receive(:search).and_return([])
31
31
  expect { @resolver.uri }.to raise_error(HackyHAL::DeviceResolvers::SsdpUnresolvedDevice)
32
32
  end
33
33
 
34
34
  it "should return the host of device with given USN" do
35
- UPnP::SSDP.stub(:search).and_return([
35
+ allow(UPnP::SSDP).to receive(:search).and_return([
36
36
  {location: "http://other-resolved-host/path", usn: "other-usn"},
37
37
  {location: "http://resolved-host/path", usn: "dummy-usn"}
38
38
  ])
39
- @resolver.uri.host.should == "resolved-host"
39
+ expect(@resolver.uri.host).to eq "resolved-host"
40
40
  end
41
41
 
42
42
  it "should raise SsdpUnresolvedDevice if device with request USN not found" do
43
- UPnP::SSDP.stub(:search).and_return([
43
+ allow(UPnP::SSDP).to receive(:search).and_return([
44
44
  {location: "http://other-resolved-host/path", usn: "other-usn"}
45
45
  ])
46
46
  expect { @resolver.uri }.to raise_error(HackyHAL::DeviceResolvers::SsdpUnresolvedDevice)
@@ -11,6 +11,6 @@ describe HackyHAL::DeviceResolvers::StaticURI do
11
11
 
12
12
  it "should return static host" do
13
13
  resolver = described_class.new(uri: "http://device-host.local")
14
- resolver.uri.host.should == "device-host.local"
14
+ expect(resolver.uri.host).to eq "device-host.local"
15
15
  end
16
16
  end
@@ -12,14 +12,14 @@ describe HackyHAL::Log do
12
12
  end
13
13
 
14
14
  it "should use custom formatter" do
15
- described_class.instance.formatter.should be_a(described_class::Formatter)
16
- described_class.instance.formatter.should_receive(:call)
15
+ expect(described_class.instance.formatter).to be_a(described_class::Formatter)
16
+ expect(described_class.instance.formatter).to receive(:call)
17
17
  described_class.instance.info("foo")
18
18
  end
19
19
 
20
20
  describe "#write" do
21
21
  it "should alias to self.<<" do
22
- described_class.instance.should_receive(:<<).with("foo")
22
+ expect(described_class.instance).to receive(:<<).with("foo")
23
23
  described_class.instance.write("foo")
24
24
  end
25
25
  end
@@ -9,14 +9,14 @@ describe HackyHAL::Options do
9
9
  describe "#initialize" do
10
10
  it "should set options" do
11
11
  object = DummyClass.new(dummy_argument: "dummy value")
12
- object.options.should == {dummy_argument: "dummy value"}
12
+ expect(object.options).to eq({dummy_argument: "dummy value"})
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#[]" do
17
17
  it "should return option values" do
18
18
  object = DummyClass.new(dummy_argument: "dummy value")
19
- object[:dummy_argument].should == "dummy value"
19
+ expect(object[:dummy_argument]).to eq "dummy value"
20
20
  end
21
21
  end
22
22
  end
@@ -10,21 +10,22 @@ describe HackyHAL::Registry do
10
10
  "foo" => "bar"
11
11
  }
12
12
  }
13
- File.stub(:read)
14
- YAML.stub(:load).and_return(@device_config)
13
+
14
+ allow(File).to receive(:read)
15
+ allow(YAML).to receive(:load).and_return(@device_config)
15
16
  end
16
17
 
17
18
  it "should load and initialize device controllers into registry" do
18
19
  described_class.instance.load_yaml_file("foo.yml")
19
20
  devices = described_class.instance.devices
20
- devices.length.should == 1
21
- devices[:foo_device].should be_instance_of(HackyHAL::DeviceControllers::Base)
21
+ expect(devices.length).to eq 1
22
+ expect(devices[:foo_device]).to be_instance_of(HackyHAL::DeviceControllers::Base)
22
23
  end
23
24
 
24
25
  it "should convert keys to symbols" do
25
26
  described_class.instance.load_yaml_file("foo.yml")
26
27
  devices = described_class.instance.devices
27
- devices[:foo_device][:foo].should == "bar"
28
+ expect(devices[:foo_device][:foo]).to eq "bar"
28
29
  end
29
30
  end
30
31
  end
@@ -14,14 +14,14 @@ describe HackyHAL::Util do
14
14
 
15
15
  it "should return instance of built class" do
16
16
  dummy_instance = double("dummy instance")
17
- DummyModule::DummyClass.should_receive(:new).with(foo: 1).and_return(dummy_instance)
18
- described_class.object_from_hash({type: 'DummyClass', foo: 1}, DummyModule).should == dummy_instance
17
+ expect(DummyModule::DummyClass).to receive(:new).with(foo: 1).and_return(dummy_instance)
18
+ expect(described_class.object_from_hash({type: "DummyClass", foo: 1}, DummyModule)).to eq dummy_instance
19
19
  end
20
20
  end
21
21
 
22
22
  describe ".symbolize_keys_deep" do
23
23
  it "should symbolize hash keys" do
24
- described_class.symbolize_keys_deep("a" => 1, :b => {"c" => 2}).should == {a: 1, b: {c: 2}}
24
+ expect(described_class.symbolize_keys_deep("a" => 1, :b => {"c" => 2})).to eq({a: 1, b: {c: 2}})
25
25
  end
26
26
  end
27
27
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: hacky_hal
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 0.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nick Ewing
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-08 00:00:00.000000000 Z
12
+ date: 2014-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: upnp-nickewing