caius-culerity 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/culerity.gemspec +2 -2
- data/lib/culerity/celerity_server.rb +12 -5
- data/lib/culerity/remote_browser_proxy.rb +13 -0
- data/lib/culerity/remote_object_proxy.rb +30 -10
- data/spec/remote_browser_proxy_spec.rb +21 -13
- data/spec/remote_object_proxy_spec.rb +34 -2
- metadata +2 -2
data/VERSION.yml
CHANGED
data/culerity.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{culerity}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Alexander Lang"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-26}
|
10
10
|
s.description = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
|
11
11
|
s.email = %q{alex@upstream-berlin.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -11,10 +11,17 @@ module Culerity
|
|
11
11
|
|
12
12
|
while(true)
|
13
13
|
call = eval _in.gets.to_s.strip
|
14
|
-
return
|
14
|
+
return if call == ["_exit_"]
|
15
15
|
unless call.nil?
|
16
16
|
begin
|
17
|
-
|
17
|
+
# check if last arg is a block
|
18
|
+
if call.last.is_a?(Proc)
|
19
|
+
# pass as &call[-1]
|
20
|
+
result = target(call.first).send call[1], *call[2..-2], &call[-1]
|
21
|
+
else
|
22
|
+
# just call with args as normal
|
23
|
+
result = target(call.first).send call[1], *call[2..-1]
|
24
|
+
end
|
18
25
|
_out << "[:return, #{proxify result}]\n"
|
19
26
|
rescue => e
|
20
27
|
_out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
|
@@ -44,11 +51,11 @@ module Culerity
|
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
def proxify(result)
|
54
|
+
def proxify(result, in_array = false)
|
48
55
|
if result.is_a?(Array)
|
49
|
-
result.map {|x| proxify(x) }.inspect
|
56
|
+
result.map {|x| proxify(x, true) }.inspect
|
50
57
|
elsif [String, TrueClass, FalseClass, Fixnum, Float, NilClass].include?(result.class)
|
51
|
-
result.inspect
|
58
|
+
in_array ? result : result.inspect
|
52
59
|
else
|
53
60
|
@proxies[result.object_id] = result
|
54
61
|
"Culerity::RemoteObjectProxy.new(#{result.object_id}, @io)"
|
@@ -42,6 +42,19 @@ module Culerity
|
|
42
42
|
true
|
43
43
|
end
|
44
44
|
|
45
|
+
|
46
|
+
#
|
47
|
+
# Specify whether to accept or reject all confirm js dialogs
|
48
|
+
# for the code in the block that's run.
|
49
|
+
#
|
50
|
+
def confirm(bool, &block)
|
51
|
+
blk = "lambda { #{bool} }"
|
52
|
+
|
53
|
+
self.send_remote(:add_listener, :confirm) { blk }
|
54
|
+
block.call
|
55
|
+
self.send_remote(:remove_listener, :confirm) { blk }
|
56
|
+
end
|
57
|
+
|
45
58
|
private
|
46
59
|
|
47
60
|
def remote_object_id
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Culerity
|
2
|
-
|
2
|
+
|
3
3
|
class CulerityException < StandardError
|
4
4
|
def initialize(message, backtrace)
|
5
5
|
super message
|
@@ -12,7 +12,7 @@ module Culerity
|
|
12
12
|
@remote_object_id = remote_object_id
|
13
13
|
@io = io
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
#
|
17
17
|
# Commonly used to get the HTML id attribute
|
18
18
|
# Use `object_id` to get the local objects' id.
|
@@ -20,26 +20,32 @@ module Culerity
|
|
20
20
|
def id
|
21
21
|
send_remote(:id)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def method_missing(name, *args)
|
25
25
|
send_remote(name, *args)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
#
|
29
29
|
# Calls the passed method on the remote object with any arguments specified.
|
30
30
|
# Behaves the same as <code>Object#send</code>.
|
31
31
|
#
|
32
|
-
|
33
|
-
|
32
|
+
# If you pass it a block then it will append the block as a "lambda { … }".
|
33
|
+
# If your block returns a lambda string ("lambda { … }") then it will be passed
|
34
|
+
# straight through, otherwise it will be wrapped in a lambda string before sending.
|
35
|
+
#
|
36
|
+
def send_remote(name, *args, &blk)
|
37
|
+
input = [remote_object_id, %Q{"#{name}"}, *args.map{|a| a.inspect}]
|
38
|
+
input << block_to_string(&blk) if block_given?
|
39
|
+
@io << "[#{input.join(", ")}]\n"
|
34
40
|
process_result @io.gets.to_s.strip
|
35
41
|
end
|
36
|
-
|
42
|
+
|
37
43
|
def exit
|
38
44
|
@io << '["_exit_"]'
|
39
45
|
end
|
40
|
-
|
46
|
+
|
41
47
|
private
|
42
|
-
|
48
|
+
|
43
49
|
def process_result(result)
|
44
50
|
res = eval result
|
45
51
|
if res.first == :return
|
@@ -48,7 +54,21 @@ module Culerity
|
|
48
54
|
raise CulerityException.new("#{res[1]}: #{res[2]}", res[3])
|
49
55
|
end
|
50
56
|
end
|
51
|
-
|
57
|
+
|
58
|
+
#
|
59
|
+
# Takes a block and either returns the result (if it returns "lambda { … }")
|
60
|
+
# or builds the lambda string with the result of the block in it.
|
61
|
+
#
|
62
|
+
# Returns a string in the format "lambda { … }"
|
63
|
+
#
|
64
|
+
def block_to_string &block
|
65
|
+
result = block.call.to_s
|
66
|
+
unless result.is_a?(String) && result[/^lambda \s* \{ .*? \}/x]
|
67
|
+
result = "lambda { #{result} }"
|
68
|
+
end
|
69
|
+
result
|
70
|
+
end
|
71
|
+
|
52
72
|
def remote_object_id
|
53
73
|
@remote_object_id
|
54
74
|
end
|
@@ -21,31 +21,39 @@ describe Culerity::RemoteBrowserProxy do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should timeout if wait_until takes too long" do
|
24
|
-
|
25
|
-
proxy = Culerity::RemoteBrowserProxy.new io
|
24
|
+
proxy = Culerity::RemoteBrowserProxy.new nil
|
26
25
|
lambda {
|
27
|
-
proxy.wait_until(1) { false }
|
26
|
+
proxy.wait_until(0.1) { false }
|
28
27
|
}.should raise_error(Timeout::Error)
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should return successfully when wait_until returns true" do
|
32
|
-
|
33
|
-
proxy
|
34
|
-
proxy.wait_until(1) { true }.should == true
|
31
|
+
proxy = Culerity::RemoteBrowserProxy.new nil
|
32
|
+
proxy.wait_until(0.1) { true }.should == true
|
35
33
|
end
|
36
34
|
|
37
35
|
it "should timeout if wait_while takes too long" do
|
38
|
-
|
39
|
-
proxy = Culerity::RemoteBrowserProxy.new io
|
36
|
+
proxy = Culerity::RemoteBrowserProxy.new nil
|
40
37
|
lambda {
|
41
|
-
proxy.wait_while(1) { true }
|
38
|
+
proxy.wait_while(0.1) { true }
|
42
39
|
}.should raise_error(Timeout::Error)
|
43
40
|
end
|
44
41
|
|
45
42
|
it "should return successfully when wait_while returns !true" do
|
46
|
-
|
47
|
-
proxy
|
48
|
-
proxy.wait_while(1) { false }.should == true
|
43
|
+
proxy = Culerity::RemoteBrowserProxy.new nil
|
44
|
+
proxy.wait_while(0.1) { false }.should == true
|
49
45
|
end
|
50
|
-
|
46
|
+
|
47
|
+
it "should accept all javascript confirmation dialogs" do
|
48
|
+
proxy = Culerity::RemoteBrowserProxy.new nil
|
49
|
+
|
50
|
+
proxy.should_receive(:send_remote).with(:add_listener, :confirm).and_return(true)
|
51
|
+
proxy.should_receive(:send_remote).with(:goto, "http://example.com").and_return(true)
|
52
|
+
proxy.should_receive(:send_remote).with(:remove_listener, :confirm).and_return(true)
|
53
|
+
|
54
|
+
proxy.confirm(true) do
|
55
|
+
proxy.goto "http://example.com"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
end
|
@@ -1,13 +1,45 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Culerity::RemoteObjectProxy do
|
4
|
+
describe "block_to_string method" do
|
5
|
+
it "should return block result when result is lambda string" do
|
6
|
+
proxy = Culerity::RemoteObjectProxy.new nil, nil
|
7
|
+
block = lambda { "lambda { true}" }
|
8
|
+
proxy.send(:block_to_string, &block).should == "lambda { true}"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return lambda string when block result isn't a lambda string" do
|
12
|
+
proxy = Culerity::RemoteObjectProxy.new nil, nil
|
13
|
+
[true, false, "blah", 5].each do |var|
|
14
|
+
block = lambda { var }
|
15
|
+
proxy.send(:block_to_string, &block).should == "lambda { #{var} }"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
4
20
|
it "should send the serialized method call to the output" do
|
5
21
|
io = stub 'io', :gets => '[:return]'
|
6
|
-
io.should_receive(:<<).with(
|
22
|
+
io.should_receive(:<<).with(%Q{[345, "goto", "/homepage"]\n})
|
7
23
|
proxy = Culerity::RemoteObjectProxy.new 345, io
|
8
24
|
proxy.goto '/homepage'
|
9
25
|
end
|
10
26
|
|
27
|
+
it "should send the serialized method call with argument plus block to the output" do
|
28
|
+
io = stub 'io', :gets => "[:return]"
|
29
|
+
io.should_receive(:<<).with(%Q{[345, "method", true, lambda { true }]\n})
|
30
|
+
proxy = Culerity::RemoteObjectProxy.new 345, io
|
31
|
+
|
32
|
+
proxy.send_remote(:method, true) { "lambda { true }" }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should send the serialized method call without argument plus block to the output" do
|
36
|
+
io = stub 'io', :gets => "[:return]"
|
37
|
+
io.should_receive(:<<).with(%Q{[345, "method", lambda { true }]\n})
|
38
|
+
proxy = Culerity::RemoteObjectProxy.new 345, io
|
39
|
+
|
40
|
+
proxy.send_remote(:method) { "lambda { true }" }
|
41
|
+
end
|
42
|
+
|
11
43
|
it "should return the deserialized return value" do
|
12
44
|
io = stub 'io', :gets => "[:return, :okay]\n", :<< => nil
|
13
45
|
proxy = Culerity::RemoteObjectProxy.new 345, io
|
@@ -15,7 +47,7 @@ describe Culerity::RemoteObjectProxy do
|
|
15
47
|
end
|
16
48
|
|
17
49
|
it "should raise the received exception" do
|
18
|
-
io = stub 'io', :gets =>
|
50
|
+
io = stub 'io', :gets => %Q{[:exception, "RuntimeError", "test exception", []]}, :<< => nil
|
19
51
|
proxy = Culerity::RemoteObjectProxy.new 345, io
|
20
52
|
lambda {
|
21
53
|
proxy.goto '/home'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caius-culerity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|