lackie 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/features/remote_control.feature +14 -6
- data/features/step_definitions/lackie_steps.rb +20 -1
- data/lib/lackie.rb +1 -1
- data/lib/lackie/remote_control.rb +29 -2
- data/spec/lackie/remote_control_spec.rb +31 -1
- metadata +4 -4
@@ -3,13 +3,14 @@ Feature: Remote Control
|
|
3
3
|
As a client
|
4
4
|
I want to surrender applications as javascript lackies
|
5
5
|
|
6
|
-
|
6
|
+
Background:
|
7
7
|
Given I have surrendered my web page as a lackie
|
8
|
+
|
9
|
+
Scenario Outline: Remote Execution
|
8
10
|
When I tell the lackie to execute "<command>"
|
9
11
|
Then I should see a result with the value "<result>"
|
10
12
|
|
11
13
|
Examples:
|
12
|
-
|
13
14
|
| command | result |
|
14
15
|
| 1 + 1 | 2 |
|
15
16
|
| 2 + 2 | 4 |
|
@@ -17,18 +18,25 @@ Feature: Remote Control
|
|
17
18
|
| document.title | Lackie Example App |
|
18
19
|
|
19
20
|
Scenario: Remote Execution Error
|
20
|
-
Given I have surrendered my web page as a lackie
|
21
21
|
When I tell the lackie to execute "(function() { throw 'whoopsie'; })()"
|
22
22
|
Then I should see an error with the message "whoopsie"
|
23
23
|
|
24
24
|
Scenario: Remote Log
|
25
|
-
Given I have surrendered my web page as a lackie
|
26
25
|
When I tell the lackie to log "yipee"
|
27
26
|
Then I should see a result with the value "yipee"
|
28
27
|
|
29
28
|
Scenario: Send Command Without Expecting A Result
|
30
|
-
Given I have surrendered my web page as a lackie
|
31
29
|
When I tell the lackie to send the command "window.foo = '123'"
|
32
30
|
Then I should see a result with the value "OK"
|
33
31
|
When I tell the lackie to execute "window.foo = 99"
|
34
|
-
Then I should see a result with the value "99"
|
32
|
+
Then I should see a result with the value "99"
|
33
|
+
|
34
|
+
Scenario: Await Result
|
35
|
+
When I tell the lackie to execute "setTimeout(function() { window.foo = 666 }, 500)"
|
36
|
+
And I await the result of "window.foo" to equal "666"
|
37
|
+
Then I should not see an error
|
38
|
+
|
39
|
+
Scenario: Await Result Timeout
|
40
|
+
When I tell the lackie to execute "window.bar = 123"
|
41
|
+
When I await the result of "window.bar" to equal "456"
|
42
|
+
Then I should see an error with a message including "123"
|
@@ -18,10 +18,29 @@ When /^I tell the lackie to send the command "([^"]*)"$/ do |script|
|
|
18
18
|
@response = remote_control.send_command(script)
|
19
19
|
end
|
20
20
|
|
21
|
+
When /^I await the result of "([^"]*)" to equal "([^"]*)"$/ do |script, value|
|
22
|
+
begin
|
23
|
+
@response = remote_control.await(script, :timeout_seconds => 1) do |current_value|
|
24
|
+
current_value.to_s == value
|
25
|
+
end
|
26
|
+
rescue Lackie::AwaitError => e
|
27
|
+
@error = e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
21
31
|
Then /^I should see a result with the value "([^\"]*)"$/ do |value|
|
22
32
|
@response.to_s.should == value
|
23
33
|
end
|
24
34
|
|
25
35
|
Then /^I should see an error with the message "([^\"]*)"$/ do |message|
|
26
36
|
@error.message.should == message
|
27
|
-
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^I should not see an error$/ do
|
40
|
+
raise @error unless @error.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^I should see an error with a message including "([^"]*)"$/ do |string|
|
44
|
+
@error.should_not be_nil
|
45
|
+
@error.message.should =~ Regexp.new(string)
|
46
|
+
end
|
data/lib/lackie.rb
CHANGED
@@ -26,6 +26,22 @@ module Lackie
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def await(expression, options={})
|
30
|
+
result = nil
|
31
|
+
begin
|
32
|
+
@poller.await("result matching expression: #{expression}", options) do
|
33
|
+
begin
|
34
|
+
result = exec(expression)
|
35
|
+
rescue TimeoutError => e
|
36
|
+
end
|
37
|
+
yield result
|
38
|
+
end
|
39
|
+
rescue TimeoutError => e
|
40
|
+
raise AwaitError.new(expression, result)
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
29
45
|
private
|
30
46
|
|
31
47
|
def poll_for_result(command, options={})
|
@@ -56,8 +72,7 @@ module Lackie
|
|
56
72
|
|
57
73
|
class ConnectionError < RuntimeError
|
58
74
|
def initialize(url, inner)
|
59
|
-
@url = url
|
60
|
-
@inner = inner
|
75
|
+
@url, @inner = url, inner
|
61
76
|
end
|
62
77
|
|
63
78
|
def message
|
@@ -68,4 +83,16 @@ module Lackie
|
|
68
83
|
|
69
84
|
class RemoteExecutionError < RuntimeError
|
70
85
|
end
|
86
|
+
|
87
|
+
class AwaitError < RuntimeError
|
88
|
+
def initialize(expression, result)
|
89
|
+
@expression, @result = expression, result
|
90
|
+
end
|
91
|
+
|
92
|
+
def message
|
93
|
+
"Timed out awaiting the result of expression:\n" +
|
94
|
+
"#{@expression}\n" +
|
95
|
+
"The last result was:\n#{@result}"
|
96
|
+
end
|
97
|
+
end
|
71
98
|
end
|
@@ -64,7 +64,7 @@ module Lackie
|
|
64
64
|
lambda { @rc.log("oops") }.should raise_error("oops")
|
65
65
|
end
|
66
66
|
|
67
|
-
it "
|
67
|
+
it "raises when sending a command fails" do
|
68
68
|
RestClient.should_receive(:post).with("http://host:555/lackie/eval", 'foo').and_raise "oops"
|
69
69
|
begin
|
70
70
|
@rc.exec("foo")
|
@@ -73,5 +73,35 @@ module Lackie
|
|
73
73
|
e.message.should =~ /have you started a lackie server?/
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
describe "#await" do
|
78
|
+
it "does not raise if the value eventually matches the block" do
|
79
|
+
responses = ["bar", "foo"].map do |result|
|
80
|
+
mock("stub_result_response", :body => { :value => result }.to_json)
|
81
|
+
end
|
82
|
+
RestClient.stub!(:get).with("http://host:555/lackie/result?cachebust").and_return {
|
83
|
+
responses.shift
|
84
|
+
}
|
85
|
+
lambda {
|
86
|
+
@rc.await("script") { |value| value == "foo" }
|
87
|
+
}.should_not raise_error
|
88
|
+
end
|
89
|
+
|
90
|
+
it "raises if the value never matches the block" do
|
91
|
+
RestClient.stub!(:get).with("http://host:555/lackie/result?cachebust").and_return {
|
92
|
+
mock("stub_result_response", :body => '{"value":"oopsie"}')
|
93
|
+
}
|
94
|
+
begin
|
95
|
+
@rc.await("script") { |value| value == "bar" }
|
96
|
+
rescue Lackie::AwaitError => e
|
97
|
+
e.message.should =~ /oopsie/
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "accepts an optional total number of seconds to wait" do
|
102
|
+
@poller.should_receive(:await).with("result matching expression: script", :timeout_seconds => 333)
|
103
|
+
@rc.await("script", :timeout_seconds => 333) { |value| value == "bar" }
|
104
|
+
end
|
105
|
+
end
|
76
106
|
end
|
77
107
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Chisholm
|
@@ -197,7 +197,7 @@ rubyforge_project:
|
|
197
197
|
rubygems_version: 1.3.7
|
198
198
|
signing_key:
|
199
199
|
specification_version: 3
|
200
|
-
summary: lackie-0.1.
|
200
|
+
summary: lackie-0.1.5
|
201
201
|
test_files:
|
202
202
|
- features/remote_control.feature
|
203
203
|
- features/step_definitions/lackie_steps.rb
|