ruku 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +96 -0
  3. data/Rakefile +33 -0
  4. data/bin/ruku +50 -0
  5. data/lib/ruku/clients/simple.rb +232 -0
  6. data/lib/ruku/clients/tk.rb +36 -0
  7. data/lib/ruku/clients/web.rb +117 -0
  8. data/lib/ruku/clients/web_static/css/ruku.css +196 -0
  9. data/lib/ruku/clients/web_static/images/box-medium.png +0 -0
  10. data/lib/ruku/clients/web_static/images/box-small.png +0 -0
  11. data/lib/ruku/clients/web_static/images/remote/back-over.png +0 -0
  12. data/lib/ruku/clients/web_static/images/remote/back.png +0 -0
  13. data/lib/ruku/clients/web_static/images/remote/down-over.png +0 -0
  14. data/lib/ruku/clients/web_static/images/remote/down.png +0 -0
  15. data/lib/ruku/clients/web_static/images/remote/fwd-over.png +0 -0
  16. data/lib/ruku/clients/web_static/images/remote/fwd.png +0 -0
  17. data/lib/ruku/clients/web_static/images/remote/home-over.png +0 -0
  18. data/lib/ruku/clients/web_static/images/remote/home.png +0 -0
  19. data/lib/ruku/clients/web_static/images/remote/left-over.png +0 -0
  20. data/lib/ruku/clients/web_static/images/remote/left.png +0 -0
  21. data/lib/ruku/clients/web_static/images/remote/pause-over.png +0 -0
  22. data/lib/ruku/clients/web_static/images/remote/pause.png +0 -0
  23. data/lib/ruku/clients/web_static/images/remote/right-over.png +0 -0
  24. data/lib/ruku/clients/web_static/images/remote/right.png +0 -0
  25. data/lib/ruku/clients/web_static/images/remote/select-over.png +0 -0
  26. data/lib/ruku/clients/web_static/images/remote/select.png +0 -0
  27. data/lib/ruku/clients/web_static/images/remote/space1.png +0 -0
  28. data/lib/ruku/clients/web_static/images/remote/space2.png +0 -0
  29. data/lib/ruku/clients/web_static/images/remote/space3.png +0 -0
  30. data/lib/ruku/clients/web_static/images/remote/up-over.png +0 -0
  31. data/lib/ruku/clients/web_static/images/remote/up.png +0 -0
  32. data/lib/ruku/clients/web_static/images/spacer.gif +0 -0
  33. data/lib/ruku/clients/web_static/index.html +203 -0
  34. data/lib/ruku/clients/web_static/js/jquery-1.4.2.js +154 -0
  35. data/lib/ruku/clients/web_static/js/ruku.js +447 -0
  36. data/lib/ruku/remote.rb +138 -0
  37. data/lib/ruku/remotes.rb +78 -0
  38. data/lib/ruku/storage.rb +77 -0
  39. data/lib/ruku.rb +5 -0
  40. data/ruku.gemspec +31 -0
  41. data/test/helper.rb +11 -0
  42. data/test/js/qunit.css +119 -0
  43. data/test/js/qunit.js +1069 -0
  44. data/test/js/runner.html +29 -0
  45. data/test/js/test_remote.js +37 -0
  46. data/test/js/test_remote_manager.js +186 -0
  47. data/test/js/test_remote_menu.js +208 -0
  48. data/test/js/test_util.js +15 -0
  49. data/test/test_remote.rb +89 -0
  50. data/test/test_remotes.rb +144 -0
  51. data/test/test_simple_client.rb +166 -0
  52. data/test/test_simple_storage.rb +70 -0
  53. data/test/test_web_client.rb +46 -0
  54. data/test/test_yaml_storage.rb +54 -0
  55. metadata +156 -0
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <title>Ruku Web Client JavaScript Test Results</title>
5
+
6
+ <!-- jQuery, QUnit, and utils -->
7
+ <script language="javascript" src="../../lib/ruku/clients/web_static/js/jquery-1.4.2.js" type="text/javascript"></script>
8
+ <script language="javascript" src="qunit.js" type="text/javascript"></script>
9
+ <script language="javascript" src="test_util.js" type="text/javascript"></script>
10
+
11
+ <!-- code under test -->
12
+ <script language="javascript" src="../../lib/ruku/clients/web_static/js/ruku.js" type="text/javascript"></script>
13
+
14
+ <!-- tests -->
15
+ <script language="javascript" src="test_remote.js" type="text/javascript"></script>
16
+ <script language="javascript" src="test_remote_manager.js" type="text/javascript"></script>
17
+ <script language="javascript" src="test_remote_menu.js" type="text/javascript"></script>
18
+
19
+ <link media="screen" href="qunit.css" type="text/css" rel="stylesheet"/>
20
+ </head>
21
+ <body>
22
+ <h1 id="qunit-header">Ruku Web Client JavaScript Test Results</h1>
23
+ <h2 id="qunit-banner"></h2>
24
+ <h2 id="qunit-userAgent"></h2>
25
+ <ol id="qunit-tests"></ol>
26
+
27
+ <div id="testArea"> </div>
28
+ </body>
29
+ </html>
@@ -0,0 +1,37 @@
1
+ module("remote");
2
+
3
+ test("should create correctly", function() {
4
+ var initObj = {host:"192.168.1.101", name:"Test box name", port:"5000"};
5
+ var remote = RUKU.createRemote(initObj);
6
+ equals(remote.host, initObj.host);
7
+ equals(remote.name, initObj.name);
8
+ equals(remote.port, initObj.port);
9
+ });
10
+
11
+ test("should have correct default port", function() {
12
+ var initObj = {host:"192.168.1.101", name:"Test box name"};
13
+ var remote = RUKU.createRemote(initObj);
14
+ equals(remote.host, initObj.host);
15
+ equals(remote.name, initObj.name);
16
+ equals(remote.port, 8080);
17
+ });
18
+
19
+ test("should send ajax requests for commands", function() {
20
+ var testHost = "192.168.1.101"
21
+ var remote = RUKU.createRemote({host:testHost, name:"Test box name"});
22
+
23
+ TEST.mockAjax("success");
24
+ remote.up();
25
+ var opts = TEST.lastAjaxOptions;
26
+
27
+ equals(opts.url, "/ajax");
28
+ equals(opts.data.host, testHost);
29
+ equals(opts.data.command, "up");
30
+
31
+ TEST.mockAjax("success");
32
+ remote.select();
33
+ var opts = TEST.lastAjaxOptions;
34
+ equals(opts.url, "/ajax");
35
+ equals(opts.data.host, testHost);
36
+ equals(opts.data.command, "select");
37
+ });
@@ -0,0 +1,186 @@
1
+ (function() {
2
+
3
+ module("remoteManager");
4
+
5
+ RMTEST = {};
6
+ RMTEST.activeHost = "192.168.1.70";
7
+ RMTEST.activeName = "The Initially Active Remote";
8
+ RMTEST.inactiveHost = "192.168.1.80";
9
+ RMTEST.inactiveName = "Not Initially Active";
10
+
11
+ function getTestRemoteManager() {
12
+ return RUKU.createRemoteManager({
13
+ remotes: [
14
+ {host:RMTEST.inactiveHost, name:RMTEST.inactiveName},
15
+ {host:RMTEST.activeHost, name:RMTEST.activeName}
16
+ ],
17
+ active: 1
18
+ });
19
+ }
20
+
21
+ test("should create correctly with no args", function() {
22
+ var rm = RUKU.createRemoteManager();
23
+ equals(rm.remotes.length, 0);
24
+ equals(rm.activeIndex, 0);
25
+ });
26
+
27
+ test("should create correctly with remote data", function() {
28
+ var rm = getTestRemoteManager();
29
+ equals(rm.remotes.length, 2);
30
+ equals(rm.activeIndex, 1);
31
+ equals(rm.remotes[0].host,RMTEST.inactiveHost);
32
+ equals(rm.remotes[0].name, RMTEST.inactiveName);
33
+ equals(rm.remotes[1].host, RMTEST.activeHost);
34
+ equals(rm.remotes[1].name, RMTEST.activeName);
35
+ });
36
+
37
+ test("should create correctly without active index", function() {
38
+ var rm = RUKU.createRemoteManager({
39
+ remotes: [
40
+ {host:"192.168.1.8", name:"Should Be Active"},
41
+ {host:"192.168.1.70", name:"Not Active"}
42
+ ]
43
+ });
44
+ equals(rm.remotes.length, 2);
45
+ equals(rm.activeIndex, 0);
46
+ equals(rm.remotes[0].host, "192.168.1.8");
47
+ equals(rm.remotes[1].host, "192.168.1.70");
48
+ });
49
+
50
+ test("load should load data from the server", function() {
51
+ var newHost = "192.168.1.20";
52
+ TEST.mockAjax({"remotes":[{"host":newHost}],"active":0});
53
+ var rm = getTestRemoteManager();
54
+ equals(rm.remotes.length, 2, "Initialized with correct number of remotes");
55
+
56
+ rm.load();
57
+
58
+ var opts = TEST.lastAjaxOptions;
59
+ equals(opts.url, "/ajax");
60
+ equals(opts.dataType, "json");
61
+ equals(opts.data.action, "list");
62
+
63
+ equals(rm.remotes.length, 1);
64
+ equals(rm.getActive().host, newHost);
65
+ });
66
+
67
+ test("should send data to the server for saving", function() {
68
+ var rm = getTestRemoteManager();
69
+
70
+ TEST.mockAjax("success");
71
+
72
+ rm.save();
73
+
74
+ var opts = TEST.lastAjaxOptions;
75
+ equals(opts.url, "/ajax", "Correct path used");
76
+ equals(opts.data.action, "update", "Correct action specified");
77
+
78
+ var remoteData = $.parseJSON(opts.data.data);
79
+ equals(remoteData.remotes.length, 2, "Correct number of remotes sent");
80
+ var remote1 = remoteData.remotes[0];
81
+ var remote2 = remoteData.remotes[1];
82
+ equals(remote1.host, RMTEST.inactiveHost, "First remote host sent correctly");
83
+ equals(remote1.name, RMTEST.inactiveName, "First remote name sent correctly");
84
+ equals(remote1.port, 8080, "First remote port sent correctly");
85
+ equals(remote2.host, RMTEST.activeHost, "Second remote host sent correctly");
86
+ equals(remote2.name, RMTEST.activeName, "Second remote name sent correctly");
87
+ equals(remote2.port, 8080, "Second remote port sent correctly");
88
+ equals(remoteData.active, 1, "Active index sent correctly");
89
+ });
90
+
91
+ test("getActive should get the active remote", function() {
92
+ var rm = getTestRemoteManager();
93
+ equals(rm.getActive().host, RMTEST.activeHost);
94
+ equals(rm.getActive().name, RMTEST.activeName);
95
+ });
96
+
97
+ test("setActive with remote object should set the active remote and send the update to the server",
98
+ function() {
99
+ var rm = getTestRemoteManager();
100
+ equals(rm.getActive().host, RMTEST.activeHost, "Initial active host is correct");
101
+
102
+ TEST.mockAjax("success");
103
+
104
+ var newActive = RUKU.createRemote({name:RMTEST.inactiveName, host:RMTEST.inactiveHost});
105
+ rm.setActive(newActive);
106
+
107
+ equals(rm.getActive().host, newActive.host, "Active host address updated correctly");
108
+ equals(rm.getActive().name, newActive.name, "Active name updated correctly");
109
+
110
+ var opts = TEST.lastAjaxOptions;
111
+ equals(opts.url, "/ajax", "Correct path used");
112
+ equals(opts.data.action, "update", "Correct action specified");
113
+
114
+ var remoteData = $.parseJSON(opts.data.data);
115
+ equals(remoteData.remotes.length, 2, "Correct number of remotes sent");
116
+ var remote1 = remoteData.remotes[0];
117
+ var remote2 = remoteData.remotes[1];
118
+ equals(remote1.host, RMTEST.inactiveHost, "First remote host sent correctly");
119
+ equals(remote2.host, RMTEST.activeHost, "Second remote host sent correctly");
120
+ equals(remoteData.active, 0, "Correct new active index sent to server");
121
+ });
122
+
123
+ test("setActive with host should set the active remote and send the update to the server",
124
+ function() {
125
+ var rm = getTestRemoteManager();
126
+ equals(rm.getActive().host, RMTEST.activeHost, "Initial active host is correct");
127
+
128
+ TEST.mockAjax("success");
129
+
130
+ var newActive = RUKU.createRemote({name:RMTEST.inactiveName, host:RMTEST.inactiveHost});
131
+ rm.setActive(newActive.host); // Set with host instead of remote object itself
132
+
133
+ equals(rm.getActive().host, newActive.host, "Active host address updated correctly");
134
+ equals(rm.getActive().name, newActive.name, "Active name updated correctly");
135
+
136
+ var opts = TEST.lastAjaxOptions;
137
+ equals(opts.url, "/ajax", "Correct path used");
138
+ equals(opts.data.action, "update", "Correct action specified");
139
+
140
+ var remoteData = $.parseJSON(opts.data.data);
141
+ equals(remoteData.remotes.length, 2, "Correct number of remotes sent");
142
+ var remote1 = remoteData.remotes[0];
143
+ var remote2 = remoteData.remotes[1];
144
+ equals(remote1.host, RMTEST.inactiveHost, "First remote host sent correctly");
145
+ equals(remote2.host, RMTEST.activeHost, "Second remote host sent correctly");
146
+ equals(remoteData.active, 0, "Correct new active index sent to server");
147
+ });
148
+
149
+ test("should load scan for first results from the server", function() {
150
+ var newHost = "192.168.1.77";
151
+ var rm = getTestRemoteManager();
152
+
153
+ TEST.mockAjax({"remotes":[{"host":newHost}],"active":0});
154
+
155
+ rm.scanForFirst();
156
+
157
+ var opts = TEST.lastAjaxOptions;
158
+ equals(opts.url, "/ajax");
159
+ equals(opts.dataType, "json");
160
+ equals(opts.data.action, "scanForFirst");
161
+
162
+ var active = rm.getActive();
163
+ equals(active.host, newHost);
164
+ });
165
+
166
+ test("should load scan for all results from the server", function() {
167
+ var firstHost = "192.168.1.77";
168
+ var secondHost = "192.168.1.78";
169
+ var rm = getTestRemoteManager();
170
+
171
+ TEST.mockAjax({"remotes":[{"host":firstHost}, {"host":secondHost}],"active":0});
172
+
173
+ rm.scanForAll();
174
+
175
+ var opts = TEST.lastAjaxOptions;
176
+ equals(opts.url, "/ajax");
177
+ equals(opts.dataType, "json");
178
+ equals(opts.data.action, "scanForAll");
179
+
180
+ equals(rm.remotes.length, 2, "Correct number of remotes retrieved");
181
+ var active = rm.getActive();
182
+ equals(active.host, firstHost);
183
+ equals(rm.remotes[1].host, secondHost);
184
+ });
185
+
186
+ })();
@@ -0,0 +1,208 @@
1
+ (function() {
2
+
3
+ module("remoteMenu", {
4
+ setup:function() {
5
+ $("#testArea").empty()
6
+ .append($('<div id="activeRemoteTitle">&nbsp;</div>'))
7
+ .append(
8
+ $('<div id="remoteMenu" style="display:none;">' +
9
+ '<a id="closeButton" class="buttonLink" href="#">X close</a>' +
10
+ '<a id="scanButton" class="buttonLink" href="#">scan for boxes</a>' +
11
+ '<div class="title">Manage Boxes</div>' +
12
+ '<div id="remoteList"></div>' +
13
+ '<div id="firstBoxInfo" style="display:none;"></div>' +
14
+ '</div>')
15
+ );
16
+ }, teardown:function() {
17
+ $("#testArea").empty();
18
+ }
19
+ });
20
+
21
+ MENUTEST = {};
22
+ MENUTEST.activeHost = "192.168.1.70";
23
+ MENUTEST.activeName = "The Active Remote";
24
+ MENUTEST.inactiveHost = "192.168.1.80";
25
+ MENUTEST.inactiveName = "Not Active";
26
+
27
+ function getTestRemoteManager() {
28
+ return RUKU.createRemoteManager({
29
+ remotes: [
30
+ {host:MENUTEST.inactiveHost, name:MENUTEST.inactiveName},
31
+ {host:MENUTEST.activeHost, name:MENUTEST.activeName}
32
+ ],
33
+ active: 1
34
+ });
35
+ }
36
+
37
+ function getTestRemoteMenu() {
38
+ return RUKU.createRemoteMenu($("#remoteMenu"), $("#activeRemoteTitle"), getTestRemoteManager());
39
+ };
40
+
41
+ test("should know if it hasRemotes", function() {
42
+ ok(getTestRemoteMenu().hasRemotes(), "Yep, 2 remotes here");
43
+ ok(!RUKU.createRemoteMenu($("remoteMenu"), $("activeRemoteTitle")).hasRemotes(),
44
+ "No remotes in this one");
45
+ ok(!RUKU.createRemoteMenu($("remoteMenu"), $("activeRemoteTitle"),
46
+ RUKU.createRemoteManager()).hasRemotes(), "Also no remotes");
47
+ });
48
+
49
+ test("should show remotes list correctly", function() {
50
+ var menu = getTestRemoteMenu();
51
+ menu.show();
52
+ var remoteDivs = $("#remoteMenu > #remoteList > div.remote");
53
+ equals(remoteDivs.size(), 2, "Displays the correct number of remotes");
54
+ equals(remoteDivs.first().find(".name").val(), MENUTEST.inactiveName,
55
+ "First remote name is correct");
56
+ equals(remoteDivs.first().find(".host").text(), MENUTEST.inactiveHost,
57
+ "First remote host is correct");
58
+ equals(remoteDivs.last().find(".name").val(), MENUTEST.activeName,
59
+ "Second remote name is correct");
60
+ equals(remoteDivs.last().find(".host").text(), MENUTEST.activeHost,
61
+ "Second remote host is correct");
62
+ ok($("#remoteMenu > #remoteList").is(":visible"), "List is visible");
63
+ });
64
+
65
+ test("should get the correct active remote", function() {
66
+ var menu = getTestRemoteMenu();
67
+ var active = menu.getActiveRemote();
68
+ equals(active.host, MENUTEST.activeHost, "Active remote has correct host");
69
+ });
70
+
71
+ test("should load results from server and render result after scanning for first", function() {
72
+ var newHost = "192.168.1.77";
73
+ var menu = getTestRemoteMenu();
74
+
75
+ TEST.mockAjax({"remotes":[{"host":newHost}],"active":0});
76
+
77
+ $("#remoteMenu").show(); // Remote menu would be visible for scan button to be clicked
78
+
79
+ $("#scanButton").click();
80
+
81
+ var opts = TEST.lastAjaxOptions;
82
+ equals(opts.url, "/ajax");
83
+ equals(opts.dataType, "json");
84
+ equals(opts.data.action, "scanForFirst");
85
+
86
+ var active = menu.getActiveRemote();
87
+ equals(active.host, newHost);
88
+
89
+ ok($("#firstBoxInfo").is(":visible"));
90
+ equals($("#firstBoxInfo .host").text(), newHost);
91
+ });
92
+
93
+ test("should load results from server and render result after scanning for all", function() {
94
+ var firstHost = "192.168.1.77";
95
+ var secondHost = "192.168.1.78";
96
+ var menu = getTestRemoteMenu();
97
+
98
+ TEST.mockAjax({"remotes":[{"host":firstHost}],"active":0});
99
+ $("#remoteMenu").show();
100
+ $("#scanButton").click();
101
+
102
+ // We should be set up now in the typical situation to scan for more boxes,
103
+ // after the first is found and displayed.
104
+
105
+ // Send back one more the second time
106
+ TEST.mockAjax({"remotes":[{"host":firstHost}, {"host":secondHost}],"active":0});
107
+ $("#remoteMenu .moreButton").click();
108
+
109
+ var remoteDivs = $("#remoteMenu > #remoteList > div.remote");
110
+ equals(remoteDivs.size(), 2, "Displays the correct number of remotes");
111
+ equals(remoteDivs.first().find(".host").text(), firstHost,
112
+ "First remote host is correct");
113
+ equals(remoteDivs.last().find(".host").text(), secondHost,
114
+ "Second remote host is correct");
115
+ ok($("#remoteMenu > #remoteList").is(":visible"), "List is visible");
116
+ });
117
+
118
+ test("should allow updating of remote name", function() {
119
+ var menu = getTestRemoteMenu();
120
+ menu.show();
121
+
122
+ var newName = "New Name";
123
+
124
+ // This is something of an integration test since it tests to make sure everything happens,
125
+ // the whole way to the remoteManager making the correct request to the server to update
126
+ // the remote data.
127
+
128
+ TEST.mockAjax("success");
129
+
130
+ var nameElement = $("#remoteList .remote .name").last();
131
+
132
+ // Simulate a user editing the remote name
133
+ nameElement.focus();
134
+ nameElement.val(newName);
135
+ nameElement.blur();
136
+
137
+ // Make sure the resulting request has the correct data
138
+ var opts = TEST.lastAjaxOptions;
139
+ equals(opts.url, "/ajax");
140
+ equals(opts.data.action, "update");
141
+
142
+ var remoteData = $.parseJSON(opts.data.data);
143
+ equals(remoteData.remotes.length, 2);
144
+ var remote1 = remoteData.remotes[0];
145
+ var remote2 = remoteData.remotes[1];
146
+ equals(remote1.host, MENUTEST.inactiveHost);
147
+ equals(remote1.name, MENUTEST.inactiveName);
148
+ equals(remote1.port, 8080);
149
+ equals(remote2.host, MENUTEST.activeHost);
150
+ equals(remote2.name, newName);
151
+ equals(remote2.port, 8080);
152
+ equals(remoteData.active, 1);
153
+ });
154
+
155
+ test("should update active remote title on remote name update", function() {
156
+ var menu = getTestRemoteMenu();
157
+ menu.show();
158
+
159
+ var newName = "New Name";
160
+
161
+ // Just mock out the AJAX to prevent it from making the request
162
+ TEST.mockAjax("success");
163
+
164
+ var nameDisplay = $("#activeRemoteTitle");
165
+ var menuNameElement = $("#remoteList .remote .name").last();
166
+
167
+ menu.updateActiveRemoteTitle();
168
+
169
+ equals(nameDisplay.text(), MENUTEST.activeName, "Has correct initial title");
170
+
171
+ // Simulate a user editing the remote name
172
+ menuNameElement.focus();
173
+ menuNameElement.val(newName);
174
+ menuNameElement.blur();
175
+
176
+ equals(nameDisplay.text(), newName, "Has correct updated title");
177
+ });
178
+
179
+ test("should allow updating of active remote", function() {
180
+ var menu = getTestRemoteMenu();
181
+ menu.show();
182
+
183
+ // Also tests integration with remoteManager and verifies request to the server to update
184
+ // the remote data.
185
+ TEST.mockAjax("success");
186
+
187
+ equals(menu.getActiveRemote().host, MENUTEST.activeHost, "Has correct initial host");
188
+
189
+ // Select the first remote to make it active
190
+ $("#remoteMenu .activeRemoteRadio").first().change();
191
+
192
+ equals(menu.getActiveRemote().host, MENUTEST.inactiveHost, "Has correct updated host");
193
+
194
+ // Make sure the resulting request has the correct data
195
+ var opts = TEST.lastAjaxOptions;
196
+ equals(opts.url, "/ajax");
197
+ equals(opts.data.action, "update");
198
+
199
+ var remoteData = $.parseJSON(opts.data.data);
200
+ equals(remoteData.remotes.length, 2);
201
+ var remote1 = remoteData.remotes[0];
202
+ var remote2 = remoteData.remotes[1];
203
+ equals(remote1.host, MENUTEST.inactiveHost);
204
+ equals(remote2.host, MENUTEST.activeHost);
205
+ equals(remoteData.active, 0, "Correct new active index sent to server");
206
+ });
207
+
208
+ })();
@@ -0,0 +1,15 @@
1
+ function TEST() {}
2
+
3
+ TEST.lastAjaxOptions;
4
+ TEST.mockAjax = function(response, error) {
5
+ TEST.lastAjaxOptions = null;
6
+
7
+ jQuery.ajax = function(opts) {
8
+ TEST.lastAjaxOptions = opts;
9
+ if (!error) {
10
+ opts["success"](response);
11
+ } else {
12
+ opts["error"](response);
13
+ }
14
+ };
15
+ };
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestRemote < Test::Unit::TestCase
4
+ TEST_HOST = "192.168.1.5"
5
+ TEST_NAME = "Living room"
6
+ TEST_PORT = 5000
7
+
8
+ def test_initialize_and_read_host
9
+ assert_equal TEST_HOST, Remote.new(TEST_HOST, TEST_NAME).host
10
+ end
11
+
12
+ def test_initialize_and_read_port
13
+ assert_equal TEST_PORT, Remote.new(TEST_HOST, TEST_NAME, TEST_PORT).port
14
+ end
15
+
16
+ def test_initialize_and_read_name
17
+ assert_equal TEST_NAME, Remote.new(TEST_HOST, TEST_NAME).name
18
+ end
19
+
20
+ def test_default_port
21
+ assert_equal 8080, Remote::DEFAULT_PORT
22
+ assert_equal Remote::DEFAULT_PORT, Remote.new(TEST_HOST, TEST_NAME).port
23
+ end
24
+
25
+ def test_send_command
26
+ expect_command('left')
27
+ r = default_remote
28
+ r.send_roku_command :left
29
+ end
30
+
31
+ def test_send_command_as_string
32
+ expect_command('left')
33
+ r = default_remote
34
+ r.send_roku_command 'left'
35
+ end
36
+
37
+ def test_select_overridden
38
+ expect_command('sel')
39
+ r = default_remote
40
+ r.select
41
+ end
42
+
43
+ def test_select_fixed
44
+ expect_command('sel')
45
+ r = default_remote
46
+ r.send_roku_command :select
47
+ end
48
+
49
+ # Make sure that most methods on the Remote have been undefined so that
50
+ # almost any command can be sent
51
+ def test_blank_slated
52
+ mock = expect_command('freeze')
53
+ expect_command('send', mock)
54
+ r = default_remote
55
+ r.freeze
56
+ r.send
57
+ end
58
+
59
+ def test_commands_are_chainable
60
+ mock = expect_command('down')
61
+ expect_command('right', mock)
62
+ r = default_remote
63
+ assert_same r.down.right, r
64
+ end
65
+
66
+ def test_same_host_means_equal
67
+ r1 = Remote.new(TEST_HOST, 'one')
68
+ r2 = Remote.new(TEST_HOST, 'two')
69
+ assert r1 == r2
70
+ new_test_host = "192.168.1.7"
71
+ assert new_test_host != TEST_HOST
72
+ r3 = Remote.new(new_test_host, 'three')
73
+ assert r1 != r3
74
+ assert r3 != r1
75
+ end
76
+
77
+ protected
78
+
79
+ def default_remote
80
+ Remote.new(TEST_HOST, TEST_NAME)
81
+ end
82
+
83
+ def expect_command(cmd, mock_socket=mock())
84
+ mock_socket.expects(:write).with("press #{cmd}\n").once
85
+ mock_socket.expects(:close).once
86
+ TCPSocket.expects(:open).with(TEST_HOST, Remote::DEFAULT_PORT).returns(mock_socket).once
87
+ mock_socket
88
+ end
89
+ end