akephalos2 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ else
8
8
  require 'akephalos/htmlunit/ext/http_method'
9
9
  require 'akephalos/htmlunit/ext/confirm_handler'
10
10
 
11
+ require 'akephalos/exception_handling_delegators'
11
12
  require 'akephalos/page'
12
13
  require 'akephalos/node'
13
14
 
@@ -21,6 +22,16 @@ else
21
22
  # allowing navigation.
22
23
  class Client
23
24
 
25
+ class << self
26
+
27
+ alias_method :new_orig, :new
28
+
29
+ def new(*args)
30
+ ExceptionConvertingDelegator.new(new_orig(*args), "NativeException", RuntimeError)
31
+ end
32
+
33
+ end
34
+
24
35
  # @return [Akephalos::Page] the current page
25
36
  attr_reader :page
26
37
 
@@ -0,0 +1,66 @@
1
+ require 'delegate'
2
+
3
+ ##
4
+ # This class can be used to wrap an object so that any exceptions raised by the object's methods are recued and passed to a specified exception_handler block
5
+ #
6
+ class ExceptionCatchingDelegator < SimpleDelegator
7
+
8
+ ##
9
+ # * *Args* :
10
+ # - ++ -> delgate - object to be wrapped
11
+ # - ++ -> exception_handler - block to handle rescued exeptions (will be called with yield(exception))
12
+ #
13
+ def initialize(delegate, exception_handler)
14
+ super(delegate)
15
+ @exception_handler = exception_handler
16
+ end
17
+
18
+ ##
19
+ # Override of method_missing to rescue exceptions and pass them to the exception_handler
20
+ #
21
+ def method_missing(m, *args, &block)
22
+ begin
23
+ return super(m, *args, &block)
24
+ rescue Exception => exception
25
+ @exception_handler.yield(exception)
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ ##
32
+ # This class can be used to wrap an object so that exceptions matching a given type are rescued and then raised as another type.
33
+ #
34
+ # This kind of exception converting is most of use when dealing with exceptions passed across DRb where a remote
35
+ # exception class may not exist on the client-side.
36
+ #
37
+ class ExceptionConvertingDelegator < ExceptionCatchingDelegator
38
+
39
+ ##
40
+ # * *Args* :
41
+ # - ++ -> delgate - object to be wrapped
42
+ # - ++ -> exception_type_to_catch - an exception class or name of an exception class that will be used to match (in a regular-expression sense) the name of exceptions thrown by the delegate's methods
43
+ # - ++ -> exception_type_to_throw - the exception class that will be used to create and raise a new exception
44
+ #
45
+ def initialize(delegate, exception_type_to_catch = Exception, exception_type_to_throw = RuntimeError)
46
+
47
+ handler = lambda do |e|
48
+
49
+ raise e unless e.class.name =~ Regexp.new(exception_type_to_catch.to_s)
50
+
51
+ # Create and raise a RuntimeError
52
+ message = e.class.name
53
+ unless e.message.nil? || e.message.size == 0
54
+ message << " "
55
+ message << e.message
56
+ end
57
+ new_exception = exception_type_to_throw.new(message)
58
+ new_exception.set_backtrace(e.backtrace)
59
+ raise new_exception
60
+ end
61
+
62
+ super(delegate, handler)
63
+
64
+ end
65
+
66
+ end
@@ -3,6 +3,17 @@ module Akephalos
3
3
  # Akephalos::Node wraps HtmlUnit's DOMNode class, providing a simple API for
4
4
  # interacting with an element on the page.
5
5
  class Node
6
+
7
+ class << self
8
+
9
+ alias_method :new_orig, :new
10
+
11
+ def new(*args)
12
+ ExceptionConvertingDelegator.new(new_orig(*args), "NativeException", RuntimeError)
13
+ end
14
+
15
+ end
16
+
6
17
  # @param [HtmlUnit::DOMNode] node
7
18
  def initialize(node)
8
19
  @nodes = []
@@ -3,6 +3,17 @@ module Akephalos
3
3
  # Akephalos::Page wraps HtmlUnit's HtmlPage class, exposing an API for
4
4
  # interacting with a page in the browser.
5
5
  class Page
6
+
7
+ class << self
8
+
9
+ alias_method :new_orig, :new
10
+
11
+ def new(*args)
12
+ ExceptionConvertingDelegator.new(new_orig(*args), "NativeException", RuntimeError)
13
+ end
14
+
15
+ end
16
+
6
17
  # @param [HtmlUnit::HtmlPage] page
7
18
  def initialize(page)
8
19
  @nodes = []
@@ -1,10 +1,6 @@
1
1
  require 'socket'
2
2
  require 'drb/drb'
3
3
 
4
- # We need to define our own NativeException class for the cases when a native
5
- # exception is raised by the JRuby DRb server.
6
- class NativeException < StandardError; end
7
-
8
4
  module Akephalos
9
5
 
10
6
  # The +RemoteClient+ class provides an interface to an +Akephalos::Client+
@@ -1,3 +1,3 @@
1
1
  module Akephalos #:nodoc
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akephalos2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-12-23 00:00:00.000000000 Z
13
+ date: 2012-04-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capybara
17
- requirement: &70282950353040 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70282950353040
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: rake
28
- requirement: &70282950368980 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70282950368980
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: jruby-jars
39
- requirement: &70282950368360 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :runtime
46
56
  prerelease: false
47
- version_requirements: *70282950368360
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: sinatra
50
- requirement: &70282950367560 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70282950367560
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: rspec
61
- requirement: &70282950367120 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,7 +86,12 @@ dependencies:
66
86
  version: '0'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70282950367120
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  description: Headless Browser for Integration Testing with Capybara
71
96
  email:
72
97
  - bj.schaefer@gmail.com
@@ -83,6 +108,7 @@ files:
83
108
  - lib/akephalos/configuration.rb
84
109
  - lib/akephalos/console.rb
85
110
  - lib/akephalos/cucumber.rb
111
+ - lib/akephalos/exception_handling_delegators.rb
86
112
  - lib/akephalos/htmlunit/ext/confirm_handler.rb
87
113
  - lib/akephalos/htmlunit/ext/http_method.rb
88
114
  - lib/akephalos/htmlunit.rb
@@ -95,7 +121,8 @@ files:
95
121
  - lib/akephalos.rb
96
122
  - README.md
97
123
  - MIT_LICENSE
98
- - bin/akephalos
124
+ - !binary |-
125
+ YmluL2FrZXBoYWxvcw==
99
126
  homepage: https://github.com/Nerian/akephalos2
100
127
  licenses: []
101
128
  post_install_message:
@@ -109,15 +136,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
136
  - - ! '>='
110
137
  - !ruby/object:Gem::Version
111
138
  version: '0'
139
+ segments:
140
+ - 0
141
+ hash: -2791345104495626226
112
142
  required_rubygems_version: !ruby/object:Gem::Requirement
113
143
  none: false
114
144
  requirements:
115
145
  - - ! '>='
116
146
  - !ruby/object:Gem::Version
117
147
  version: '0'
148
+ segments:
149
+ - 0
150
+ hash: -2791345104495626226
118
151
  requirements: []
119
152
  rubyforge_project:
120
- rubygems_version: 1.8.10
153
+ rubygems_version: 1.8.21
121
154
  signing_key:
122
155
  specification_version: 3
123
156
  summary: Headless Browser for Integration Testing with Capybara