watir-rspec 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/watir/rspec.rb +96 -96
- data/lib/watir/rspec/helper.rb +7 -3
- data/lib/watir/rspec/version.rb +1 -1
- metadata +2 -2
data/lib/watir/rspec.rb
CHANGED
@@ -25,134 +25,134 @@ module Watir
|
|
25
25
|
#
|
26
26
|
class RSpec
|
27
27
|
class << self
|
28
|
-
|
29
|
-
|
28
|
+
def add_within_and_during_to_matcher const
|
29
|
+
const.class_eval do
|
30
30
|
|
31
|
-
|
31
|
+
inst_methods = instance_methods.map &:to_sym
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
if !(inst_methods.include?(:__matches?) || inst_methods.include?(:__does_not_match?)) &&
|
34
|
+
(inst_methods.include?(:matches?) || inst_methods.include?(:does_not_match?))
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def within(timeout)
|
37
|
+
@within_timeout = timeout
|
38
|
+
self
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def during(timeout)
|
42
|
+
@during_timeout = timeout
|
43
|
+
self
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def soon
|
47
|
+
within(30)
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def seconds
|
51
|
+
# for syntactic sugar
|
52
|
+
self
|
53
|
+
end
|
54
54
|
|
55
|
-
|
55
|
+
alias_method :second, :seconds
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
def minutes
|
58
|
+
@within_timeout *= 60 if @within_timeout
|
59
|
+
@during_timeout *= 60 if @during_timeout
|
60
|
+
self
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
alias_method :minute, :minutes
|
64
|
+
end
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
if inst_methods.include? :matches?
|
67
|
+
alias_method :__matches?, :matches?
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
def matches?(actual)
|
70
|
+
match_with_wait {__matches?(actual)}
|
71
|
+
end
|
71
72
|
end
|
72
|
-
end
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
if inst_methods.include? :does_not_match?
|
75
|
+
alias_method :__does_not_match?, :does_not_match?
|
76
76
|
|
77
|
-
|
78
|
-
|
77
|
+
def does_not_match?(actual)
|
78
|
+
match_with_wait {__does_not_match?(actual)}
|
79
|
+
end
|
80
|
+
elsif inst_methods.include? :matches?
|
81
|
+
def does_not_match?(actual)
|
82
|
+
match_with_wait {!__matches?(actual)}
|
83
|
+
end
|
79
84
|
end
|
80
|
-
elsif inst_methods.include? :matches?
|
81
|
-
def does_not_match?(actual)
|
82
|
-
match_with_wait {!__matches?(actual)}
|
83
|
-
end
|
84
|
-
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
86
|
+
private
|
87
|
+
|
88
|
+
def match_with_wait
|
89
|
+
if @within_timeout
|
90
|
+
timeout = @within_timeout; @within_timeout = nil
|
91
|
+
Watir::Wait.until(timeout) {yield} rescue false
|
92
|
+
elsif @during_timeout
|
93
|
+
timeout = @during_timeout; @during_timeout = nil
|
94
|
+
Watir::Wait.while(timeout) {yield} rescue true
|
95
|
+
else
|
96
|
+
yield
|
97
|
+
end
|
97
98
|
end
|
98
99
|
end
|
99
100
|
end
|
100
|
-
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
def file_path(file_name, description=nil)
|
103
|
+
formatter.file_path(file_name, description=nil)
|
104
|
+
end
|
105
105
|
|
106
|
-
|
106
|
+
private
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
Watir::RSpec::HtmlFormatter is not set as a RSpec formatter.
|
108
|
+
def formatter
|
109
|
+
@formatter ||= begin
|
110
|
+
formatter = ::RSpec.configuration.formatters.find {|f| f.kind_of? Watir::RSpec::HtmlFormatter}
|
111
|
+
unless formatter
|
112
|
+
raise <<-EOF
|
113
|
+
Watir::RSpec::HtmlFormatter is not set as a RSpec formatter.
|
114
114
|
|
115
|
-
You need to add it into your spec_helper.rb file like this:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
EOF
|
115
|
+
You need to add it into your spec_helper.rb file like this:
|
116
|
+
RSpec.configure do |config|
|
117
|
+
config.add_formatter('documentation')
|
118
|
+
config.add_formatter(Watir::RSpec::HtmlFormatter)
|
119
|
+
end
|
120
|
+
EOF
|
121
|
+
end
|
122
|
+
formatter
|
121
123
|
end
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|
124
|
+
end
|
125
125
|
|
126
126
|
|
127
|
-
|
127
|
+
end
|
128
128
|
|
129
|
+
end
|
129
130
|
end
|
130
|
-
end
|
131
131
|
|
132
|
-
# patch for #within(timeout) method
|
133
|
-
module ::RSpec::Matchers
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
# patch for #within(timeout) method
|
133
|
+
module ::RSpec::Matchers
|
134
|
+
class BuiltIn::Change
|
135
|
+
def matches?(event_proc)
|
136
|
+
raise_block_syntax_error if block_given?
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
138
|
+
# to make #change work with #in(timeout) method
|
139
|
+
unless defined? @actual_before
|
140
|
+
@actual_before = evaluate_value_proc
|
141
|
+
event_proc.call
|
142
|
+
end
|
143
|
+
@actual_after = evaluate_value_proc
|
144
144
|
|
145
|
-
|
145
|
+
(!change_expected? || changed?) && matches_before? && matches_after? && matches_expected_delta? && matches_min? && matches_max?
|
146
|
+
end
|
146
147
|
end
|
147
|
-
end
|
148
148
|
|
149
|
-
|
150
|
-
end
|
149
|
+
alias_method :make, :change
|
150
|
+
end
|
151
151
|
|
152
|
-
matchers = RSpec::Matchers::BuiltIn.constants.map(&:to_sym)
|
153
|
-
matchers.delete :BaseMatcher
|
154
|
-
matchers.each do |const|
|
155
|
-
|
156
|
-
end
|
152
|
+
matchers = RSpec::Matchers::BuiltIn.constants.map(&:to_sym)
|
153
|
+
matchers.delete :BaseMatcher
|
154
|
+
matchers.each do |const|
|
155
|
+
Watir::RSpec.add_within_and_during_to_matcher RSpec::Matchers::BuiltIn.const_get const
|
156
|
+
end
|
157
157
|
|
158
|
-
Watir::RSpec.
|
158
|
+
Watir::RSpec.add_within_and_during_to_matcher RSpec::Matchers::DSL::Matcher
|
data/lib/watir/rspec/helper.rb
CHANGED
@@ -3,11 +3,15 @@ module Watir
|
|
3
3
|
module Helper
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
+
def browser
|
7
|
+
@browser || $browser
|
8
|
+
end
|
9
|
+
|
6
10
|
def method_missing name, *args #:nodoc:
|
7
|
-
if
|
11
|
+
if browser.respond_to?(name)
|
8
12
|
Helper.module_eval %Q[
|
9
13
|
def #{name}(*args)
|
10
|
-
|
14
|
+
browser.send(:#{name}, *args) {yield}
|
11
15
|
end
|
12
16
|
]
|
13
17
|
self.send(name, *args) {yield}
|
@@ -19,7 +23,7 @@ module Watir
|
|
19
23
|
# make sure that using method 'p' will be invoked on browser
|
20
24
|
# and not Kernel
|
21
25
|
# use Kernel.p if you need to dump some variable
|
22
|
-
def_delegators
|
26
|
+
def_delegators :browser, :p
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/watir/rspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|