watirsplash 2.0.1.rc1 → 2.0.1.rc3

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.
data/.gitignore CHANGED
@@ -2,6 +2,5 @@ coverage/
2
2
  pkg/
3
3
  archive/
4
4
  results/
5
- .idea
6
5
  todo.txt
7
6
  rdoc/
data/.rspec CHANGED
@@ -1,2 +1,5 @@
1
- --require
2
- spec/environment.rb
1
+ --require spec/spec_helper.rb
2
+ --color
3
+ --format documentation
4
+ --require lib/watirsplash/html_formatter
5
+ --format WatirSplash::HtmlFormatter
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ end
11
11
  gem "watir-webdriver", WatirSplash::Version::WATIR_WEBDRIVER
12
12
  gem "firewatir", WatirSplash::Version::WATIR
13
13
  gem "rspec", "~>2.6.0"
14
+ gem "spork", "~>0.9.0.rc9"
14
15
 
15
16
  # add your project specific dependencies here:
16
17
  # gem "ruby-debug", "0.10.3"
@@ -1,20 +1,13 @@
1
1
  module WatirSplash
2
2
  class Browser
3
3
  class << self
4
+
5
+ attr_accessor :current
6
+
4
7
  def new
5
8
  prepare Watir::Browser.new
6
9
  end
7
10
 
8
- @@current = nil
9
-
10
- def current
11
- @@current
12
- end
13
-
14
- def current= browser
15
- @@current = browser
16
- end
17
-
18
11
  private
19
12
 
20
13
  def prepare browser
@@ -1,2 +1,6 @@
1
- --require
2
- environment
1
+ --drb
2
+ --require spec/spec_helper
3
+ --color
4
+ --format documentation
5
+ --require watirsplash/html_formatter
6
+ --format WatirSplash::HtmlFormatter
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.setup
4
+ require 'spork'
5
+
6
+ Spork.prefork do
7
+ # Loading more in this block will cause your tests to run faster. However,
8
+ # if you change any configuration or code from libraries loaded here, you'll
9
+ # need to restart spork for it take effect.
10
+ ENV["WATIRSPLASH_RESULTS_PATH"] = "results/#{Time.now.strftime("%y%m%d_%H%M%S")}/index.html"
11
+ require "watirsplash"
12
+
13
+ # What framework to use? Possible values are:
14
+ # * default
15
+ # * watir
16
+ # * firewatir
17
+ # * watir-webdriver/ie
18
+ # * watir-webdriver/firefox
19
+ # * watir-webdriver/chrome
20
+ WatirSplash::Util.framework = "default"
21
+
22
+ # Load the framework specified by the environment variable WATIRSPLASH_FRAMEWORK or WatirSplash::Util.framework
23
+ WatirSplash::Util.load_framework
24
+
25
+ require_rel "../config.rb"
26
+
27
+ # Add all your require statements into this block to avoid unnecessary
28
+ # code in your spec files
29
+ end
30
+
31
+ Spork.each_run do
32
+ # This code will be run each time you run your specs.
33
+ require_all Dir.glob(File.join(File.dirname(__FILE__), "../lib/**/*.rb"))
34
+ end
35
+
36
+ # --- Instructions ---
37
+ # Sort the contents of this file into a Spork.prefork and a Spork.each_run
38
+ # block.
39
+ #
40
+ # The Spork.prefork block is run only once when the spork server is started.
41
+ # You typically want to place most of your (slow) initializer code in here, in
42
+ # particular, require'ing any 3rd-party gems that you don't normally modify
43
+ # during development.
44
+ #
45
+ # The Spork.each_run block is run each time you run your specs. In case you
46
+ # need to load files that tend to change during development, require them here.
47
+ # With Rails, your application modules are loaded automatically, so sometimes
48
+ # this block can remain empty.
49
+ #
50
+ # Note: You can modify files loaded *from* the Spork.each_run block without
51
+ # restarting the spork server. However, this file itself will not be reloaded,
52
+ # so if you change any of the code inside the each_run block, you still need to
53
+ # restart the server. In general, if you have non-trivial code in this file,
54
+ # it's advisable to move it into a separate file so you can easily edit it
55
+ # without restarting spork. (For example, with RSpec, you could move
56
+ # non-trivial code into a file spec/support/my_helper.rb, making sure that the
57
+ # spec/support/* files are require'd from inside the each_run block.)
58
+ #
59
+ # Any code that is left outside the two blocks will be run during preforking
60
+ # *and* during each_run -- that's probably not what you want.
61
+ #
62
+ # These instructions should self-destruct in 10 seconds. If they don't, feel
63
+ # free to delete them.
@@ -10,15 +10,16 @@ module WatirSplash
10
10
  # * saves all files generated/downloaded during the test and shows them in the report
11
11
  class HtmlFormatter < ::RSpec::Core::Formatters::HtmlFormatter
12
12
 
13
- def initialize(output) # :nodoc:
14
- @output_dir = File.expand_path(File.dirname(output))
15
- archive_results
13
+ attr_reader :output_relative_path
16
14
 
17
- puts "Results will be saved into the directory #{@output_dir}"
18
- @files_dir = File.join(@output_dir, "files")
15
+ def initialize(output) # :nodoc:
16
+ @output_path = File.expand_path(ENV["WATIRSPLASH_RESULTS_PATH"] || (output.respond_to?(:path) ? output.path : "results/index.html"))
17
+ @output_relative_path = Pathname.new(@output_path).relative_path_from(Pathname.new(Dir.pwd))
18
+ puts "Results will be saved to #{@output_relative_path}"
19
+ @files_dir = File.join(File.dirname(@output_path), "files")
19
20
  FileUtils.mkdir_p(@files_dir)
20
21
  @files_saved_during_example = []
21
- super(File.open(output, "w"))
22
+ super(File.open(@output_path, "w"))
22
23
  end
23
24
 
24
25
  def example_group_started(example_group) # :nodoc:
@@ -51,7 +52,7 @@ module WatirSplash
51
52
 
52
53
  description = file[:desc] ? file[:desc] : File.extname(file[:path]).upcase[1..-1]
53
54
  path = Pathname.new(file[:path])
54
- "<a href='#{path.relative_path_from(Pathname.new(@output_dir))}'>#{description}</a>&nbsp;"
55
+ "<a href='#{path.relative_path_from(Pathname.new @output_path)}'>#{description}</a>&nbsp;"
55
56
  end
56
57
 
57
58
  def save_html # :nodoc:
@@ -85,14 +86,6 @@ module WatirSplash
85
86
 
86
87
  private
87
88
 
88
- def archive_results
89
- if File.exists?(@output_dir)
90
- archive_dir = File.join(@output_dir, "../archive")
91
- FileUtils.mkdir_p(archive_dir) unless File.exists?(archive_dir)
92
- FileUtils.mv @output_dir, File.join(archive_dir, "#{File.basename(@output_dir)}_#{File.mtime(@output_dir).strftime("%y%m%d_%H%M%S")}")
93
- end
94
- end
95
-
96
89
  def append_extra_information_to_description(example_group)
97
90
  date = Time.now.strftime("%d.%m.%Y")
98
91
  spec_location, line_no = extract_example_group_metadata example_group.metadata[:example_group]
@@ -1,15 +1,6 @@
1
1
  require 'rspec/core/formatters/html_formatter'
2
2
  require 'rspec/core/formatters/snippet_extractor'
3
3
 
4
- # make sure that UnkownObjectException constant exists
5
- module Watir
6
- module Exception
7
- class WatirException < RuntimeError
8
- end
9
- class UnknownObjectException < WatirException; end
10
- end
11
- end
12
-
13
4
  # patch for https://github.com/rspec/rspec-core/issues/#issue/214
14
5
  module RSpec
15
6
  module Core
@@ -155,25 +146,7 @@ RSpec::Matchers.constants.each do |const|
155
146
  alias_method :__matches?, :matches?
156
147
 
157
148
  def matches?(actual)
158
- if @within_timeout
159
- Watir::Wait.until(@within_timeout) do
160
- begin
161
- __matches?(actual)
162
- rescue Watir::Exception::UnknownObjectException
163
- false
164
- end
165
- end rescue false
166
- elsif @during_timeout
167
- Watir::Wait.while(@during_timeout) do
168
- begin
169
- __matches?(actual)
170
- rescue Watir::Exception::UnknownObjectException
171
- false
172
- end
173
- end rescue true
174
- else
175
- __matches?(actual)
176
- end
149
+ match_with_wait {__matches?(actual)}
177
150
  end
178
151
  end
179
152
 
@@ -181,47 +154,25 @@ RSpec::Matchers.constants.each do |const|
181
154
  alias_method :__does_not_match?, :does_not_match?
182
155
 
183
156
  def does_not_match?(actual)
184
- if @within_timeout
185
- Watir::Wait.until(@within_timeout) do
186
- begin
187
- __does_not_match?(actual)
188
- rescue Watir::Exception::UnknownObjectException
189
- false
190
- end
191
- end rescue false
192
- elsif @during_timeout
193
- Watir::Wait.while(@during_timeout) do
194
- begin
195
- __does_not_match?(actual)
196
- rescue Watir::Exception::UnknownObjectException
197
- false
198
- end
199
- end rescue true
200
- else
201
- __does_not_match?(actual)
202
- end
157
+ match_with_wait {__does_not_match?(actual)}
203
158
  end
204
159
  elsif inst_methods.include? :matches?
205
160
  def does_not_match?(actual)
206
- if @within_timeout
207
- Watir::Wait.until(@within_timeout) do
208
- begin
209
- !__matches?(actual)
210
- rescue Watir::Exception::UnknownObjectException
211
- false
212
- end
213
- end rescue false
214
- elsif @during_timeout
215
- Watir::Wait.while(@during_timeout) do
216
- begin
217
- !__matches?(actual)
218
- rescue Watir::Exception::UnknownObjectException
219
- false
220
- end
221
- end rescue true
222
- else
223
- !__matches?(actual)
224
- end
161
+ match_with_wait {!__matches?(actual)}
162
+ end
163
+ end
164
+
165
+ private
166
+
167
+ def match_with_wait
168
+ if @within_timeout
169
+ timeout = @within_timeout; @within_timeout = nil
170
+ Watir::Wait.until(timeout) {yield} rescue false
171
+ elsif @during_timeout
172
+ timeout = @during_timeout; @during_timeout = nil
173
+ Watir::Wait.while(timeout) {yield} rescue true
174
+ else
175
+ yield
225
176
  end
226
177
  end
227
178
  end
@@ -17,29 +17,21 @@ module WatirSplash
17
17
  File::ALT_SEPARATOR ? file_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR) : file_path
18
18
  end
19
19
 
20
- # configure RSpec to use documentation and WatirSplash::HtmlFormatter formatters
21
- def configure_rspec_formatters
22
- config = RSpec.configuration
23
- config.color_enabled = true
24
- results_path = ENV["WATIRSPLASH_RESULTS_PATH"] || "results/index.html"
25
- @@html_formatter = WatirSplash::HtmlFormatter.new(results_path)
26
- config.formatters.unshift(@@html_formatter)
27
- config.add_formatter(:documentation)
28
- end
29
-
30
20
  def formatter
31
- @@html_formatter
21
+ @html_formatter ||= begin
22
+ formatter = RSpec.configuration.formatters.find {|formatter| formatter.kind_of? WatirSplash::HtmlFormatter}
23
+ raise "WatirSplash::HtmlFormatter is not loaded - are you sure that you have specified it in your .rspec file?" unless formatter
24
+ formatter
25
+ end
32
26
  end
33
27
 
34
- @@framework = nil
35
-
36
28
  def framework= framework
37
29
  framework = framework.to_sym
38
- @@framework = framework == :default ? default_framework : framework.to_sym
30
+ @framework = framework == :default ? default_framework : framework
39
31
  end
40
32
 
41
33
  def framework
42
- @@framework
34
+ @framework
43
35
  end
44
36
 
45
37
  def load_framework
@@ -1,6 +1,6 @@
1
1
  module WatirSplash
2
2
  module Version
3
- WATIRSPLASH = "2.0.1.rc1"
3
+ WATIRSPLASH = "2.0.1.rc3"
4
4
 
5
5
  # possible runtime dependencies
6
6
  WATIR = "1.9.1"
data/lib/watirsplash.rb CHANGED
@@ -10,5 +10,3 @@ require_rel "watirsplash/util"
10
10
  require_rel "watirsplash/html_formatter"
11
11
  require_rel "watirsplash/frameworks/helper"
12
12
  require_rel "watirsplash/page/base"
13
- WatirSplash::Util.configure_rspec_formatters
14
-
@@ -5,31 +5,60 @@ describe "RSpec patches" do
5
5
  end
6
6
 
7
7
  context "RSpec::Matchers" do
8
+ context "Array#match_array" do
9
+ it "matches other arrays with regexps" do
10
+ expected_ary = ["1", "2", "3", /\d/]
11
+ ["1", "2", "3", "5"].should match_array(expected_ary)
12
+
13
+ expected_ary = ["1", ["2", /\d+/], /3/]
14
+ ["1", [], "4"].should_not match_array(expected_ary)
15
+ ["1", ["2", "55"], "3"].should match_array(expected_ary)
16
+ end
17
+
18
+ it "doesn't work with other objects except Array" do
19
+ lambda {"".should match_array("")}.should raise_exception
20
+ lambda {[].should match_array("")}.should raise_exception
21
+ lambda {"".should match_array([])}.should raise_exception
22
+ end
23
+ end
24
+
8
25
  context "#within" do
9
26
  it "can be used with #change" do
27
+ div(:id => "div2").text.should == "Div is shown"
28
+
10
29
  t = Time.now
11
30
  expect {
12
31
  link(:id => "toggle").click
13
32
  }.to change {div(:id => "div2").text}.from("Div is shown").to("Div is hidden").within(2)
14
- (Time.now - t).should be <= 2
33
+ (Time.now - t).should be_between(1, 2)
34
+
35
+ div(:id => "div2").text.should == "Div is hidden"
15
36
  end
16
37
 
17
38
  it "will fail upon timeout" do
39
+ div(:id => "div2").text.should == "Div is shown"
40
+
18
41
  t = Time.now
19
42
  expect {
20
43
  expect {
21
44
  link(:id => "toggle").click
22
45
  }.to change {div(:id => "div2").text}.from("Div is shown").to("Div is hidden").within(0.5)
23
46
  }.to raise_exception(%q{result should have been changed to "Div is hidden", but is now "Div is shown"})
24
- (Time.now - t).should be >= 0.5
47
+ (Time.now - t).should be_between(0.5, 0.7)
48
+
49
+ div(:id => "div2").text.should == "Div is shown"
25
50
  end
26
51
 
27
52
  it "can be used with #make" do
53
+ div(:id => "div1").should be_present
54
+
28
55
  t = Time.now
29
56
  expect {
30
57
  link(:id => "toggle").click
31
- }.to make {div(:id => "div1").present?}.within(2)
32
- (Time.now - t).should be <= 2
58
+ }.to make {div(:id => "div1").present?}.from(true).to(false).within(2)
59
+ (Time.now - t).should be_between(1, 2)
60
+
61
+ div(:id => "div1").should_not be_present
33
62
  end
34
63
 
35
64
  it "handles #should_not via matcher's #matches?" do
@@ -37,7 +66,9 @@ describe "RSpec patches" do
37
66
  h = {:special => true}
38
67
  Thread.new {sleep 0.5; h.delete :special}
39
68
  h.should_not have_key(:special).within(1)
40
- (Time.now - t).should be_between(0.5, 1)
69
+ (Time.now - t).should be_between(0.5, 0.7)
70
+
71
+ h.should_not have_key(:special)
41
72
  end
42
73
 
43
74
  it "fails when #should_not is not satisfied within timeout via matcher's #matches?" do
@@ -46,7 +77,7 @@ describe "RSpec patches" do
46
77
  expect {
47
78
  h.should_not have_key(:special).within(0.5)
48
79
  }.to raise_error
49
- (Time.now - t).should be >= 0.5
80
+ (Time.now - t).should be_between(0.5, 0.7)
50
81
  end
51
82
 
52
83
  it "handles #should_not via matcher's #does_not_match?" do
@@ -60,7 +91,9 @@ describe "RSpec patches" do
60
91
  h = {:special => true}
61
92
  Thread.new {sleep 0.5; h.delete :special}
62
93
  h.should_not have_my_key(:special).within(1)
63
- (Time.now - t).should be_between(0.5, 1)
94
+ (Time.now - t).should be_between(0.5, 0.7)
95
+
96
+ h.should_not have_key(:special)
64
97
  end
65
98
 
66
99
  it "fails when #should_not is not satisfied within timeout via matcher's #does_not_match?" do
@@ -75,7 +108,7 @@ describe "RSpec patches" do
75
108
  expect {
76
109
  h.should_not have_my_key(:special).within(0.5)
77
110
  }.to raise_error
78
- (Time.now - t).should be >= 0.5
111
+ (Time.now - t).should be_between(0.5, 0.7)
79
112
  end
80
113
  end
81
114
 
@@ -83,14 +116,14 @@ describe "RSpec patches" do
83
116
  it "will pass upon timeout" do
84
117
  t = Time.now
85
118
  true.should be_true.during(0.5)
86
- (Time.now - t).should be >= 0.5
119
+ (Time.now - t).should be_between(0.5, 0.7)
87
120
  end
88
121
 
89
122
  it "handles #should_not via matcher's #matches?" do
90
123
  t = Time.now
91
124
  h = {}
92
125
  h.should_not have_key(:special).during(1)
93
- (Time.now - t).should be >= 1
126
+ (Time.now - t).should be_between(1, 1.2)
94
127
  end
95
128
 
96
129
  it "fails when #should_not is not satisfied during timeout via matcher's #matches?" do
@@ -100,7 +133,9 @@ describe "RSpec patches" do
100
133
  expect {
101
134
  h.should_not have_key(:special).during(1)
102
135
  }.to raise_error
103
- (Time.now - t).should be_between(0.5, 1)
136
+ (Time.now - t).should be_between(0.5, 0.7)
137
+
138
+ h.should have_key(:special)
104
139
  end
105
140
 
106
141
  it "handles #should_not via matcher's #does_not_match?" do
@@ -113,7 +148,7 @@ describe "RSpec patches" do
113
148
  t = Time.now
114
149
  h = {}
115
150
  h.should_not have_my_key(:special).during(1)
116
- (Time.now - t).should be >= 1
151
+ (Time.now - t).should be_between(1, 1.2)
117
152
  end
118
153
 
119
154
  it "fails when #should_not is not satisfied within timeout via matcher's #does_not_match?" do
@@ -125,21 +160,19 @@ describe "RSpec patches" do
125
160
 
126
161
  t = Time.now
127
162
  h = {}
163
+ h.should_not have_my_key(:special)
164
+
128
165
  Thread.new {sleep 0.5; h[:special] = true}
129
166
  expect {
130
167
  h.should_not have_my_key(:special).during(1)
131
168
  }.to raise_error
132
- (Time.now - t).should be_between(0.5, 1)
169
+ (Time.now - t).should be_between(0.5, 0.7)
133
170
  end
134
171
  end
135
172
 
136
173
  context "#soon" do
137
- it "is an alias for #in(30)" do
138
- t = Time.now
139
- expect {
140
- link(:id => "toggle").click
141
- }.to make {div(:id => "div1").present?}.soon
142
- (Time.now - t).should be <= 30
174
+ it "is an alias for #within(30)" do
175
+ RSpec::Matchers::Matcher.new(nil) {}.soon.instance_variable_get(:@within_timeout).should == 30
143
176
  end
144
177
  end
145
178
 
File without changes
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watirsplash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424095
4
+ hash: 15424091
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 1
10
10
  - rc
11
- - 1
12
- version: 2.0.1.rc1
11
+ - 3
12
+ version: 2.0.1.rc3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Jarmo Pertman
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-07-06 00:00:00 Z
20
+ date: 2011-07-11 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rake
@@ -125,7 +125,7 @@ files:
125
125
  - lib/watirsplash/generators/page.rb
126
126
  - lib/watirsplash/generators/templates/new_project/.rspec
127
127
  - lib/watirsplash/generators/templates/new_project/config.rb.tt
128
- - lib/watirsplash/generators/templates/new_project/environment.rb.tt
128
+ - lib/watirsplash/generators/templates/new_project/spec/spec_helper.rb
129
129
  - lib/watirsplash/generators/templates/page/lib/%formatted_namespace%/page/%formatted_page_name%.rb.tt
130
130
  - lib/watirsplash/generators/templates/page/spec/%formatted_namespace%/page/%formatted_page_name%_spec.rb.tt
131
131
  - lib/watirsplash/html_formatter.rb
@@ -136,11 +136,10 @@ files:
136
136
  - lib/watirsplash/util.rb
137
137
  - lib/watirsplash/version.rb
138
138
  - spec/browser_spec.rb
139
- - spec/environment.rb
140
139
  - spec/page_spec.rb
141
140
  - spec/rspec_patches_spec.rb
141
+ - spec/spec_helper.rb
142
142
  - spec/spec_helper_spec.rb
143
- - spec/spec_match_array_spec.rb
144
143
  - spec/util_spec.rb
145
144
  - spec/watir_ie_spec.rb
146
145
  - watirsplash.gemspec
@@ -178,13 +177,12 @@ rubyforge_project:
178
177
  rubygems_version: 1.8.4
179
178
  signing_key:
180
179
  specification_version: 3
181
- summary: watirsplash 2.0.1.rc1
180
+ summary: watirsplash 2.0.1.rc3
182
181
  test_files:
183
182
  - spec/browser_spec.rb
184
- - spec/environment.rb
185
183
  - spec/page_spec.rb
186
184
  - spec/rspec_patches_spec.rb
185
+ - spec/spec_helper.rb
187
186
  - spec/spec_helper_spec.rb
188
- - spec/spec_match_array_spec.rb
189
187
  - spec/util_spec.rb
190
188
  - spec/watir_ie_spec.rb
@@ -1,15 +0,0 @@
1
- require "rubygems"
2
- require "bundler"
3
- Bundler.setup
4
- require "watirsplash"
5
-
6
- <%= frameworks_banner %>
7
-
8
- # Load the framework specified by the environment variable WATIRSPLASH_FRAMEWORK or WatirSplash::Util.framework
9
- WatirSplash::Util.load_framework
10
-
11
- require_all Dir.glob(File.join(File.dirname(__FILE__), "lib/**/*.rb"))
12
- require_rel "config.rb"
13
-
14
- # Add all your require statements into this file to avoid unnecessary
15
- # code in your spec files
@@ -1,18 +0,0 @@
1
- describe "Array match_array matcher" do
2
-
3
- it "matches other arrays with regexps" do
4
- expected_ary = ["1", "2", "3", /\d/]
5
- ["1", "2", "3", "5"].should match_array(expected_ary)
6
-
7
- expected_ary = ["1", ["2", /\d+/], /3/]
8
- ["1", [], "4"].should_not match_array(expected_ary)
9
- ["1", ["2", "55"], "3"].should match_array(expected_ary)
10
- end
11
-
12
- it "doesn't work with other objects except Array" do
13
- lambda {"".should match_array("")}.should raise_exception
14
- lambda {[].should match_array("")}.should raise_exception
15
- lambda {"".should match_array([])}.should raise_exception
16
- end
17
-
18
- end