rwebspec 1.4.0 → 1.4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +300 -300
- data/MIT-LICENSE +21 -21
- data/README +32 -32
- data/Rakefile +94 -94
- data/lib/rspec_extensions.rb +50 -50
- data/lib/rwebspec/assert.rb +361 -361
- data/lib/rwebspec/clickJSDialog.rb +15 -15
- data/lib/rwebspec/context.rb +24 -24
- data/lib/rwebspec/driver.rb +734 -734
- data/lib/rwebspec/itest_plugin.rb +68 -68
- data/lib/rwebspec/matchers/contains_text.rb +37 -37
- data/lib/rwebspec/popup.rb +147 -147
- data/lib/rwebspec/rspec_helper.rb +96 -96
- data/lib/rwebspec/test_script.rb +8 -8
- data/lib/rwebspec/test_utils.rb +171 -171
- data/lib/rwebspec/using_pages.rb +49 -49
- data/lib/rwebspec/web_browser.rb +528 -528
- data/lib/rwebspec/web_page.rb +94 -94
- data/lib/rwebspec/web_testcase.rb +36 -36
- data/lib/rwebspec.rb +31 -31
- data/lib/rwebunit.rb +3 -3
- data/lib/watir_extensions.rb +69 -69
- metadata +6 -6
@@ -1,96 +1,96 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
|
-
# ZZ patches to RSpec 1.1.2 - 1.1.4
|
4
|
-
# - add to_s method to example_group
|
5
|
-
module Spec
|
6
|
-
module Example
|
7
|
-
class ExampleGroup
|
8
|
-
def to_s
|
9
|
-
@_defined_description
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# example
|
16
|
-
# should link_by_text(text, options).size > 0
|
17
|
-
|
18
|
-
module RWebSpec
|
19
|
-
module RSpecHelper
|
20
|
-
include RWebSpec::Driver
|
21
|
-
include RWebSpec::Utils
|
22
|
-
include RWebSpec::Assert
|
23
|
-
|
24
|
-
# --
|
25
|
-
# Content
|
26
|
-
# --
|
27
|
-
|
28
|
-
def table_source(table_id)
|
29
|
-
table(:id, table_id).innerHTML
|
30
|
-
# elem = @web_browser.document.getElementById(table_id)
|
31
|
-
# raise "The element '#{table_id}' is not a table or there are multple elements with same id" unless elem.name.uppercase == "TABLE"
|
32
|
-
# elem.innerHTML
|
33
|
-
end
|
34
|
-
alias table_source_by_id table_source
|
35
|
-
|
36
|
-
def element_text(elem_id)
|
37
|
-
@web_browser.element_value(elem_id)
|
38
|
-
end
|
39
|
-
alias element_text_by_id element_text
|
40
|
-
|
41
|
-
#TODO: is it working?
|
42
|
-
def element_source(elem_id)
|
43
|
-
@web_browser.get_html_in_element(elem_id)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
def button_by_id(button_id)
|
48
|
-
button(:id, button_id)
|
49
|
-
end
|
50
|
-
|
51
|
-
def buttons_by_caption(text)
|
52
|
-
button(:text, text)
|
53
|
-
end
|
54
|
-
alias buttons_by_text buttons_by_caption
|
55
|
-
|
56
|
-
def link_by_id(link_id)
|
57
|
-
link(:id, link_id)
|
58
|
-
end
|
59
|
-
|
60
|
-
# default options: exact => true
|
61
|
-
def links_by_text(link_text, options = {})
|
62
|
-
options.merge!({:exact=> true})
|
63
|
-
matching_links = []
|
64
|
-
links.each { |link|
|
65
|
-
matching_links << link if (options[:exact] ? link.text == link_text : link.text.include?(link_text))
|
66
|
-
}
|
67
|
-
return matching_links
|
68
|
-
end
|
69
|
-
alias links_with_text links_by_text
|
70
|
-
|
71
|
-
def save_page(file_name = nil)
|
72
|
-
@web_browser.save_page(file_name)
|
73
|
-
end
|
74
|
-
|
75
|
-
def save_content_to_file(content, file_name = nil)
|
76
|
-
file_name ||= Time.now.strftime("%Y%m%d%H%M%S") + ".html"
|
77
|
-
puts "about to save page: #{File.expand_path(file_name)}"
|
78
|
-
File.open(file_name, "w").puts content
|
79
|
-
end
|
80
|
-
|
81
|
-
# When running
|
82
|
-
def debugging?
|
83
|
-
$ITEST2_DEBUGGING && $ITEST2_RUNNING_AS == "test_case"
|
84
|
-
end
|
85
|
-
|
86
|
-
# RSpec Matchers
|
87
|
-
#
|
88
|
-
# Example,
|
89
|
-
# a_number.should be_odd_number
|
90
|
-
def be_odd_number
|
91
|
-
simple_matcher("must be odd number") { |actual| actual && actual.to_id % 2 == 1}
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
# ZZ patches to RSpec 1.1.2 - 1.1.4
|
4
|
+
# - add to_s method to example_group
|
5
|
+
module Spec
|
6
|
+
module Example
|
7
|
+
class ExampleGroup
|
8
|
+
def to_s
|
9
|
+
@_defined_description
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# example
|
16
|
+
# should link_by_text(text, options).size > 0
|
17
|
+
|
18
|
+
module RWebSpec
|
19
|
+
module RSpecHelper
|
20
|
+
include RWebSpec::Driver
|
21
|
+
include RWebSpec::Utils
|
22
|
+
include RWebSpec::Assert
|
23
|
+
|
24
|
+
# --
|
25
|
+
# Content
|
26
|
+
# --
|
27
|
+
|
28
|
+
def table_source(table_id)
|
29
|
+
table(:id, table_id).innerHTML
|
30
|
+
# elem = @web_browser.document.getElementById(table_id)
|
31
|
+
# raise "The element '#{table_id}' is not a table or there are multple elements with same id" unless elem.name.uppercase == "TABLE"
|
32
|
+
# elem.innerHTML
|
33
|
+
end
|
34
|
+
alias table_source_by_id table_source
|
35
|
+
|
36
|
+
def element_text(elem_id)
|
37
|
+
@web_browser.element_value(elem_id)
|
38
|
+
end
|
39
|
+
alias element_text_by_id element_text
|
40
|
+
|
41
|
+
#TODO: is it working?
|
42
|
+
def element_source(elem_id)
|
43
|
+
@web_browser.get_html_in_element(elem_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def button_by_id(button_id)
|
48
|
+
button(:id, button_id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def buttons_by_caption(text)
|
52
|
+
button(:text, text)
|
53
|
+
end
|
54
|
+
alias buttons_by_text buttons_by_caption
|
55
|
+
|
56
|
+
def link_by_id(link_id)
|
57
|
+
link(:id, link_id)
|
58
|
+
end
|
59
|
+
|
60
|
+
# default options: exact => true
|
61
|
+
def links_by_text(link_text, options = {})
|
62
|
+
options.merge!({:exact=> true})
|
63
|
+
matching_links = []
|
64
|
+
links.each { |link|
|
65
|
+
matching_links << link if (options[:exact] ? link.text == link_text : link.text.include?(link_text))
|
66
|
+
}
|
67
|
+
return matching_links
|
68
|
+
end
|
69
|
+
alias links_with_text links_by_text
|
70
|
+
|
71
|
+
def save_page(file_name = nil)
|
72
|
+
@web_browser.save_page(file_name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def save_content_to_file(content, file_name = nil)
|
76
|
+
file_name ||= Time.now.strftime("%Y%m%d%H%M%S") + ".html"
|
77
|
+
puts "about to save page: #{File.expand_path(file_name)}"
|
78
|
+
File.open(file_name, "w").puts content
|
79
|
+
end
|
80
|
+
|
81
|
+
# When running
|
82
|
+
def debugging?
|
83
|
+
$ITEST2_DEBUGGING && $ITEST2_RUNNING_AS == "test_case"
|
84
|
+
end
|
85
|
+
|
86
|
+
# RSpec Matchers
|
87
|
+
#
|
88
|
+
# Example,
|
89
|
+
# a_number.should be_odd_number
|
90
|
+
def be_odd_number
|
91
|
+
simple_matcher("must be odd number") { |actual| actual && actual.to_id % 2 == 1}
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/lib/rwebspec/test_script.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module RWebSpec
|
2
|
-
module TestScript
|
3
|
-
include RWebSpec::Driver
|
4
|
-
include RWebSpec::Utils
|
5
|
-
include RWebSpec::Assert
|
6
|
-
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module RWebSpec
|
2
|
+
module TestScript
|
3
|
+
include RWebSpec::Driver
|
4
|
+
include RWebSpec::Utils
|
5
|
+
include RWebSpec::Assert
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
data/lib/rwebspec/test_utils.rb
CHANGED
@@ -1,171 +1,171 @@
|
|
1
|
-
#***********************************************************
|
2
|
-
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
-
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
-
#***********************************************************
|
5
|
-
|
6
|
-
# useful hekoer methods for testing
|
7
|
-
#
|
8
|
-
module RWebSpec
|
9
|
-
module Utils
|
10
|
-
|
11
|
-
# default date format returned is 29/12/2007.
|
12
|
-
# if supplied parameter is not '%m/%d/%Y' -> 12/29/2007
|
13
|
-
# Otherwise, "2007-12-29", which is most approiate date format
|
14
|
-
#
|
15
|
-
# %a - The abbreviated weekday name (``Sun'')
|
16
|
-
# %A - The full weekday name (``Sunday'')
|
17
|
-
# %b - The abbreviated month name (``Jan'')
|
18
|
-
# %B - The full month name (``January'')
|
19
|
-
# %c - The preferred local date and time representation
|
20
|
-
# %d - Day of the month (01..31)
|
21
|
-
# %H - Hour of the day, 24-hour clock (00..23)
|
22
|
-
# %I - Hour of the day, 12-hour clock (01..12)
|
23
|
-
# %j - Day of the year (001..366)
|
24
|
-
# %m - Month of the year (01..12)
|
25
|
-
# %M - Minute of the hour (00..59)
|
26
|
-
# %p - Meridian indicator (``AM'' or ``PM'')
|
27
|
-
# %S - Second of the minute (00..60)
|
28
|
-
# %U - Week number of the current year,
|
29
|
-
# starting with the first Sunday as the first
|
30
|
-
# day of the first week (00..53)
|
31
|
-
# %W - Week number of the current year,
|
32
|
-
# starting with the first Monday as the first
|
33
|
-
# day of the first week (00..53)
|
34
|
-
# %w - Day of the week (Sunday is 0, 0..6)
|
35
|
-
# %x - Preferred representation for the date alone, no time
|
36
|
-
# %X - Preferred representation for the time alone, no date
|
37
|
-
# %y - Year without a century (00..99)
|
38
|
-
# %Y - Year with century
|
39
|
-
# %Z - Time zone name
|
40
|
-
# %% - Literal ``%'' character
|
41
|
-
|
42
|
-
def today(format = '%d/%m/%Y')
|
43
|
-
format_date(Time.now, format)
|
44
|
-
end
|
45
|
-
alias getToday_AU today
|
46
|
-
alias getToday_US today
|
47
|
-
alias getToday today
|
48
|
-
|
49
|
-
|
50
|
-
def days_before(days, format = '%d/%m/%Y')
|
51
|
-
nil if !(days.instance_of?(Fixnum))
|
52
|
-
format_date(Time.now - days * 24 * 3600, format)
|
53
|
-
end
|
54
|
-
|
55
|
-
def yesterday
|
56
|
-
days_before(1)
|
57
|
-
end
|
58
|
-
|
59
|
-
def days_from_now(days, format = '%d/%m/%Y')
|
60
|
-
nil if !(days.instance_of?(Fixnum))
|
61
|
-
format_date(Time.now + days * 24 * 3600, format)
|
62
|
-
end
|
63
|
-
alias days_after days_from_now
|
64
|
-
|
65
|
-
def tomorrow
|
66
|
-
days_from_now(1)
|
67
|
-
end
|
68
|
-
|
69
|
-
# return a random number >= min, but <= max
|
70
|
-
def random_number(min, max)
|
71
|
-
rand(max-min+1)+min
|
72
|
-
end
|
73
|
-
|
74
|
-
def random_boolean
|
75
|
-
return random_number(0, 1) == 1
|
76
|
-
end
|
77
|
-
|
78
|
-
def random_char(lowercase = true)
|
79
|
-
sprintf("%c", random_number(97, 122)) if lowercase
|
80
|
-
sprintf("%c", random_number(65, 90)) unless lowercase
|
81
|
-
end
|
82
|
-
|
83
|
-
def random_digit()
|
84
|
-
sprintf("%c", random_number(48, 57))
|
85
|
-
end
|
86
|
-
|
87
|
-
def random_str(length, lowercase = true)
|
88
|
-
randomStr = ""
|
89
|
-
length.times {
|
90
|
-
randomStr += random_char(lowercase)
|
91
|
-
}
|
92
|
-
randomStr
|
93
|
-
end
|
94
|
-
|
95
|
-
# Return a random string in a rangeof pre-defined strings
|
96
|
-
def random_string_in(arr)
|
97
|
-
return nil if arr.empty?
|
98
|
-
index = random_number(0, arr.length-1)
|
99
|
-
arr[index]
|
100
|
-
end
|
101
|
-
alias random_string_in_collection random_string_in
|
102
|
-
|
103
|
-
|
104
|
-
WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
|
105
|
-
|
106
|
-
# Pick a random value out of a given range.
|
107
|
-
def value_in_range(range)
|
108
|
-
case range.first
|
109
|
-
when Integer then number_in_range(range)
|
110
|
-
when Time then time_in_range(range)
|
111
|
-
when Date then date_in_range(range)
|
112
|
-
else range.to_a.rand
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Generate a given number of words. If a range is passed, it will generate
|
117
|
-
# a random number of words within that range.
|
118
|
-
def words(total)
|
119
|
-
(1..interpret_value(total)).map { WORDS.rand }.join(' ')
|
120
|
-
end
|
121
|
-
|
122
|
-
# Generate a given number of sentences. If a range is passed, it will generate
|
123
|
-
# a random number of sentences within that range.
|
124
|
-
def sentences(total)
|
125
|
-
(1..interpret_value(total)).map do
|
126
|
-
words(5..20).capitalize
|
127
|
-
end.join('. ')
|
128
|
-
end
|
129
|
-
|
130
|
-
# Generate a given number of paragraphs. If a range is passed, it will generate
|
131
|
-
# a random number of paragraphs within that range.
|
132
|
-
def paragraphs(total)
|
133
|
-
(1..interpret_value(total)).map do
|
134
|
-
sentences(3..8).capitalize
|
135
|
-
end.join("\n\n")
|
136
|
-
end
|
137
|
-
|
138
|
-
# If an array or range is passed, a random value will be selected to match.
|
139
|
-
# All other values are simply returned.
|
140
|
-
def interpret_value(value)
|
141
|
-
case value
|
142
|
-
when Array then value.rand
|
143
|
-
when Range then value_in_range(value)
|
144
|
-
else value
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
private
|
149
|
-
|
150
|
-
def time_in_range(range)
|
151
|
-
Time.at number_in_range(Range.new(range.first.to_i, range.last.to_i, range.exclude_end?))
|
152
|
-
end
|
153
|
-
|
154
|
-
def date_in_range(range)
|
155
|
-
Date.jd number_in_range(Range.new(range.first.jd, range.last.jd, range.exclude_end?))
|
156
|
-
end
|
157
|
-
|
158
|
-
def number_in_range(range)
|
159
|
-
if range.exclude_end?
|
160
|
-
rand(range.last - range.first) + range.first
|
161
|
-
else
|
162
|
-
rand((range.last+1) - range.first) + range.first
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def format_date(date, date_format = '%d/%m/%Y')
|
167
|
-
date.strftime(date_format)
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
171
|
-
end
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
# useful hekoer methods for testing
|
7
|
+
#
|
8
|
+
module RWebSpec
|
9
|
+
module Utils
|
10
|
+
|
11
|
+
# default date format returned is 29/12/2007.
|
12
|
+
# if supplied parameter is not '%m/%d/%Y' -> 12/29/2007
|
13
|
+
# Otherwise, "2007-12-29", which is most approiate date format
|
14
|
+
#
|
15
|
+
# %a - The abbreviated weekday name (``Sun'')
|
16
|
+
# %A - The full weekday name (``Sunday'')
|
17
|
+
# %b - The abbreviated month name (``Jan'')
|
18
|
+
# %B - The full month name (``January'')
|
19
|
+
# %c - The preferred local date and time representation
|
20
|
+
# %d - Day of the month (01..31)
|
21
|
+
# %H - Hour of the day, 24-hour clock (00..23)
|
22
|
+
# %I - Hour of the day, 12-hour clock (01..12)
|
23
|
+
# %j - Day of the year (001..366)
|
24
|
+
# %m - Month of the year (01..12)
|
25
|
+
# %M - Minute of the hour (00..59)
|
26
|
+
# %p - Meridian indicator (``AM'' or ``PM'')
|
27
|
+
# %S - Second of the minute (00..60)
|
28
|
+
# %U - Week number of the current year,
|
29
|
+
# starting with the first Sunday as the first
|
30
|
+
# day of the first week (00..53)
|
31
|
+
# %W - Week number of the current year,
|
32
|
+
# starting with the first Monday as the first
|
33
|
+
# day of the first week (00..53)
|
34
|
+
# %w - Day of the week (Sunday is 0, 0..6)
|
35
|
+
# %x - Preferred representation for the date alone, no time
|
36
|
+
# %X - Preferred representation for the time alone, no date
|
37
|
+
# %y - Year without a century (00..99)
|
38
|
+
# %Y - Year with century
|
39
|
+
# %Z - Time zone name
|
40
|
+
# %% - Literal ``%'' character
|
41
|
+
|
42
|
+
def today(format = '%d/%m/%Y')
|
43
|
+
format_date(Time.now, format)
|
44
|
+
end
|
45
|
+
alias getToday_AU today
|
46
|
+
alias getToday_US today
|
47
|
+
alias getToday today
|
48
|
+
|
49
|
+
|
50
|
+
def days_before(days, format = '%d/%m/%Y')
|
51
|
+
nil if !(days.instance_of?(Fixnum))
|
52
|
+
format_date(Time.now - days * 24 * 3600, format)
|
53
|
+
end
|
54
|
+
|
55
|
+
def yesterday
|
56
|
+
days_before(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
def days_from_now(days, format = '%d/%m/%Y')
|
60
|
+
nil if !(days.instance_of?(Fixnum))
|
61
|
+
format_date(Time.now + days * 24 * 3600, format)
|
62
|
+
end
|
63
|
+
alias days_after days_from_now
|
64
|
+
|
65
|
+
def tomorrow
|
66
|
+
days_from_now(1)
|
67
|
+
end
|
68
|
+
|
69
|
+
# return a random number >= min, but <= max
|
70
|
+
def random_number(min, max)
|
71
|
+
rand(max-min+1)+min
|
72
|
+
end
|
73
|
+
|
74
|
+
def random_boolean
|
75
|
+
return random_number(0, 1) == 1
|
76
|
+
end
|
77
|
+
|
78
|
+
def random_char(lowercase = true)
|
79
|
+
sprintf("%c", random_number(97, 122)) if lowercase
|
80
|
+
sprintf("%c", random_number(65, 90)) unless lowercase
|
81
|
+
end
|
82
|
+
|
83
|
+
def random_digit()
|
84
|
+
sprintf("%c", random_number(48, 57))
|
85
|
+
end
|
86
|
+
|
87
|
+
def random_str(length, lowercase = true)
|
88
|
+
randomStr = ""
|
89
|
+
length.times {
|
90
|
+
randomStr += random_char(lowercase)
|
91
|
+
}
|
92
|
+
randomStr
|
93
|
+
end
|
94
|
+
|
95
|
+
# Return a random string in a rangeof pre-defined strings
|
96
|
+
def random_string_in(arr)
|
97
|
+
return nil if arr.empty?
|
98
|
+
index = random_number(0, arr.length-1)
|
99
|
+
arr[index]
|
100
|
+
end
|
101
|
+
alias random_string_in_collection random_string_in
|
102
|
+
|
103
|
+
|
104
|
+
WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
|
105
|
+
|
106
|
+
# Pick a random value out of a given range.
|
107
|
+
def value_in_range(range)
|
108
|
+
case range.first
|
109
|
+
when Integer then number_in_range(range)
|
110
|
+
when Time then time_in_range(range)
|
111
|
+
when Date then date_in_range(range)
|
112
|
+
else range.to_a.rand
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Generate a given number of words. If a range is passed, it will generate
|
117
|
+
# a random number of words within that range.
|
118
|
+
def words(total)
|
119
|
+
(1..interpret_value(total)).map { WORDS.rand }.join(' ')
|
120
|
+
end
|
121
|
+
|
122
|
+
# Generate a given number of sentences. If a range is passed, it will generate
|
123
|
+
# a random number of sentences within that range.
|
124
|
+
def sentences(total)
|
125
|
+
(1..interpret_value(total)).map do
|
126
|
+
words(5..20).capitalize
|
127
|
+
end.join('. ')
|
128
|
+
end
|
129
|
+
|
130
|
+
# Generate a given number of paragraphs. If a range is passed, it will generate
|
131
|
+
# a random number of paragraphs within that range.
|
132
|
+
def paragraphs(total)
|
133
|
+
(1..interpret_value(total)).map do
|
134
|
+
sentences(3..8).capitalize
|
135
|
+
end.join("\n\n")
|
136
|
+
end
|
137
|
+
|
138
|
+
# If an array or range is passed, a random value will be selected to match.
|
139
|
+
# All other values are simply returned.
|
140
|
+
def interpret_value(value)
|
141
|
+
case value
|
142
|
+
when Array then value.rand
|
143
|
+
when Range then value_in_range(value)
|
144
|
+
else value
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def time_in_range(range)
|
151
|
+
Time.at number_in_range(Range.new(range.first.to_i, range.last.to_i, range.exclude_end?))
|
152
|
+
end
|
153
|
+
|
154
|
+
def date_in_range(range)
|
155
|
+
Date.jd number_in_range(Range.new(range.first.jd, range.last.jd, range.exclude_end?))
|
156
|
+
end
|
157
|
+
|
158
|
+
def number_in_range(range)
|
159
|
+
if range.exclude_end?
|
160
|
+
rand(range.last - range.first) + range.first
|
161
|
+
else
|
162
|
+
rand((range.last+1) - range.first) + range.first
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def format_date(date, date_format = '%d/%m/%Y')
|
167
|
+
date.strftime(date_format)
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
data/lib/rwebspec/using_pages.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
module RWebSpec
|
2
|
-
module UsingPages
|
3
|
-
|
4
|
-
# support Ruby 1.9
|
5
|
-
def self.extended(kclass)
|
6
|
-
caller_file = caller[1]
|
7
|
-
if caller_file && caller_file =~ /^(.*):\d+.*$/
|
8
|
-
file = $1
|
9
|
-
dir = File.expand_path(File.dirname(file))
|
10
|
-
kclass.const_set "TestFileDir", dir
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# Example
|
15
|
-
# pages :all
|
16
|
-
# pages :login_page, :payment_page
|
17
|
-
# pages :login_page, :payment_page, :page_dir => "c:/tmp"
|
18
|
-
def pages(*args)
|
19
|
-
return if args.nil? or args.empty?
|
20
|
-
|
21
|
-
test_file_dir = class_eval{ self::TestFileDir }
|
22
|
-
default_page_dir = File.join(test_file_dir, "pages")
|
23
|
-
#puts "debug: default_page_dir :#{default_page_dir}}"
|
24
|
-
page_dir = default_page_dir
|
25
|
-
|
26
|
-
page_files = []
|
27
|
-
args.each do |x|
|
28
|
-
if x.class == Hash && x[:page_dir]
|
29
|
-
page_dir = x[:page_dir]
|
30
|
-
else
|
31
|
-
page_files << x
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
if page_files.size == 1 && page_files[0] == :all
|
36
|
-
Dir[File.expand_path(page_dir)+ "/*_page.rb"].each { |page_file|
|
37
|
-
load page_file
|
38
|
-
}
|
39
|
-
return
|
40
|
-
end
|
41
|
-
|
42
|
-
page_files.each do |page|
|
43
|
-
page_file = File.join(page_dir, page.to_s)
|
44
|
-
load page_file
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
1
|
+
module RWebSpec
|
2
|
+
module UsingPages
|
3
|
+
|
4
|
+
# support Ruby 1.9
|
5
|
+
def self.extended(kclass)
|
6
|
+
caller_file = caller[1]
|
7
|
+
if caller_file && caller_file =~ /^(.*):\d+.*$/
|
8
|
+
file = $1
|
9
|
+
dir = File.expand_path(File.dirname(file))
|
10
|
+
kclass.const_set "TestFileDir", dir
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Example
|
15
|
+
# pages :all
|
16
|
+
# pages :login_page, :payment_page
|
17
|
+
# pages :login_page, :payment_page, :page_dir => "c:/tmp"
|
18
|
+
def pages(*args)
|
19
|
+
return if args.nil? or args.empty?
|
20
|
+
|
21
|
+
test_file_dir = class_eval{ self::TestFileDir }
|
22
|
+
default_page_dir = File.join(test_file_dir, "pages")
|
23
|
+
#puts "debug: default_page_dir :#{default_page_dir}}"
|
24
|
+
page_dir = default_page_dir
|
25
|
+
|
26
|
+
page_files = []
|
27
|
+
args.each do |x|
|
28
|
+
if x.class == Hash && x[:page_dir]
|
29
|
+
page_dir = x[:page_dir]
|
30
|
+
else
|
31
|
+
page_files << x
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if page_files.size == 1 && page_files[0] == :all
|
36
|
+
Dir[File.expand_path(page_dir)+ "/*_page.rb"].each { |page_file|
|
37
|
+
load page_file
|
38
|
+
}
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
page_files.each do |page|
|
43
|
+
page_file = File.join(page_dir, page.to_s)
|
44
|
+
load page_file
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|