watir-rails 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -4
- data/lib/watir/browser.rb +2 -1
- data/lib/watir/rails.rb +38 -19
- data/lib/watir/rails/middleware.rb +25 -0
- data/lib/watir/version.rb +5 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f55b4c34351f604ba80f5ce9d8cf3671f1adb8
|
4
|
+
data.tar.gz: 96797851b1429d45a2b9412bf27709f1a196c8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a315b5a51eb5a2a5aeb0303797aec1028667a9d64e6cb9dc6d71ceb143f6f04f2efe71ada441d1423abadb0d41d9b2fcab6ad19f88f3bb7fa228b36c57bb6fc
|
7
|
+
data.tar.gz: 2dbefb973b573af3da48e3fed23dd11e69b5733ae2852e828b72d37dc4c2fa36e06089ede3f41f022f29d569710d9408dada719ea4e4e75b0e08d2782108014d
|
data/README.md
CHANGED
@@ -2,27 +2,40 @@
|
|
2
2
|
|
3
3
|
This gem adds the [Watir](http://github.com/watir/watir) usage support when writing integration tests in Rails.
|
4
4
|
|
5
|
+
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this code to your Gemfile:
|
8
9
|
|
9
|
-
|
10
|
+
```ruby
|
10
11
|
group :test do
|
11
12
|
gem 'watir-rails'
|
12
13
|
end
|
13
|
-
|
14
|
+
```
|
14
15
|
|
15
16
|
## Usage
|
16
17
|
|
17
18
|
Just use Watir like you've always done in your requests/integration tests:
|
18
19
|
|
19
|
-
|
20
|
+
```ruby
|
20
21
|
browser = Watir::Browser.new
|
21
22
|
browser.goto home_path
|
22
23
|
browser.text_field(name: "first").set "Jarmo"
|
23
24
|
browser.text_field(name: "last").set "Pertman"
|
24
25
|
browser.button(name: "sign_in").click
|
25
|
-
|
26
|
+
```
|
27
|
+
|
28
|
+
### Ignore Rails Exceptions
|
29
|
+
|
30
|
+
By default, exceptions raised by Rails application will be re-raised in your tests making them to fail.
|
31
|
+
|
32
|
+
This feature is only enabled when `config.action_dispatch.show_exceptions` is set to `false` in your Rails configuration.
|
33
|
+
|
34
|
+
You can disable it in watir-rails by ignoring exceptions:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Watir::Rails.ignore_exceptions = false
|
38
|
+
```
|
26
39
|
|
27
40
|
## Limitations
|
28
41
|
|
@@ -33,6 +46,13 @@ The problem is probably caused by the fact that [WIN32OLE overwrites Thread#init
|
|
33
46
|
|
34
47
|
* When using Rails path/url helpers in your tests then always use path instead of url methods, because latter won't work!
|
35
48
|
|
49
|
+
|
50
|
+
## Contributors
|
51
|
+
|
52
|
+
* [Jarmo Pertman](https://github.com/jarmo)
|
53
|
+
* [Alex Rodionov](https://github.com/p0deje)
|
54
|
+
|
55
|
+
|
36
56
|
## License
|
37
57
|
|
38
58
|
See [LICENSE](https://github.com/watir/watir-rails/blob/master/LICENSE).
|
data/lib/watir/browser.rb
CHANGED
@@ -9,6 +9,7 @@ module Watir
|
|
9
9
|
def initialize(*args)
|
10
10
|
Rails.boot
|
11
11
|
original_initialize *args
|
12
|
+
add_checker { raise Rails.error if Rails.error } unless Rails.ignore_exceptions?
|
12
13
|
end
|
13
14
|
|
14
15
|
# @private
|
@@ -25,7 +26,7 @@ module Watir
|
|
25
26
|
#
|
26
27
|
# @param [String] url URL to be navigated to.
|
27
28
|
def goto(url)
|
28
|
-
url = "http://#{Rails.host}:#{Rails.port}#{url}" unless url =~ %r{^https
|
29
|
+
url = "http://#{Rails.host}:#{Rails.port}#{url}" unless url =~ %r{^(about|data|https?):}i
|
29
30
|
original_goto url
|
30
31
|
end
|
31
32
|
end
|
data/lib/watir/rails.rb
CHANGED
@@ -3,27 +3,14 @@ require 'net/http'
|
|
3
3
|
require 'rack'
|
4
4
|
require 'watir-webdriver'
|
5
5
|
require File.expand_path("browser.rb", File.dirname(__FILE__))
|
6
|
+
require File.expand_path("rails/middleware.rb", File.dirname(__FILE__))
|
6
7
|
|
7
8
|
module Watir
|
8
9
|
class Rails
|
9
|
-
# @private
|
10
|
-
class Middleware
|
11
|
-
def initialize(app)
|
12
|
-
@app = app
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
if env["PATH_INFO"] == "/__identify__"
|
17
|
-
[200, {}, [@app.object_id.to_s]]
|
18
|
-
else
|
19
|
-
@app.call(env)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
10
|
class << self
|
25
11
|
private :new
|
26
12
|
attr_reader :port, :middleware
|
13
|
+
attr_writer :ignore_exceptions
|
27
14
|
|
28
15
|
# Start the Rails server for tests.
|
29
16
|
# Will be called automatically by {Watir::Browser#initialize}.
|
@@ -39,7 +26,7 @@ module Watir
|
|
39
26
|
Timeout.timeout(60) { @server_thread.join(0.1) until running? }
|
40
27
|
end
|
41
28
|
rescue TimeoutError
|
42
|
-
raise "Rack application timed out during boot"
|
29
|
+
raise "Rails Rack application timed out during boot"
|
43
30
|
end
|
44
31
|
|
45
32
|
# Host for Rails app under test. When not set via {.host=} then
|
@@ -64,6 +51,33 @@ module Watir
|
|
64
51
|
"127.0.0.1"
|
65
52
|
end
|
66
53
|
|
54
|
+
# Error rescued by the middleware.
|
55
|
+
#
|
56
|
+
# @return [Exception or NilClass]
|
57
|
+
def error
|
58
|
+
@middleware.error
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check if Rails exceptions should be ignored. Defaults to false.
|
62
|
+
#
|
63
|
+
# @return [Boolean] true if exceptions should be ignored, false otherwise.
|
64
|
+
def ignore_exceptions?
|
65
|
+
unless @ignore_exceptions
|
66
|
+
show = if legacy_rails?
|
67
|
+
::Rails.configuration.action_dispatch.show_exceptions
|
68
|
+
else
|
69
|
+
::Rails.application.config.action_dispatch.show_exceptions
|
70
|
+
end
|
71
|
+
|
72
|
+
if show
|
73
|
+
warn '[WARN] "action_dispatch.show_exceptions" is set to "true", disabling watir-rails exception catcher.'
|
74
|
+
@ignore_exceptions = false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
!!@ignore_exceptions
|
79
|
+
end
|
80
|
+
|
67
81
|
# Check if Rails app under test is running.
|
68
82
|
#
|
69
83
|
# @return [Boolean] true when Rails app under test is running, false otherwise.
|
@@ -83,13 +97,14 @@ module Watir
|
|
83
97
|
#
|
84
98
|
# @return [Object] Rails Rack app.
|
85
99
|
def app
|
100
|
+
legacy = legacy_rails?
|
86
101
|
@app ||= Rack::Builder.new do
|
87
102
|
map "/" do
|
88
|
-
if
|
89
|
-
run ::Rails.application
|
90
|
-
else # Rails 2
|
103
|
+
if legacy
|
91
104
|
use ::Rails::Rack::Static
|
92
105
|
run ActionController::Dispatcher.new
|
106
|
+
else
|
107
|
+
run ::Rails.application
|
93
108
|
end
|
94
109
|
end
|
95
110
|
end.to_app
|
@@ -115,6 +130,10 @@ module Watir
|
|
115
130
|
end
|
116
131
|
end
|
117
132
|
|
133
|
+
def legacy_rails?
|
134
|
+
::Rails.version.to_f < 3.0
|
135
|
+
end
|
136
|
+
|
118
137
|
end
|
119
138
|
end
|
120
139
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Watir
|
2
|
+
class Rails
|
3
|
+
# @private
|
4
|
+
class Middleware
|
5
|
+
attr_reader :error
|
6
|
+
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env["PATH_INFO"] == "/__identify__"
|
13
|
+
[200, {}, [@app.object_id.to_s]]
|
14
|
+
else
|
15
|
+
begin
|
16
|
+
@app.call(env)
|
17
|
+
rescue => e
|
18
|
+
@error = e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/watir/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module Watir
|
2
|
-
class Rails
|
3
|
-
VERSION = "0.0
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Watir
|
2
|
+
class Rails
|
3
|
+
VERSION = "0.1.0"
|
4
|
+
end
|
5
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarmo Pertman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- Rakefile
|
96
96
|
- lib/watir/browser.rb
|
97
97
|
- lib/watir/rails.rb
|
98
|
+
- lib/watir/rails/middleware.rb
|
98
99
|
- lib/watir/version.rb
|
99
100
|
- watir-rails.gemspec
|
100
101
|
homepage: http://github.com/watir/watir-rails
|