lackie 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,10 +3,18 @@ Feature: Remote Control
3
3
  As a client
4
4
  I want to surrender applications as javascript lackies
5
5
 
6
- Scenario: Remote Execution
6
+ Scenario Outline: Remote Execution
7
7
  Given I have surrendered my web page as a lackie
8
- When I tell the lackie to execute "1 + 1"
9
- Then I should see a result with the value "2"
8
+ When I tell the lackie to execute "<command>"
9
+ Then I should see a result with the value "<result>"
10
+
11
+ Examples:
12
+
13
+ | command | result |
14
+ | 1 + 1 | 2 |
15
+ | 2 + 2 | 4 |
16
+ | 'foo' | foo |
17
+ | document.title | Lackie Example App |
10
18
 
11
19
  Scenario: Remote Execution Error
12
20
  Given I have surrendered my web page as a lackie
@@ -1,6 +1,6 @@
1
1
  <html>
2
2
  <head>
3
- <title>Lackie: Surrendered Web Page Example</title>
3
+ <title>Lackie Example App</title>
4
4
  </head>
5
5
  <body>
6
6
 
data/lackie.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency 'cucumber', '~> 0.10.0'
19
19
  s.add_development_dependency 'mongrel', '~> 1.1.5'
20
20
  s.add_development_dependency 'relevance-rcov', '~> 0.9.2.1'
21
+ s.add_development_dependency 'selenium-webdriver', '~> 0.1.2'
21
22
 
22
23
  s.rubygems_version = "1.3.7"
23
24
  s.files = `git ls-files`.split("\n")
@@ -1,4 +1,7 @@
1
1
  Lackie = {
2
+ wip: false,
3
+ enabled: true,
4
+
2
5
  createXMLHttpRequest: function() {
3
6
  try { return new XMLHttpRequest(); } catch(e) {}
4
7
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
@@ -6,9 +9,13 @@ Lackie = {
6
9
  },
7
10
 
8
11
  yield: function() {
12
+ if (Lackie.wip || !Lackie.enabled) {
13
+ return;
14
+ }
9
15
  var xhReq = Lackie.createXMLHttpRequest();
10
16
  function readyStateChange() {
11
- if (xhReq.readyState != 4) { return; }
17
+ if (xhReq.readyState != 4 || xhReq.status==404) { return; }
18
+ Lackie.wip = true;
12
19
  try {
13
20
  Lackie.execute(xhReq.responseText);
14
21
  }
@@ -32,6 +39,7 @@ Lackie = {
32
39
  xhReq.setRequestHeader("Content-length", params.length);
33
40
  xhReq.setRequestHeader("Connection", "close");
34
41
  xhReq.send(params);
42
+ Lackie.wip = false;
35
43
  },
36
44
 
37
45
  execute: function(command) {
@@ -53,6 +61,7 @@ Lackie = {
53
61
  return message;
54
62
  }
55
63
  }
64
+
56
65
  if (window) {
57
- window.setInterval(Lackie.yield, 200);
66
+ window.setInterval(Lackie.yield, 400);
58
67
  }
@@ -4,6 +4,7 @@ module Lackie
4
4
  module Rack
5
5
  class Middleware
6
6
  def initialize(app)
7
+ #puts "MIDDLEWARE CREATED"
7
8
  @app = app
8
9
  @command = nil
9
10
  @result = nil
@@ -31,9 +32,13 @@ module Lackie
31
32
  end
32
33
 
33
34
  def yield(request)
34
- what = @command || ""
35
- @command = nil
36
- js(what)
35
+ if @command.nil?
36
+ not_found
37
+ else
38
+ cmd = @command
39
+ @command = nil
40
+ js(cmd)
41
+ end
37
42
  end
38
43
 
39
44
  def result(request)
@@ -20,13 +20,19 @@ module Lackie
20
20
  private
21
21
 
22
22
  def send_command(command)
23
- RestClient.post("http://#{@host}:#{@port}/lackie/eval", command)
23
+ url = "http://#{@host}:#{@port}/lackie/eval"
24
+ begin
25
+ RestClient.post(url, command)
26
+ rescue => e
27
+ raise ConnectionError.new(url, e)
28
+ end
24
29
  end
25
30
 
26
31
  def poll_for_result(command)
27
32
  body = nil
28
33
  @poller.await("result of command:\n#{command}") do
29
34
  body = retrieve_result_body
35
+ !body.nil?
30
36
  end
31
37
  parse_result(body)
32
38
  end
@@ -41,11 +47,25 @@ module Lackie
41
47
 
42
48
  def parse_result(body)
43
49
  parsed_body = JSON.parse(body)
44
- raise RemoteExecutionError.new(parsed_body["error"]) if parsed_body.include?("error")
50
+ if parsed_body.include?("error")
51
+ raise RemoteExecutionError.new(parsed_body["error"])
52
+ end
45
53
  return parsed_body["value"]
46
54
  end
47
55
  end
48
56
 
57
+ class ConnectionError < RuntimeError
58
+ def initialize(url, inner)
59
+ @url = url
60
+ @inner = inner
61
+ end
62
+
63
+ def message
64
+ "Failed to send command to #{@url} - " +
65
+ "have you started a lackie server?\n#{@inner.message}"
66
+ end
67
+ end
68
+
49
69
  class RemoteExecutionError < RuntimeError
50
70
  end
51
71
  end
data/lib/lackie.rb CHANGED
@@ -2,7 +2,7 @@ lib = File.dirname(__FILE__)
2
2
  $:.unshift(lib) unless $:.include?(lib) || $:.include?(File.expand_path(lib))
3
3
 
4
4
  module Lackie
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
 
8
8
  require 'lackie/remote_control'
@@ -52,7 +52,7 @@ module Lackie
52
52
  it "returns '' as the response body" do
53
53
  post("/lackie/eval", "foo()")
54
54
  get("/lackie/yield")
55
- get("/lackie/yield").should == [200, {"Content-Type"=>"text/javascript"}, [""]]
55
+ get("/lackie/yield").should == [404, {"Content-Type"=>"text/plain"}, ["Not Found"]]
56
56
  end
57
57
  end
58
58
  end
@@ -42,5 +42,15 @@ module Lackie
42
42
  RestClient.should_receive(:get).and_return(mock("response", :body => '{"error":"oops"}'))
43
43
  lambda { @rc.log("oops") }.should raise_error("oops")
44
44
  end
45
+
46
+ it "reports a useful error when sending a command fails" do
47
+ RestClient.should_receive(:post).with("http://host:555/lackie/eval", 'foo').and_raise "oops"
48
+ begin
49
+ @rc.exec("foo")
50
+ fail "never raised"
51
+ rescue => e
52
+ e.message.should =~ /have you started a lackie server?/
53
+ end
54
+ end
45
55
  end
46
56
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lackie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Chisholm
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-31 00:00:00 +00:00
18
+ date: 2011-01-02 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -115,6 +115,22 @@ dependencies:
115
115
  version: 0.9.2.1
116
116
  type: :development
117
117
  version_requirements: *id006
118
+ - !ruby/object:Gem::Dependency
119
+ name: selenium-webdriver
120
+ prerelease: false
121
+ requirement: &id007 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ hash: 31
127
+ segments:
128
+ - 0
129
+ - 1
130
+ - 2
131
+ version: 0.1.2
132
+ type: :development
133
+ version_requirements: *id007
118
134
  description: Automates remote applications using an HTTP middleman
119
135
  email: joshuachisholm@gmail.com
120
136
  executables: []
@@ -182,7 +198,7 @@ rubyforge_project:
182
198
  rubygems_version: 1.3.7
183
199
  signing_key:
184
200
  specification_version: 3
185
- summary: lackie-0.1.0
201
+ summary: lackie-0.1.1
186
202
  test_files:
187
203
  - features/remote_control.feature
188
204
  - features/step_definitions/lackie_steps.rb