watir-rails 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8edc0290a0d14704fb728ea56c21794d20ac317
4
- data.tar.gz: 4f863b275e8f3c46c4876d25126dce28bdb460b0
3
+ metadata.gz: 31008115d6a0ed1cd3554b257f0d28237ca3449d
4
+ data.tar.gz: a44a67b33ffef400006f8a3a36770e58af34ae72
5
5
  SHA512:
6
- metadata.gz: 9b31e10fc8944ad4ab387d8e10e10d5f0d1b1c8d8389e1614228d0fc1690d5ac23147a2e0ca3fec7cafcda7597bd0d25b05de64af49dfab88a9fe1b6aa0b06df
7
- data.tar.gz: 835e47a998c9d9d4e0d3fe956d6d3ec9e2062719dcbd90a3662dcc977eca43e2147d9d0e8468b69d7580bc3bfd0c70b923c4a1ca3f234182cb18b8c762023743
6
+ metadata.gz: 29ddc148bfe23b5bb9adb807a18fafb15a696de78b9cb462e90348580ac076ca157709f6ee6ed900aad58139e60a26d1fc7414b20e64eec78ef4dbcf404039db
7
+ data.tar.gz: 1a2a9bcc5d9c6546e4735f895057021de0b21b20bd1aa628d35d0f73bee5cda907ea33946a1a437e077b32fe8d0102a727d0d2879ddbc4ef24803feee7bb9576
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - ruby-head
5
+ notifications:
6
+ recipients:
7
+ - jarmo.p@gmail.com
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: ruby-head
11
+
data/CHANGES.md ADDED
@@ -0,0 +1,5 @@
1
+ ### 1.0.0 - 2013/10/05
2
+
3
+ * Add watir as a dependency to make it possible to use watir-classic too.
4
+ * Add specs to keep the quality high.
5
+ * Documentation fixes.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "coveralls", require: false
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Watir::Rails
2
+ [![Gem Version](https://badge.fury.io/rb/watir-rails.png)](http://badge.fury.io/rb/watir-rails)
3
+ [![Build Status](https://api.travis-ci.org/watir/watir-rails.png)](http://travis-ci.org/watir/watir-rails)
4
+ [![Coverage](https://coveralls.io/repos/watir/watir-rails/badge.png?branch=master)](https://coveralls.io/r/watir/watir-rails)
2
5
 
3
- This gem adds the [Watir](http://github.com/watir/watir) usage support when writing integration tests in Rails.
6
+ This gem makes the [Watir](https://github.com/watir/watir) work with Rails.
4
7
 
5
8
 
6
9
  ## Installation
@@ -9,7 +12,7 @@ Add this code to your Gemfile:
9
12
 
10
13
  ```ruby
11
14
  group :test do
12
- gem 'watir-rails'
15
+ gem "watir-rails"
13
16
  end
14
17
  ```
15
18
 
@@ -34,7 +37,7 @@ This feature is only enabled when `config.action_dispatch.show_exceptions` is se
34
37
  You can disable it in watir-rails by ignoring exceptions:
35
38
 
36
39
  ```ruby
37
- Watir::Rails.ignore_exceptions = false
40
+ Watir::Rails.ignore_exceptions = true
38
41
  ```
39
42
 
40
43
  ## Limitations
@@ -56,11 +59,3 @@ The problem is probably caused by the fact that [WIN32OLE overwrites Thread#init
56
59
  ## License
57
60
 
58
61
  See [LICENSE](https://github.com/watir/watir-rails/blob/master/LICENSE).
59
-
60
- ## Contributing
61
-
62
- 1. Fork it
63
- 2. Create your feature branch (`git checkout -b my-new-feature`)
64
- 3. Commit your changes (`git commit -am 'Added some feature'`)
65
- 4. Push to the branch (`git push origin my-new-feature`)
66
- 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,3 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
6
+ task :release => :spec
7
+
2
8
  require "yard"
3
9
  YARD::Rake::YardocTask.new
data/lib/watir/browser.rb CHANGED
@@ -7,32 +7,60 @@ module Watir
7
7
  # Will start Rails instance for Watir automatically and then invoke the
8
8
  # original Watir::Browser#initialize method.
9
9
  def initialize(*args)
10
- Rails.boot
11
- original_initialize *args
12
- add_checker do
13
- if error = Rails.error
14
- Rails.error = nil
15
- raise error
16
- end
17
- end unless Rails.ignore_exceptions?
10
+ initialize_rails_with_watir *args
18
11
  end
19
12
 
20
- # @private
21
- alias_method :original_goto, :goto
22
-
23
13
  # Opens the url with the browser instance.
24
14
  # Will add {Rails.host} and {Rails.port} to the url when path is specified.
25
15
  #
26
- # @example Open the regular url:
16
+ # @example Go to the regular url:
27
17
  # browser.goto "http://google.com"
28
18
  #
29
- # @example Open the controller path:
19
+ # @example Go to the controller path:
30
20
  # browser.goto home_path
31
21
  #
32
22
  # @param [String] url URL to be navigated to.
33
23
  def goto(url)
34
24
  url = "http://#{Rails.host}:#{Rails.port}#{url}" unless url =~ %r{^(about|data|https?):}i
35
- original_goto url
25
+ _new_goto url
26
+ end
27
+
28
+ private
29
+
30
+ def override_and_preserve_original_methods(*method_names, &block)
31
+ method_names.each do |method_name|
32
+ next if respond_to? "_original_#{method_name}", true
33
+ self.class.send :alias_method, "_original_#{method_name}", method_name
34
+ end
35
+
36
+ result = block.call
37
+
38
+ method_names.each do |method_name|
39
+ next if respond_to? "_new_#{method_name}", true
40
+ self.class.send :alias_method, "_new_#{method_name}", method_name
41
+
42
+ self.class.send :define_method, method_name do |*args|
43
+ send("_original_#{method_name}", *args)
44
+ #send("_new_#{method_name}", *args)
45
+ end
46
+ end
47
+
48
+ result
49
+ end
50
+
51
+ def initialize_rails_with_watir(*args)
52
+ Rails.boot
53
+ override_and_preserve_original_methods(:goto) { original_initialize *args }
54
+ add_exception_checker unless Rails.ignore_exceptions?
55
+ end
56
+
57
+ def add_exception_checker
58
+ add_checker do
59
+ if error = Rails.error
60
+ Rails.error = nil
61
+ raise error
62
+ end
63
+ end
36
64
  end
37
65
  end
38
66
  end
data/lib/watir/rails.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'rack'
4
- require 'watir-webdriver'
1
+ require "uri"
2
+ require "net/http"
3
+ require "rack"
4
+ require "watir"
5
+ require "rails"
5
6
  require File.expand_path("browser.rb", File.dirname(__FILE__))
6
7
  require File.expand_path("rails/middleware.rb", File.dirname(__FILE__))
7
8
 
@@ -23,14 +24,13 @@ module Watir
23
24
  run_default_server @middleware, @port
24
25
  end
25
26
 
26
- Timeout.timeout(60) { @server_thread.join(0.1) until running? }
27
+ Timeout.timeout(boot_timeout) { @server_thread.join(0.1) until running? }
27
28
  end
28
29
  rescue TimeoutError
29
- raise "Rails Rack application timed out during boot"
30
+ raise TimeoutError, "Rails Rack application timed out during boot"
30
31
  end
31
32
 
32
- # Host for Rails app under test. When not set via {.host=} then
33
- # {.local_host} is used.
33
+ # Host for Rails app under test. Default is {.local_host}.
34
34
  #
35
35
  # @return [String] Host for Rails app under test.
36
36
  def host
@@ -119,6 +119,10 @@ module Watir
119
119
 
120
120
  private
121
121
 
122
+ def boot_timeout
123
+ 60
124
+ end
125
+
122
126
  def find_available_port
123
127
  server = TCPServer.new(local_host, 0)
124
128
  server.addr[1]
data/lib/watir/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Watir
2
2
  class Rails
3
- VERSION = "0.1.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,15 @@
1
+ require "simplecov"
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start
6
+
7
+ # Make sure that fake watir gems are loaded for specs.
8
+ $LOAD_PATH.unshift File.expand_path("support", File.dirname(__FILE__))
9
+
10
+ require "watir/rails"
11
+
12
+ RSpec.configure do |c|
13
+ c.color = true
14
+ c.order = :random
15
+ end
@@ -0,0 +1,8 @@
1
+ # Needed to simulate watir driver's gem (watir-webdriver or watir-classic).
2
+
3
+ module Watir
4
+ class Browser
5
+ def goto(*args)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # Needed to simulate watir gem.
2
+
3
+ module Watir
4
+ class Browser
5
+ def initialize(*args)
6
+ require File.expand_path("fake_browser_with_goto", File.dirname(__FILE__))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe Watir::Browser do
4
+ before { Watir::Rails.stub(ignore_exceptions?: true) }
5
+
6
+ context "#initialize" do
7
+ it "starts Rails before opening the browser" do
8
+ Watir::Rails.should_receive(:boot)
9
+ Watir::Browser.any_instance.should_receive(:original_initialize).and_call_original
10
+
11
+ Watir::Browser.new
12
+ end
13
+
14
+ it "does not add Exception checker when exceptions are ignored" do
15
+ Watir::Rails.stub(ignore_exceptions?: true, boot: nil)
16
+
17
+ Watir::Browser.any_instance.should_not_receive(:add_exception_checker)
18
+ Watir::Browser.new
19
+ end
20
+
21
+ it "adds Exception checker when exceptions are not ignored" do
22
+ Watir::Rails.stub(ignore_exceptions?: false, boot: nil)
23
+
24
+ Watir::Browser.any_instance.should_receive(:add_exception_checker)
25
+ Watir::Browser.new
26
+ end
27
+ end
28
+
29
+ context "#goto" do
30
+ before do
31
+ Watir::Rails.stub(host: "foo.com", port: 42, boot: nil)
32
+ end
33
+
34
+ let(:browser) { Watir::Browser.new }
35
+
36
+ it "uses Rails for paths specified as an url" do
37
+ browser.should_receive(:_new_goto).with("http://foo.com:42/foo/bar")
38
+ browser.goto("/foo/bar")
39
+ end
40
+
41
+ it "does not alter url with http:// scheme" do
42
+ browser.should_receive(:_new_goto).with("http://baz.org/lol")
43
+ browser.goto("http://baz.org/lol")
44
+ end
45
+
46
+ it "does not alter url with https:// scheme" do
47
+ browser.should_receive(:_new_goto).with("https://baz.org/lol")
48
+ browser.goto("https://baz.org/lol")
49
+ end
50
+
51
+ it "does not alter about:urls" do
52
+ browser.should_receive(:_new_goto).with("about:url")
53
+ browser.goto("about:url")
54
+ end
55
+
56
+ it "does not alter data:urls" do
57
+ browser.should_receive(:_new_goto).with("data:url")
58
+ browser.goto("data:url")
59
+ end
60
+
61
+ it "alters the unknown urls" do
62
+ browser.should_receive(:_new_goto).with("http://foo.com:42/xxx:yyy")
63
+ browser.goto("http://foo.com:42/xxx:yyy")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe Watir::Rails::Middleware do
4
+ let(:app) { double("app") }
5
+ let(:middleware) { described_class.new app }
6
+
7
+ context "#call" do
8
+ it "/__identify__ returns app id" do
9
+ app.should_not_receive(:call)
10
+ middleware.call("PATH_INFO" => "/__identify__").should == [200, {}, [app.object_id.to_s]]
11
+ end
12
+
13
+ it "other requests are forwarded to the app" do
14
+ env = {}
15
+ app.should_receive(:call).with(env)
16
+ middleware.call(env)
17
+ end
18
+
19
+ it "errors are stored and re-raised" do
20
+ error = RuntimeError.new
21
+ app.stub(:call).and_raise error
22
+
23
+ expect {
24
+ middleware.call({})
25
+ }.to raise_error(error)
26
+
27
+ middleware.error.should == error
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,127 @@
1
+ require "spec_helper"
2
+
3
+ describe Watir::Rails do
4
+ before do
5
+ described_class.stub(:warn)
6
+ described_class.ignore_exceptions = false
7
+ described_class.instance_eval { @middleware = @port = @server_thread = @host = @app = nil }
8
+ end
9
+
10
+ context ".boot" do
11
+ it "starts the server unless already running" do
12
+ described_class.stub(app: double("app"), find_available_port: 42)
13
+ described_class.should_receive(:running?).twice.and_return(false, true)
14
+ described_class.should_receive(:run_default_server).once
15
+
16
+ described_class.boot
17
+ end
18
+
19
+ it "does nothing if server is already running" do
20
+ described_class.stub(app: double("app"), find_available_port: 42)
21
+ described_class.should_receive(:running?).once.and_return(true)
22
+ described_class.should_not_receive(:run_default_server)
23
+
24
+ described_class.boot
25
+ end
26
+
27
+ it "raises an error if Rails won't boot with timeout" do
28
+ described_class.stub(app: double("app"), find_available_port: 42, boot_timeout: 0.01)
29
+ described_class.should_receive(:running?).at_least(:twice).and_return(false)
30
+ described_class.should_receive(:run_default_server)
31
+
32
+ expect {
33
+ described_class.boot
34
+ }.to raise_error(Timeout::Error)
35
+ end
36
+ end
37
+
38
+ context ".host" do
39
+ it "@host if specified" do
40
+ described_class.host = "my_host"
41
+ described_class.host.should == "my_host"
42
+ end
43
+
44
+ it "local_host if @host is not specified" do
45
+ described_class.host = nil
46
+ described_class.host.should == "127.0.0.1"
47
+ end
48
+ end
49
+
50
+ context ".ignore_exceptions?" do
51
+ it "true if @ignore_exceptions is set to true" do
52
+ described_class.ignore_exceptions = true
53
+ described_class.should be_ignore_exceptions
54
+ end
55
+
56
+ it "true if Rails.action_dispatch.show_exceptions is set to true for older Rails" do
57
+ described_class.stub(legacy_rails?: true)
58
+ described_class.ignore_exceptions = false
59
+ ::Rails.stub_chain(:configuration, :action_dispatch, :show_exceptions).and_return(true)
60
+
61
+ described_class.should be_ignore_exceptions
62
+ end
63
+
64
+ it "true if Rails.action_dispatch.show_exceptions is set to true for Rails 3" do
65
+ described_class.stub(legacy_rails?: false)
66
+ described_class.ignore_exceptions = false
67
+ ::Rails.stub_chain(:application, :config, :action_dispatch, :show_exceptions).and_return(true)
68
+
69
+ described_class.should be_ignore_exceptions
70
+ end
71
+
72
+ it "false if Rails.action_dispatch.show_exceptions is set to false for older Rails" do
73
+ described_class.stub(legacy_rails?: true)
74
+ described_class.ignore_exceptions = false
75
+ ::Rails.stub_chain(:application, :config, :action_dispatch, :show_exceptions).and_return(false)
76
+
77
+ described_class.should_not be_ignore_exceptions
78
+ end
79
+
80
+ it "true if Rails.action_dispatch.show_exceptions is set to false for Rails 3" do
81
+ described_class.stub(legacy_rails?: false)
82
+ described_class.ignore_exceptions = false
83
+ ::Rails.stub_chain(:application, :config, :action_dispatch, :show_exceptions).and_return(false)
84
+
85
+ described_class.should_not be_ignore_exceptions
86
+ end
87
+ end
88
+
89
+ context ".running?" do
90
+ it "false if server thread is running" do
91
+ fake_thread = double("thread", join: :still_running)
92
+ described_class.instance_variable_set(:@server_thread, fake_thread)
93
+
94
+ described_class.should_not be_running
95
+ end
96
+
97
+ it "false if server cannot be accessed" do
98
+ fake_thread = double("thread", join: nil)
99
+ described_class.instance_variable_set(:@server_thread, fake_thread)
100
+
101
+ Net::HTTP.should_receive(:start).and_raise Errno::ECONNREFUSED
102
+ described_class.should_not be_running
103
+ end
104
+
105
+ it "false if server response is not success" do
106
+ fake_thread = double("thread", join: nil)
107
+ described_class.instance_variable_set(:@server_thread, fake_thread)
108
+ app = double("app")
109
+ described_class.instance_variable_set(:@app, app)
110
+
111
+ response = double(Net::HTTPSuccess, is_a?: false)
112
+ Net::HTTP.should_receive(:start).and_return response
113
+ described_class.should_not be_running
114
+ end
115
+
116
+ it "true if server response is success" do
117
+ fake_thread = double("thread", join: nil)
118
+ described_class.instance_variable_set(:@server_thread, fake_thread)
119
+ app = double("app")
120
+ described_class.instance_variable_set(:@app, app)
121
+
122
+ response = double(Net::HTTPSuccess, is_a?: true, body: app.object_id.to_s)
123
+ Net::HTTP.should_receive(:start).and_return response
124
+ described_class.should be_running
125
+ end
126
+ end
127
+ end
data/watir-rails.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/watir/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Jarmo Pertman"]
6
6
  gem.email = ["jarmo.p@gmail.com"]
7
- gem.description = %q{Add support for Watir (http://github.com/watir/watir) in Rails.}
8
- gem.summary = %q{Add support for Watir (http://github.com/watir/watir) in Rails.}
7
+ gem.description = %q{Use Watir (http://github.com/watir/watir) in Rails.}
8
+ gem.summary = %q{Use Watir (http://github.com/watir/watir) in Rails.}
9
9
  gem.homepage = "http://github.com/watir/watir-rails"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -17,8 +17,9 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "rack"
19
19
  gem.add_dependency "rails"
20
- gem.add_dependency "watir-webdriver"
20
+ gem.add_dependency "watir", "~> 5.0"
21
21
 
22
22
  gem.add_development_dependency "yard"
23
23
  gem.add_development_dependency "redcarpet"
24
+ gem.add_development_dependency "rspec", "~>2.0"
24
25
  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.1.2
4
+ version: 1.0.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-07-13 00:00:00.000000000 Z
11
+ date: 2013-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: watir-webdriver
42
+ name: watir
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '5.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,21 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Add support for Watir (http://github.com/watir/watir) in Rails.
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ description: Use Watir (http://github.com/watir/watir) in Rails.
84
98
  email:
85
99
  - jarmo.p@gmail.com
86
100
  executables: []
@@ -88,7 +102,9 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - .gitignore
105
+ - .travis.yml
91
106
  - .yardopts
107
+ - CHANGES.md
92
108
  - Gemfile
93
109
  - LICENSE
94
110
  - README.md
@@ -97,6 +113,12 @@ files:
97
113
  - lib/watir/rails.rb
98
114
  - lib/watir/rails/middleware.rb
99
115
  - lib/watir/version.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/fake_browser_with_goto.rb
118
+ - spec/support/watir.rb
119
+ - spec/watir/browser_spec.rb
120
+ - spec/watir/rails/middleware_spec.rb
121
+ - spec/watir/rails_spec.rb
100
122
  - watir-rails.gemspec
101
123
  homepage: http://github.com/watir/watir-rails
102
124
  licenses: []
@@ -117,9 +139,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
139
  version: '0'
118
140
  requirements: []
119
141
  rubyforge_project:
120
- rubygems_version: 2.0.3
142
+ rubygems_version: 2.0.7
121
143
  signing_key:
122
144
  specification_version: 4
123
- summary: Add support for Watir (http://github.com/watir/watir) in Rails.
124
- test_files: []
145
+ summary: Use Watir (http://github.com/watir/watir) in Rails.
146
+ test_files:
147
+ - spec/spec_helper.rb
148
+ - spec/support/fake_browser_with_goto.rb
149
+ - spec/support/watir.rb
150
+ - spec/watir/browser_spec.rb
151
+ - spec/watir/rails/middleware_spec.rb
152
+ - spec/watir/rails_spec.rb
125
153
  has_rdoc: