drnic-culerity 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@ coverage
2
2
  rdoc
3
3
  pkg
4
4
  tmp
5
+ *.sw?
6
+ *.gem
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 0
3
2
  :minor: 2
4
- :patch: 1
3
+ :patch: 2
4
+ :major: 0
data/culerity.gemspec CHANGED
@@ -1,15 +1,12 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{culerity}
8
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Alexander Lang"]
12
- s.date = %q{2009-08-15}
9
+ s.date = %q{2009-08-16}
13
10
  s.description = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
14
11
  s.email = %q{alex@upstream-berlin.com}
15
12
  s.extra_rdoc_files = [
@@ -52,7 +49,7 @@ Gem::Specification.new do |s|
52
49
  s.homepage = %q{http://github.com/langalex/culerity}
53
50
  s.rdoc_options = ["--charset=UTF-8"]
54
51
  s.require_paths = ["lib"]
55
- s.rubygems_version = %q{1.3.5}
52
+ s.rubygems_version = %q{1.3.3}
56
53
  s.summary = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
57
54
  s.test_files = [
58
55
  "spec/celerity_server_spec.rb",
@@ -7,11 +7,12 @@ module Culerity
7
7
 
8
8
  def initialize(_in, _out)
9
9
  @proxies = {}
10
- @browser_options = {}
11
-
10
+ @browsers = []
11
+
12
12
  while(true)
13
13
  call = eval _in.gets.to_s.strip
14
14
  return if call == ["_exit_"]
15
+ next(close_browsers) if call == ["_close_browsers_"]
15
16
  unless call.nil?
16
17
  begin
17
18
  # check if last arg is a block
@@ -27,6 +28,7 @@ module Culerity
27
28
  _out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
28
29
  end
29
30
  end
31
+
30
32
  end
31
33
 
32
34
  end
@@ -37,13 +39,27 @@ module Culerity
37
39
  @browser_options = options
38
40
  end
39
41
 
40
- def browser
41
- @browser ||= Celerity::Browser.new @browser_options || {}
42
+ def new_browser(options, number = nil)
43
+ number ||= @browsers.size
44
+ @browsers[number] = Celerity::Browser.new(options || @browser_options || {})
45
+ "browser#{number}"
46
+ end
47
+
48
+ def close_browsers
49
+ @browsers.each { |browser| browser.close }
50
+ @browsers = []
51
+ end
52
+
53
+ def browser(number)
54
+ unless @browsers[number]
55
+ new_browser(nil, number)
56
+ end
57
+ @browsers[number]
42
58
  end
43
59
 
44
60
  def target(object_id)
45
- if object_id == 'browser'
46
- browser
61
+ if object_id =~ /browser(\d+)/
62
+ browser($1.to_i)
47
63
  elsif object_id == 'celerity'
48
64
  self
49
65
  else
@@ -62,4 +78,4 @@ module Culerity
62
78
  end
63
79
  end
64
80
  end
65
- end
81
+ end
@@ -3,11 +3,8 @@ module Culerity
3
3
  class RemoteBrowserProxy < RemoteObjectProxy
4
4
  def initialize(io, browser_options = {})
5
5
  @io = io
6
- unless browser_options.empty?
7
- @remote_object_id = 'celerity'
8
- configure_browser browser_options
9
- @remote_object_id = nil
10
- end
6
+ @remote_object_id = "celerity".inspect
7
+ @remote_object_id = new_browser(browser_options).inspect
11
8
  end
12
9
 
13
10
  #
@@ -55,11 +52,7 @@ module Culerity
55
52
  self.send_remote(:remove_listener, :confirm) { blk }
56
53
  end
57
54
 
58
- private
59
-
60
- def remote_object_id
61
- (@remote_object_id || 'browser').inspect
62
- end
63
55
  end
64
56
 
65
- end
57
+
58
+ end
@@ -73,4 +73,4 @@ module Culerity
73
73
  @remote_object_id
74
74
  end
75
75
  end
76
- end
76
+ end
data/lib/culerity.rb CHANGED
@@ -3,8 +3,19 @@ require File.dirname(__FILE__) + '/culerity/remote_browser_proxy'
3
3
 
4
4
  module Culerity
5
5
 
6
+ module ServerCommands
7
+ def exit_server
8
+ self << '["_exit_"]'
9
+ close
10
+ end
11
+
12
+ def close_browsers
13
+ self.puts '["_close_browsers_"]'
14
+ end
15
+ end
16
+
6
17
  def self.run_server
7
- IO.popen("jruby #{__FILE__}", 'r+')
18
+ IO.popen("jruby #{__FILE__}", 'r+').extend(ServerCommands)
8
19
 
9
20
  # open the two pipes that were created below
10
21
  # while(!File.exists?("tmp/culerity_in.pipe"))
@@ -6,18 +6,45 @@ describe Culerity::CelerityServer do
6
6
  Celerity::Browser.stub!(:new).and_return(@browser)
7
7
  end
8
8
 
9
- it "should pass the method call to the selerity browser" do
9
+ it "should pass the method call to the celerity browser" do
10
10
  @browser.should_receive(:goto).with('/homepage')
11
11
  _in = stub 'in'
12
- _in.stub!(:gets).and_return("[\"browser\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
12
+ _in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
13
13
  _out = stub 'out', :<< => nil
14
14
  Culerity::CelerityServer.new(_in, _out)
15
15
  end
16
+
17
+ it "should return the browser id when a new browser is requested" do
18
+ _in = stub 'in'
19
+ _in.stub!(:gets).and_return("[\"celerity\", \"new_browser\", {}]\n", "[\"_exit_\"]\n")
20
+ _out = stub 'out'
21
+ _out.should_receive(:<<).with("[:return, \"browser0\"]\n")
22
+ Culerity::CelerityServer.new(_in, _out)
23
+ end
24
+
25
+ it "should create a new browser with the provided options" do
26
+ _in = stub 'in'
27
+ _in.stub!(:gets).and_return("[\"celerity\", \"new_browser\", {:browser => :firefox}]\n", "[\"_exit_\"]\n")
28
+ Celerity::Browser.should_receive(:new).with(:browser => :firefox)
29
+ Culerity::CelerityServer.new(_in, stub.as_null_object)
30
+ end
31
+
32
+ it "should create multiple browsers and return the appropriate id for each" do
33
+ _in = stub 'in'
34
+ _in.stub!(:gets).and_return("[\"celerity\", \"new_browser\", {}]\n", "[\"celerity\", \"new_browser\", {}]\n", "[\"_exit_\"]\n")
35
+ Celerity::Browser.should_receive(:new).twice
36
+ _out = stub 'out'
37
+ _out.should_receive(:<<).with("[:return, \"browser0\"]\n").ordered
38
+ _out.should_receive(:<<).with("[:return, \"browser1\"]\n").ordered
39
+ Culerity::CelerityServer.new(_in, _out)
40
+
41
+ end
42
+
16
43
 
17
44
  it "should send back the return value of the call" do
18
45
  @browser.stub!(:goto).and_return(true)
19
46
  _in = stub 'in'
20
- _in.stub!(:gets).and_return("[\"browser\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
47
+ _in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
21
48
  _out = stub 'out'
22
49
  _out.should_receive(:<<).with("[:return, true]\n")
23
50
  Culerity::CelerityServer.new(_in, _out)
@@ -34,7 +61,7 @@ describe Culerity::CelerityServer do
34
61
  it "should send back a proxy if the return value is not a string, number, nil or boolean" do
35
62
  @browser.stub!(:goto).and_return(stub('123', :object_id => 456))
36
63
  _in = stub 'in'
37
- _in.stub!(:gets).and_return("[\"browser\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
64
+ _in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
38
65
  _out = stub 'out'
39
66
  _out.should_receive(:<<).with("[:return, Culerity::RemoteObjectProxy.new(456, @io)]\n")
40
67
  Culerity::CelerityServer.new(_in, _out)
@@ -44,24 +71,17 @@ describe Culerity::CelerityServer do
44
71
  proxy = stub('123', :object_id => 456)
45
72
  @browser.stub!(:goto).and_return(proxy)
46
73
  _in = stub 'in'
47
- _in.stub!(:gets).and_return("[\"browser\", \"goto\", \"/homepage\"]\n", "[456, \"goto_2\", \"1\"]", "[\"_exit_\"]\n")
74
+ _in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[456, \"goto_2\", \"1\"]", "[\"_exit_\"]\n")
48
75
  _out = stub 'out', :<< => nil
49
76
  proxy.should_receive(:goto_2).with('1')
50
77
  Culerity::CelerityServer.new(_in, _out)
51
78
  end
52
-
53
- it "should configure the browser" do
54
- _in = stub 'in'
55
- _in.stub!(:gets).and_return('["celerity", "configure_browser", {:browser=>:firefox}]' + "\n", '["browser", "goto", "/homepage"]' + "\n", "[\"_exit_\"]\n")
56
- Celerity::Browser.should_receive(:new).with(:browser => :firefox)
57
- Culerity::CelerityServer.new(_in, stub.as_null_object)
58
- end
59
-
79
+
60
80
  it "should pass multiple method calls" do
61
81
  @browser.should_receive(:goto).with('/homepage')
62
82
  @browser.should_receive(:goto).with('/page2')
63
83
  _in = stub 'in'
64
- _in.stub!(:gets).and_return("[\"browser\", \"goto\", \"/homepage\"]\n", "[\"browser\", \"goto\", \"/page2\"]\n", "[\"_exit_\"]\n")
84
+ _in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"browser0\", \"goto\", \"/page2\"]\n", "[\"_exit_\"]\n")
65
85
  _out = stub 'out', :<< => nil
66
86
  Culerity::CelerityServer.new(_in, _out)
67
87
  end
@@ -69,9 +89,9 @@ describe Culerity::CelerityServer do
69
89
  it "should return an exception" do
70
90
  @browser.stub!(:goto).and_raise(RuntimeError.new('test exception with "quotes"'))
71
91
  _in = stub 'in'
72
- _in.stub!(:gets).and_return("[\"browser\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
92
+ _in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
73
93
  _out = stub 'out'
74
94
  _out.should_receive(:<<).with(/^\[:exception, \"RuntimeError\", \"test exception with \\\"quotes\\\"\", \[.*\]\]\n$/)
75
95
  Culerity::CelerityServer.new(_in, _out)
76
96
  end
77
- end
97
+ end
@@ -1,10 +1,13 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe Culerity::RemoteBrowserProxy do
4
+ before(:each) do
5
+ @io = stub 'io', :gets => "[:return, \"browser0\"]", :<< => nil
6
+ end
4
7
  it "should send the serialized method call to the output" do
5
- io = stub 'io', :gets => '[return, :okay]'
6
- io.should_receive(:<<).with("[\"browser\", \"goto\", \"/homepage\"]\n")
7
- proxy = Culerity::RemoteBrowserProxy.new io
8
+ @io.should_receive(:<<).with("[\"celerity\", \"new_browser\", {}]\n").ordered
9
+ @io.should_receive(:<<).with("[\"browser0\", \"goto\", \"/homepage\"]\n").ordered
10
+ proxy = Culerity::RemoteBrowserProxy.new @io
8
11
  proxy.goto '/homepage'
9
12
  end
10
13
 
@@ -15,37 +18,37 @@ describe Culerity::RemoteBrowserProxy do
15
18
  end
16
19
 
17
20
  it "should send the brower options to the remote server" do
18
- io = stub 'io', :gets => "[:return, :okay]"
19
- io.should_receive(:<<).with('["celerity", "configure_browser", {:browser=>:firefox}]' + "\n")
21
+ io = stub 'io', :gets => "[:return, \"browser0\"]"
22
+ io.should_receive(:<<).with('["celerity", "new_browser", {:browser=>:firefox}]' + "\n")
20
23
  proxy = Culerity::RemoteBrowserProxy.new io, {:browser => :firefox}
21
24
  end
22
25
 
23
26
  it "should timeout if wait_until takes too long" do
24
- proxy = Culerity::RemoteBrowserProxy.new nil
27
+ proxy = Culerity::RemoteBrowserProxy.new @io
25
28
  lambda {
26
29
  proxy.wait_until(0.1) { false }
27
30
  }.should raise_error(Timeout::Error)
28
31
  end
29
32
 
30
33
  it "should return successfully when wait_until returns true" do
31
- proxy = Culerity::RemoteBrowserProxy.new nil
34
+ proxy = Culerity::RemoteBrowserProxy.new @io
32
35
  proxy.wait_until(0.1) { true }.should == true
33
36
  end
34
37
 
35
38
  it "should timeout if wait_while takes too long" do
36
- proxy = Culerity::RemoteBrowserProxy.new nil
39
+ proxy = Culerity::RemoteBrowserProxy.new @io
37
40
  lambda {
38
41
  proxy.wait_while(0.1) { true }
39
42
  }.should raise_error(Timeout::Error)
40
43
  end
41
44
 
42
45
  it "should return successfully when wait_while returns !true" do
43
- proxy = Culerity::RemoteBrowserProxy.new nil
46
+ proxy = Culerity::RemoteBrowserProxy.new @io
44
47
  proxy.wait_while(0.1) { false }.should == true
45
48
  end
46
49
 
47
50
  it "should accept all javascript confirmation dialogs" do
48
- proxy = Culerity::RemoteBrowserProxy.new nil
51
+ proxy = Culerity::RemoteBrowserProxy.new @io
49
52
 
50
53
  proxy.should_receive(:send_remote).with(:add_listener, :confirm).and_return(true)
51
54
  proxy.should_receive(:send_remote).with(:goto, "http://example.com").and_return(true)
@@ -56,4 +59,4 @@ describe Culerity::RemoteBrowserProxy do
56
59
  end
57
60
  end
58
61
 
59
- end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drnic-culerity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
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-08-15 00:00:00 -07:00
12
+ date: 2009-08-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency