rwebspec 3.1.0 → 3.1.3

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/CHANGELOG CHANGED
@@ -1,6 +1,9 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 3.1.3
5
+ - changed rows => trs, cells => tds with Watir 3
6
+
4
7
  3.1 (may break existing test)
5
8
  - Support RSpec 2
6
9
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'spec/rake/spectask'
2
+ require 'rspec/core/rake_task'
3
3
  require 'rake/rdoctask'
4
4
  require 'rake/gempackagetask'
5
5
  require 'rdoc' # require rdoc 2
@@ -23,10 +23,10 @@ task :clean do
23
23
  end
24
24
 
25
25
  desc 'Run all specs'
26
- Spec::Rake::SpecTask.new('spec') do |t|
26
+ RSpec::Core::RakeTask.new('spec') do |t|
27
27
  t.spec_opts = ['--format', 'specdoc', '--colour']
28
28
  # t.libs = ["lib", "server/lib" ]
29
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
29
+ t.pattern = Dir['spec/**/*_spec.rb'].sort
30
30
  end
31
31
 
32
32
  # Generate the RDoc documentation
@@ -71,7 +71,7 @@ end
71
71
  spec = Gem::Specification.new do |s|
72
72
  s.platform= Gem::Platform::RUBY
73
73
  s.name = "rwebspec"
74
- s.version = "3.1.0"
74
+ s.version = "3.1.3"
75
75
  s.summary = "Web application functional specification in Ruby"
76
76
  s.description = "Executable functional specification for web applications in RSpec syntax and Watir"
77
77
 
@@ -1,6 +1,7 @@
1
1
  require 'socket'
2
2
 
3
3
  MAX_MESSAGE_LENGTH = 8192 # < 10K
4
+ $testwise_support = true
4
5
 
5
6
  module RWebSpec
6
7
  module TestWisePlugin
@@ -28,7 +29,7 @@ module RWebSpec
28
29
  sleep($TESTWISE_OPERATION_DELAY / 1000)
29
30
  end
30
31
 
31
- while $TESTWISE_PAUSE || $ITEST2_PAUSE
32
+ while $TESTWISE_PAUSE
32
33
  Thread.pass
33
34
  debug("Paused, waiting ...")
34
35
  sleep 1
@@ -45,7 +46,7 @@ module RWebSpec
45
46
 
46
47
  # find out the line (and file) the execution is on, and notify iTest via Socket
47
48
  def dump_caller_stack
48
- return unless ($TESTWISE_TRACE_EXECUTION || $ITEST2_TRACE_EXECUTION)
49
+ return unless ($TESTWISE_TRACE_EXECUTION)
49
50
  begin
50
51
  trace_lines = []
51
52
  trace_file = nil
@@ -83,7 +84,7 @@ module RWebSpec
83
84
  if @last_message == the_message then # ignore the message same as preivous one
84
85
  return
85
86
  end
86
- itest_port = $TESTWISE_TRACE_PORT || $ITEST2_TRACE_PORT || 7025
87
+ itest_port = $TESTWISE_TRACE_PORT || 7025
87
88
  itest_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
88
89
  itest_socket.connect(Socket.pack_sockaddr_in(itest_port, '127.0.0.1'))
89
90
  itest_socket.puts(the_message)
@@ -38,7 +38,7 @@ module RWebSpec
38
38
  end
39
39
 
40
40
  base_url ||= $TESTWISE_PROJECT_BASE_URL
41
- base_url ||= $ITEST2_PROJECT_BASE_URL
41
+ base_url ||= $TESTWISE_PROJECT_BASE_URL
42
42
  base_url ||= $BASE_URL
43
43
  raise "base_url must be set" if base_url.nil?
44
44
 
@@ -50,8 +50,8 @@ module RWebSpec
50
50
  :go => true}
51
51
 
52
52
  options = default_options.merge options
53
- options[:firefox] = true if "Firefox" == $ITEST2_BROWSER || "Firefox" == $TESTWISE_BROWSER || "Firefox" == $BROWSER
54
- ($TESTWISE_HIDE_BROWSER || $ITEST2_HIDE_BROWSER) ? $HIDE_IE = true : $HIDE_IE = false
53
+ options[:firefox] = true if "Firefox" == $TESTWISE_BROWSER || "Firefox" == $TESTWISE_BROWSER || "Firefox" == $BROWSER
54
+ ($TESTWISE_HIDE_BROWSER || $TESTWISE_HIDE_BROWSER) ? $HIDE_IE = true : $HIDE_IE = false
55
55
 
56
56
  if base_url =~ /^file:/
57
57
  uri_base = base_url
@@ -89,7 +89,7 @@ module RWebSpec
89
89
  def close_browser
90
90
  if @web_browser
91
91
  # Old TestWise version
92
- # @web_browser.close_browser unless $ITEST2_LEAVE_BROWSER_OPEN_AFTER_RUN
92
+ # @web_browser.close_browser unless $TESTWISE_LEAVE_BROWSER_OPEN_AFTER_RUN
93
93
  @web_browser.close_browser
94
94
  else
95
95
  close_all_browsers
@@ -104,7 +104,7 @@ module RWebSpec
104
104
  if @web_browser
105
105
  Watir::IE.close_all
106
106
  else
107
- browser_type = $ITEST2_BROWSER ? $ITEST2_BROWSER.downcase.to_sym : :ie
107
+ browser_type = $TESTWISE_BROWSER ? $TESTWISE_BROWSER.downcase.to_sym : :ie
108
108
  WebBrowser.close_all_browsers(browser_type)
109
109
  end
110
110
  end
@@ -185,7 +185,7 @@ module RWebSpec
185
185
  if url && url =~ /^http/
186
186
  http_response = client.get(url).body
187
187
  else
188
- base_url = $TESTWISE_PROJECT_BASE_URL || $ITEST2_PROJECT_BASE_URL || $BASE_URL
188
+ base_url = $TESTWISE_PROJECT_BASE_URL || $TESTWISE_PROJECT_BASE_URL || $BASE_URL
189
189
  http_response = client.get("#{base_url}#{url}").body
190
190
  end
191
191
 
@@ -281,14 +281,14 @@ module RWebSpec
281
281
  alias go_back back
282
282
  alias go_forward forward
283
283
 
284
- [:images, :links, :buttons, :select_lists, :checkboxes, :radios, :text_fields, :divs, :dls, :dds, :dts, :ems, :lis, :maps, :spans, :strongs, :ps, :pres, :labels, :cells, :rows].each do |method|
284
+ [:images, :links, :buttons, :select_lists, :checkboxes, :radios, :text_fields, :divs, :dls, :dds, :dts, :ems, :lis, :maps, :spans, :strongs, :ps, :pres, :labels, :tds, :trs].each do |method|
285
285
  define_method method do
286
286
  perform_operation { @web_browser.send(method) if @web_browser }
287
287
  end
288
288
  end
289
289
  alias as links
290
- alias trs rows
291
- alias tds cells
290
+ alias rows trs
291
+ alias cells tds
292
292
  alias imgs images
293
293
 
294
294
 
@@ -386,12 +386,12 @@ module RWebSpec
386
386
  end
387
387
 
388
388
  def default_dump_dir
389
- if ($TESTWISE_RUNNING_SPEC_ID && $TESTWISE_WORKING_DIR) || ($ITEST2_RUNNING_SPEC_ID && $ITEST2_WORKING_DIR)
389
+ if ($TESTWISE_RUNNING_SPEC_ID && $TESTWISE_WORKING_DIR) || ($TESTWISE_RUNNING_SPEC_ID && $TESTWISE_WORKING_DIR)
390
390
 
391
- $TESTWISE_DUMP_DIR = $ITEST2_DUMP_DIR = File.join($ITEST2_WORKING_DIR, "dump")
392
- FileUtils.mkdir($ITEST2_DUMP_DIR) unless File.exists?($ITEST2_DUMP_DIR)
391
+ $TESTWISE_DUMP_DIR = $TESTWISE_DUMP_DIR = File.join($TESTWISE_WORKING_DIR, "dump")
392
+ FileUtils.mkdir($TESTWISE_DUMP_DIR) unless File.exists?($TESTWISE_DUMP_DIR)
393
393
 
394
- spec_run_id = $TESTWISE_RUNNING_SPEC_ID || $ITEST2_RUNNING_SPEC_ID
394
+ spec_run_id = $TESTWISE_RUNNING_SPEC_ID || $TESTWISE_RUNNING_SPEC_ID
395
395
  spec_run_dir_name = spec_run_id.to_s.rjust(4, "0") unless spec_run_id == "unknown"
396
396
  to_dir = File.join($TESTWISE_DUMP_DIR, spec_run_dir_name)
397
397
  else
@@ -80,7 +80,7 @@ module RWebSpec
80
80
 
81
81
  # When running
82
82
  def debugging?
83
- ($ITEST2_DEBUGGING && $ITEST2_RUNNING_AS == "test_case") || ($TESTWISE_DEBUGGING && $TESTWISE_RUNNING_AS == "test_case")
83
+ ($TESTWISE_DEBUGGING && $TESTWISE_RUNNING_AS == "test_case")
84
84
  end
85
85
 
86
86
  # RSpec Matchers
@@ -388,5 +388,43 @@ module RWebSpec
388
388
  array.inject(0.0) { |sum, e| sum + e }
389
389
  end
390
390
 
391
+ ## Data Driven Tests
392
+ #
393
+ # Processing each row in a CSV file, must have heading rows
394
+ #
395
+ # Usage:
396
+ #
397
+ # process_each_row_in_csv_file(@csv_file) { |row|
398
+ # goto_page("/")
399
+ # enter_text("username", row[1])
400
+ # enter_text("password", row[2])
401
+ # click_button("Sign in")
402
+ # page_text.should contain(row[3])
403
+ # failsafe{ click_link("Sign off") }
404
+ # }
405
+ #
406
+ def process_each_row_in_csv_file(csv_file, &block)
407
+ require 'faster_csv'
408
+ connect_to_testwise("CSV_START", csv_file) if $testwise_support
409
+ has_error = false
410
+ idx = 0
411
+ FasterCSV.foreach(csv_file, :headers => :first_row, :encoding => 'u') do |row|
412
+ connect_to_testwise("CSV_ON_ROW", idx.to_s) if $testwise_support
413
+ begin
414
+ yield row
415
+ connect_to_testwise("CSV_ROW_PASS", idx.to_s) if $testwise_support
416
+ rescue => e
417
+ connect_to_testwise("CSV_ROW_FAIL", idx.to_s) if $testwise_support
418
+ has_error = true
419
+ ensure
420
+ idx += 1
421
+ end
422
+ end
423
+
424
+ connect_to_testwise("CSV_END", "") if $testwise_support
425
+ raise "Test failed on data" if has_error
426
+ end
427
+
428
+
391
429
  end
392
430
  end
@@ -68,7 +68,7 @@ module RWebSpec
68
68
  end
69
69
 
70
70
  def self.reuse(base_url, options)
71
- if self.is_windows? && ($TESTWISE_BROWSER != "Firefox" && $ITEST2_BROWSER != "Firefox")
71
+ if self.is_windows? && ($TESTWISE_BROWSER != "Firefox" && $TESTWISE_BROWSER != "Firefox")
72
72
  require 'watir-classic/ie'
73
73
  # try to avoid
74
74
  # lib/ruby/1.8/dl/win32.rb:11:in `sym': unknown type specifier 'v'
@@ -205,14 +205,14 @@ module RWebSpec
205
205
  end
206
206
  end
207
207
 
208
- [:images, :links, :buttons, :select_lists, :checkboxes, :radios, :text_fields, :divs, :dls, :dds, :dts, :ems, :lis, :maps, :spans, :strongs, :ps, :pres, :labels, :cells, :rows].each do |method|
208
+ [:images, :links, :buttons, :select_lists, :checkboxes, :radios, :text_fields, :divs, :dls, :dds, :dts, :ems, :lis, :maps, :spans, :strongs, :ps, :pres, :labels, :tds, :trs].each do |method|
209
209
  define_method method do
210
210
  @browser.send(method)
211
211
  end
212
212
  end
213
213
  alias as links
214
- alias trs rows
215
- alias tds cells
214
+ alias rows trs
215
+ alias cells tds
216
216
  alias imgs images
217
217
 
218
218
  # current url
@@ -34,8 +34,8 @@ module RWebSpec
34
34
  @web_browser = @browser = @web_tester = the_browser
35
35
  @page_specific_text = page_specific_text
36
36
  begin
37
- snapshot if $TESTWISE_DUMP_PAGE || $ITEST2_DUMP_PAGE
38
- delay = $TESTWISE_PAGE_DELAY || $ITEST2_PAGE_DELAY
37
+ snapshot if $TESTWISE_DUMP_PAGE || $TESTWISE_DUMP_PAGE
38
+ delay = $TESTWISE_PAGE_DELAY || $TESTWISE_PAGE_DELAY
39
39
  sleep(delay)
40
40
  rescue => e
41
41
  end
data/lib/rwebspec.rb CHANGED
@@ -16,7 +16,7 @@ end
16
16
  require 'rspec'
17
17
 
18
18
  unless defined? RWEBSPEC_VERSION
19
- RWEBSPEC_VERSION = RWEBUNIT_VERSION = "3.1.0"
19
+ RWEBSPEC_VERSION = RWEBUNIT_VERSION = "3.1.2"
20
20
  end
21
21
 
22
22
  $testwise_polling_interval = 1 # seconds
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 1
8
- - 0
9
- version: 3.1.0
8
+ - 3
9
+ version: 3.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Zhimin Zhan
@@ -14,7 +14,7 @@ autorequire: rwebspec
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-05-28 00:00:00 +10:00
17
+ date: 2012-06-20 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency