rwebunit 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,6 +1,9 @@
1
1
  CHANGELOG
2
2
  =========
3
-
3
+ 1.3.1
4
+ [Enhancement] better absolutize the hyperlinks in dumped page source
5
+ [Fixes] logic in allowing method
6
+
4
7
  1.3
5
8
  add new syntax for including pages
6
9
  extend RWebUnit::UsingPages
data/Rakefile CHANGED
@@ -50,7 +50,7 @@ end
50
50
  spec = Gem::Specification.new do |s|
51
51
  s.platform= Gem::Platform::RUBY
52
52
  s.name = "rwebunit"
53
- s.version = "1.3.0"
53
+ s.version = "1.3.1"
54
54
  s.summary = "An wrap of WATIR/FireWatir for functional testing of web applications"
55
55
  # s.description = ""
56
56
 
data/lib/rwebunit.rb CHANGED
@@ -13,7 +13,7 @@ end
13
13
  require 'active_support/core_ext'
14
14
  require 'spec'
15
15
 
16
- RWEBUNIT_VERSION = "1.3.0"
16
+ RWEBUNIT_VERSION = "1.3.1"
17
17
 
18
18
  # Extra full path to load libraries
19
19
  require File.dirname(__FILE__) + "/rwebunit/using_pages"
@@ -337,7 +337,7 @@ module RWebUnit
337
337
  if options[:dir]
338
338
  # already defined the dir
339
339
  to_dir = options[:dir]
340
- elsif $ITEST2_RUNNING_SPEC_ID
340
+ elsif $ITEST2_RUNNING_SPEC_ID && $ITEST2_WORKING_DIR
341
341
 
342
342
  $ITEST2_DUMP_DIR = File.join($ITEST2_WORKING_DIR, "dump")
343
343
  FileUtils.mkdir($ITEST2_DUMP_DIR) unless File.exists?($ITEST2_DUMP_DIR)
@@ -364,41 +364,71 @@ module RWebUnit
364
364
  current_url =~ /(.*\/).*$/
365
365
  current_url_parent = $1
366
366
  if options[:replacement] && base_url =~ /^http:/
367
+ File.new(file, "w").puts absolutize_page_hpricot(content, base_url, current_url_parent)
368
+ else
369
+ File.new(file, "w").puts content
370
+ end
367
371
 
368
- # <link rel="stylesheet" type="text/css" href="/stylesheets/default.css" />
369
- # '<script type="text/javascript" src="http://www.jeroenwijering.com/embed/swfobject.js"></script>'
370
- # <script type="text/javascript" src="/javascripts/prototype.js"></script>
371
- # <script type="text/javascript" src="/javascripts/scriptaculous.js?load=effects,builder"></script>
372
- # <script type="text/javascript" src="/javascripts/extensions/gallery/lightbox.js"></script>
373
- # <link href="/stylesheets/extensions/gallery/lightbox.css" rel="stylesheet" type="text/css" />
374
- # <img src="images/mission_48.png" />
375
-
376
- modified_content = ""
377
-
378
- content.each_line do |line|
379
- if line =~ /<script\s+.*src=["'']?(.*)["'].*/i then
380
- script_src = $1
381
- substitute_relative_path_in_src_line(line, script_src, base_url, current_url_parent)
382
- elsif line =~ /<link\s+.*href=["'']?(.*)["'].*/i then
383
- link_href = $1
384
- substitute_relative_path_in_src_line(line, link_href, base_url, current_url_parent)
385
- elsif line =~ /<img\s+.*src=["'']?(.*)["'].*/i then
386
- img_src = $1
387
- substitute_relative_path_in_src_line(line, img_src, base_url, current_url_parent)
388
- end
372
+ end
389
373
 
390
- modified_content += line
391
- end
392
374
 
393
- File.new(file, "w").puts modified_content
394
- else
395
- File.new(file, "w").puts content
375
+ # <link rel="stylesheet" type="text/css" href="/stylesheets/default.css" />
376
+ # '<script type="text/javascript" src="http://www.jeroenwijering.com/embed/swfobject.js"></script>'
377
+ # <script type="text/javascript" src="/javascripts/prototype.js"></script>
378
+ # <script type="text/javascript" src="/javascripts/scriptaculous.js?load=effects,builder"></script>
379
+ # <script type="text/javascript" src="/javascripts/extensions/gallery/lightbox.js"></script>
380
+ # <link href="/stylesheets/extensions/gallery/lightbox.css" rel="stylesheet" type="text/css" />
381
+ # <img src="images/mission_48.png" />
382
+ def absolutize_page(content, base_url, current_url_parent)
383
+ modified_content = ""
384
+ content.each_line do |line|
385
+ if line =~ /<script\s+.*src=["'']?(.*)["'].*/i then
386
+ script_src = $1
387
+ substitute_relative_path_in_src_line(line, script_src, base_url, current_url_parent)
388
+ elsif line =~ /<link\s+.*href=["'']?(.*)["'].*/i then
389
+ link_href = $1
390
+ substitute_relative_path_in_src_line(line, link_href, base_url, current_url_parent)
391
+ elsif line =~ /<img\s+.*src=["'']?(.*)["'].*/i then
392
+ img_src = $1
393
+ substitute_relative_path_in_src_line(line, img_src, base_url, current_url_parent)
394
+ end
396
395
 
396
+ modified_content += line
397
397
  end
398
+ return modified_content
399
+ end
398
400
 
399
-
401
+ # absolutize_page referencs using hpricot
402
+ #
403
+ def absolutize_page_hpricot(content, base_url, parent_url)
404
+ begin
405
+ require 'hpricot'
406
+ doc = Hpricot(content)
407
+ base_url.slice!(-1) if ends_with?(base_url, "/")
408
+ (doc/'link').each { |e| e['href'] = absolutify_url(e['href'], base_url, parent_url) || ""}
409
+ (doc/'img').each { |e| e['src'] = absolutify_url(e['src'], base_url, parent_url) || ""}
410
+ (doc/'script').each { |e| e['src'] = absolutify_url(e['src'], base_url, parent_url) || ""}
411
+ return doc.to_html
412
+ rescue => e
413
+ absolutize_page(content, base_url, parent_url)
414
+ end
400
415
  end
401
416
 
417
+ ##
418
+ # change
419
+ # <script type="text/javascript" src="/javascripts/prototype.js"></script>
420
+ # to
421
+ # <script type="text/javascript" src="http://itest2.com/javascripts/prototype.js"></script>
422
+ def absolutify_url(src, base_url, parent_url)
423
+ if src.nil? || src.empty? || src == "//:" || src =~ /\s*http:\/\//i
424
+ return src
425
+ end
426
+
427
+ return "#{base_url}#{src}" if src =~ /^\s*\//
428
+ return "#{parent_url}#{src}" if parent_url
429
+ return src
430
+ end
431
+
402
432
  # substut
403
433
  def substitute_relative_path_in_src_line(line, script_src, host_url, page_parent_url)
404
434
  unless script_src =~ /^["']?http:/
@@ -465,6 +495,10 @@ module RWebUnit
465
495
  RUBY_PLATFORM.downcase.include?("mswin") or RUBY_PLATFORM.downcase.include?("mingw32")
466
496
  end
467
497
 
498
+ def is_linux?
499
+ RUBY_PLATFORM.downcase.include?("linux")
500
+ end
501
+
468
502
  # Support browser (IE) operations using unicode
469
503
  # Example:
470
504
  # click_button("Google 搜索")
@@ -476,10 +510,6 @@ module RWebUnit
476
510
  end
477
511
  alias support_unicode support_utf8
478
512
 
479
- def is_linux?
480
- RUBY_PLATFORM.downcase.include?("linux")
481
- end
482
-
483
513
  #= Convenient functions
484
514
  #
485
515
 
@@ -515,13 +545,7 @@ module RWebUnit
515
545
  # Example:
516
546
  # allow { click_button('Register') }
517
547
  def allow(&block)
518
- operation_performed_ok = false
519
- begin
520
- yield
521
- operation_performed_ok = true
522
- rescue
523
- end
524
- operation_performed_ok
548
+ yield
525
549
  end
526
550
  alias shall_allow allow
527
551
  alias allowing allow
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rwebunit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhimin Zhan
@@ -9,7 +9,7 @@ autorequire: rwebunit
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-01 00:00:00 +10:00
12
+ date: 2009-08-02 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency