watir-timecop 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e6a8ea36e58cd31fb47d2e58265816306e4fcc3
4
+ data.tar.gz: 093c859e3d893740361b1568c1d550aded4d05c7
5
+ SHA512:
6
+ metadata.gz: b9dcf981f1ec966646c9ba4de0836583068ed5f8e7e64b04d60179e54b88054bc9d4a8526b973556320541a8986847c1ffc7a64930ff59124d138e940c190106
7
+ data.tar.gz: 5dc475bd9058f16c9152345ff77c1f171429700ab9aac8dc05bea98787dcb6429bb927e2f039f70e12081006526e4683daa531a04e1ae3b130c01ccb408f6431
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in watir-timecop.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alex Rodionov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # watir-timecop [![Gem Version](https://badge.fury.io/rb/watir-timecop.png)](http://badge.fury.io/rb/watir-timecop) [![Build Status](https://secure.travis-ci.org/p0deje/watir-timecop.png)](http://travis-ci.org/p0deje/watir-timecop)
2
+
3
+ Makes [Timecop](https://github.com/travisjeffery/timecop) compatible with [Watir](https://github.com/watir/watir-webdriver).
4
+
5
+ The problem is that internally Watir uses `Time.now` when it waits for element presence/absence. Combined with Timecop, waiting gets broken because `Time.now` may always returns the same value. This gem implements custom timer for Watir, which uses `Timeout.timeout` instead.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```bash
12
+ gem 'watir-timecop'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ $ gem install watir-timecop
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Just require gem after Watir. That's all!
30
+
31
+ ```ruby
32
+ require 'watir-webdriver'
33
+ require 'watir-timecop'
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( http://github.com/p0deje/watir-timecop/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+ ## Copyright
45
+
46
+ Copyright (c) 2014 Alex Rodionov. See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new do |spec|
8
+ spec.rspec_opts = %w(--color)
9
+ spec.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ require 'watir-webdriver'
2
+ require 'watir-timecop/timer'
3
+
4
+ Watir::Wait.timer = Watir::Timecop::Timer.new
@@ -0,0 +1,25 @@
1
+ require 'timeout'
2
+
3
+ class Watir::Timecop::Timer
4
+
5
+ #
6
+ # Executes given block until it returns true or exceeds timeout.
7
+ # It is different from default Watir::Wait::Timer implementation
8
+ # since we use `Timeout.timeour` rather than `Time.now` to determine if
9
+ # waiting has exceeded timeout. Usage of `Time.now` is not compatible
10
+ # with Timecop gem - we may never exceed the timeout if it's stubbed.
11
+ #
12
+ # @param [Fixnum] timeout
13
+ # @yield block
14
+ # @api private
15
+ #
16
+
17
+ def wait(timeout, &block)
18
+ Timeout.timeout(timeout) do
19
+ (timeout / Watir::Wait::INTERVAL).to_i.times &block
20
+ end
21
+ rescue Timeout::Error
22
+ false
23
+ end
24
+
25
+ end # Watir::Timecop::Timer
@@ -0,0 +1,7 @@
1
+ module Watir
2
+ module Timecop
3
+
4
+ VERSION = '0.1.0'
5
+
6
+ end # Timecop
7
+ end # Watir
@@ -0,0 +1,2 @@
1
+ require 'watir-webdriver'
2
+ require 'watir-timecop'
data/spec/wait_spec.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ # extracted from https://github.com/watir/watirspec
4
+ describe Watir::Wait do
5
+ describe "#timer" do
6
+ it "returns Timecop::Timer" do
7
+ expect(Watir::Wait.timer).to be_a(Watir::Timecop::Timer)
8
+ end
9
+ end
10
+
11
+ describe "#until" do
12
+ it "waits until the block returns true" do
13
+ expect(Watir::Wait.until(0.5) { true }).to be_true
14
+ end
15
+
16
+ it "times out" do
17
+ expect {Watir::Wait.until(0.5) { false }}.to raise_error(Watir::Wait::TimeoutError)
18
+ end
19
+
20
+ it "times out with a custom message" do
21
+ expect {
22
+ Watir::Wait.until(0.5, "oops") { false }
23
+ }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
24
+ end
25
+ end
26
+
27
+ describe "#while" do
28
+ it "waits while the block returns true" do
29
+ expect(Watir::Wait.while(0.5) { false }).to be_nil
30
+ end
31
+
32
+ it "times out" do
33
+ expect {Watir::Wait.while(0.5) { true }}.to raise_error(Watir::Wait::TimeoutError)
34
+ end
35
+
36
+ it "times out with a custom message" do
37
+ expect {
38
+ Watir::Wait.while(0.5, "oops") { true }
39
+ }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'watir-timecop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "watir-timecop"
8
+ spec.version = Watir::Timecop::VERSION
9
+ spec.author = "Alex Rodionov"
10
+ spec.email = "p0deje@gmail.com"
11
+ spec.summary = "Use Watir with Timecop"
12
+ spec.description = "Watir::Wait::Timer implementation compatible with Timecop"
13
+ spec.homepage = "https://github.com/p0deje/watir-timecop"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "watir-webdriver", ">= 0.6.9"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir-timecop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Rodionov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: watir-webdriver
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Watir::Wait::Timer implementation compatible with Timecop
70
+ email: p0deje@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - lib/watir-timecop.rb
81
+ - lib/watir-timecop/timer.rb
82
+ - lib/watir-timecop/version.rb
83
+ - spec/spec_helper.rb
84
+ - spec/wait_spec.rb
85
+ - watir-timecop.gemspec
86
+ homepage: https://github.com/p0deje/watir-timecop
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.0
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Use Watir with Timecop
110
+ test_files:
111
+ - spec/spec_helper.rb
112
+ - spec/wait_spec.rb