cuculungwa 0.0.27 → 0.0.30

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cuculungwa.rb +198 -154
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 638c49c1f0c9578df17004aa4fdd3675b1bec538
4
- data.tar.gz: 36031e56aa53b3e0d27b04b2461e7764949cafce
3
+ metadata.gz: 35858ab458fb48269749eb15187c4e98997716bd
4
+ data.tar.gz: dfb3380750f698129c501095a25736a43fac9499
5
5
  SHA512:
6
- metadata.gz: 2b6bf0e85ac54457618a34256e5bbf7db18ed1b54e31d107291c2f508350d73bba8c4aa97d68430705aafd90b3e2257f84883f5b972f637523a9495042dbd65c
7
- data.tar.gz: 6dc001f56dd9455bd987d5be909231b1539cbaaa4d1dfa5c09f6adbdcc1953f39696d716be848491da58081148232f7a167df33605ff1fd2917c5fc7209aa287
6
+ metadata.gz: e0e0b11a2dc1772995a940a33563ba3dac03c3c3e474a7e22afd546f5e0c0c071b91ab00e9e18e3136617a39eac7b3f76902084b20ef7be6f1130f70525b2cd0
7
+ data.tar.gz: 02816329cd19e151131413095baba7506b62cefb5b8df7acf74148327c5fab217f3ba23fb1576a29f36e3047ed67d5008ecb6b6aced825a054f8ad2078bae9e2
data/lib/cuculungwa.rb CHANGED
@@ -1,154 +1,198 @@
1
- require 'i18n'
2
- require 'capybara'
3
- #require 'capybara-webkit'
4
- require 'capybara/dsl'
5
- require 'capybara/cucumber'
6
- require 'capybara/poltergeist'
7
- require 'capybara-screenshot'
8
- require 'capybara-screenshot/cucumber'
9
- require 'rspec/expectations'
10
- require 'site_prism'
11
- require 'yaml'
12
-
13
- config = YAML::load(File.open('config/config.yml'))
14
-
15
- I18n.enforce_available_locales = false
16
- I18n.locale = config['framework']['i18n']['locale'].to_sym
17
- I18n.load_path = Dir[config['framework']['i18n']['load_path']]
18
-
19
- if config['capybara']['browser']=='phantomjs'
20
- Capybara.register_driver :poltergeist do |app|
21
- Capybara::Poltergeist::Driver.new app,
22
- phantomjs_options: config['capybara']['phantomjs_specific']['options'],
23
- window_size: config['capybara']['phantomjs_specific']['window_size']
24
- end
25
- Capybara.default_driver = :poltergeist
26
- elsif config['capybara']['browser']=='capybara-webkit'
27
- Capybara.default_driver = :webkit
28
- Capybara.javascript_driver = :webkit
29
- else
30
- Capybara.register_driver :selenium do |app|
31
- Capybara::Selenium::Driver.new(app, :browser => config['capybara']['browser'].to_sym)
32
- end
33
- Capybara.default_driver = :selenium
34
- end
35
-
36
- Capybara.save_and_open_page_path = config['capybara']['save_and_open_page_path']
37
- Capybara.app_host = config['project']['default_host']['front']
38
- Capybara.default_wait_time = config['capybara']['default_wait_time']
39
- World(Capybara)
40
-
41
- def override_method(obj, method_name, &block)
42
- klass = class <<obj; self; end
43
- klass.send(:undef_method, method_name)
44
- klass.send(:define_method, method_name, block)
45
- end
46
-
47
- AfterConfiguration do |configuration|
48
- override_method(configuration, :feature_files) do
49
- potential_feature_files = with_default_features_path(paths).map do |path|
50
- path = path.chomp('/')
51
- if File.directory?(path)
52
- Dir["#{path}" + config['framework']['features_regexp']].sort
53
- elsif path[0..0] == '@' and
54
- File.file?(path[1..-1])
55
- IO.read(path[1..-1]).split
56
- else
57
- path
58
- end
59
- end.flatten.uniq
60
- remove_excluded_files_from(potential_feature_files)
61
- potential_feature_files.shuffle
62
- end
63
- end
64
-
65
- module GenerateData
66
- def pesel_generator(data_type)
67
- if (data_type.eql? 'positive_data_set')
68
- weights = Array[1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
69
- year = rand()*100
70
- month = rand()*12+1
71
- day = rand()*28+1
72
- evidence_number = rand()*999
73
- sex=rand()*9
74
- pesel="%02d%02d%02d%03d%d"%[year,month,day,evidence_number,sex]
75
- temp_cs = 0
76
- pesel_elem = pesel.each_char.map {|c| c.to_i}
77
- for i in 0..weights.length-1
78
- temp_cs +=weights[i]*pesel_elem[i]
79
- end
80
- control_sum = (10-(temp_cs%10))%10
81
- return pesel + control_sum.to_s
82
- elsif (data_type.eql? 'negative_data_set')
83
- return "00000000000"
84
- else
85
- return ""
86
- end
87
- end
88
-
89
- def nip_generator(data_type)
90
- if (data_type.eql? 'positive_data_set')
91
- weights = Array[6, 5, 7, 2, 3, 4, 5, 6, 7]
92
- code = rand()*998+101
93
- number = rand()*999999
94
- nip = "%d%d"%[code, number]
95
- temp_cs = 0
96
- nip_elem = nip.each_char.map{|c| c.to_i}
97
- for i in 0..weights.length-1
98
- temp_cs += weights[i]*nip_elem[i]
99
- end
100
- control_sum = temp_cs%11
101
- return nip + control_sum.to_s
102
- elsif (data_type.eql? 'negative_data_set')
103
- return "000"
104
- else
105
- return ""
106
- end
107
- end
108
- end
109
- World(GenerateData)
110
-
111
- module Utils
112
- def click(element)
113
- if (@app.config['capybara']['browser']=='phantomjs')
114
- element.trigger('click')
115
- else
116
- element.click
117
- end
118
- end
119
-
120
- def set_app(app)
121
- Capybara.app_host = @app.config['project']['default_host'][app]
122
- end
123
-
124
- def take_screenshot
125
- save_screenshot(@app.config['capybara']['save_and_open_page_path'] + "/manual_screenshots/#{Time.now.to_i}.png", :full => true)
126
- end
127
-
128
- def short_iban(iban)
129
- first_part = iban[0..1]+" "+iban[2..3]+" "+iban[4..7]
130
- middle_part=" ... "
131
- last_part=iban[-4..-1]
132
- short_iban=first_part+middle_part + last_part
133
- return short_iban
134
- end
135
-
136
- def wait_for_expected_result(timespan)
137
- _then = Time.now
138
- while true
139
- begin
140
- yield
141
- break
142
- rescue RSpec::Expectations::ExpectationNotMetError => e
143
- # Expectations were not met, check if we timed out, otherwise try one more time
144
- if Time.now > _then + timespan then
145
- puts "Timeout."
146
- raise e
147
- end
148
- end
149
- end
150
- #for debug purpose
151
- #puts "Waiting for expected result took #{Time.now - _then}s."
152
- end
153
- end
154
- World(Utils)
1
+ require 'i18n'
2
+ require 'capybara'
3
+ #require 'capybara-webkit'
4
+ require 'capybara/dsl'
5
+ require 'capybara/cucumber'
6
+ require 'capybara/poltergeist'
7
+ require 'capybara-screenshot'
8
+ require 'capybara-screenshot/cucumber'
9
+ require 'rspec/expectations'
10
+ require 'site_prism'
11
+ require 'yaml'
12
+
13
+ config = YAML::load(File.open('config/config.yml'))
14
+
15
+ I18n.enforce_available_locales = false
16
+ I18n.locale = config['framework']['i18n']['locale'].to_sym
17
+ I18n.load_path = Dir[config['framework']['i18n']['load_path']]
18
+
19
+ if config['capybara']['browser']=='phantomjs'
20
+ Capybara.register_driver :poltergeist do |app|
21
+ Capybara::Poltergeist::Driver.new app,
22
+ phantomjs_options: config['capybara']['phantomjs_specific']['options'],
23
+ window_size: config['capybara']['phantomjs_specific']['window_size']
24
+ end
25
+ Capybara.default_driver = :poltergeist
26
+ elsif config['capybara']['browser']=='capybara-webkit'
27
+ Capybara.default_driver = :webkit
28
+ Capybara.javascript_driver = :webkit
29
+ else
30
+ Capybara.register_driver :selenium do |app|
31
+ Capybara::Selenium::Driver.new(app, :browser => config['capybara']['browser'].to_sym)
32
+ end
33
+ Capybara.default_driver = :selenium
34
+ end
35
+
36
+ Capybara.save_and_open_page_path = config['capybara']['save_and_open_page_path']
37
+ Capybara.app_host = config['project']['default_host']['front']
38
+ Capybara.default_wait_time = config['capybara']['default_wait_time']
39
+ World(Capybara)
40
+
41
+ def override_method(obj, method_name, &block)
42
+ klass = class <<obj; self; end
43
+ klass.send(:undef_method, method_name)
44
+ klass.send(:define_method, method_name, block)
45
+ end
46
+
47
+ AfterConfiguration do |configuration|
48
+ override_method(configuration, :feature_files) do
49
+ potential_feature_files = with_default_features_path(paths).map do |path|
50
+ path = path.chomp('/')
51
+ if File.directory?(path)
52
+ Dir["#{path}" + config['framework']['features_regexp']].sort
53
+ elsif path[0..0] == '@' and
54
+ File.file?(path[1..-1])
55
+ IO.read(path[1..-1]).split
56
+ else
57
+ path
58
+ end
59
+ end.flatten.uniq
60
+ remove_excluded_files_from(potential_feature_files)
61
+ potential_feature_files.shuffle
62
+ end
63
+ end
64
+
65
+ module GenerateData
66
+ def pesel_generator(data_type)
67
+ if (data_type.eql? 'positive_data_set')
68
+ weights = Array[1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
69
+ year = rand()*100
70
+ month = rand()*12+1
71
+ day = rand()*28+1
72
+ evidence_number = rand()*999
73
+ sex=rand()*9
74
+ pesel="%02d%02d%02d%03d%d"%[year,month,day,evidence_number,sex]
75
+ temp_cs = 0
76
+ pesel_elem = pesel.each_char.map {|c| c.to_i}
77
+ for i in 0..weights.length-1
78
+ temp_cs +=weights[i]*pesel_elem[i]
79
+ end
80
+ control_sum = (10-(temp_cs%10))%10
81
+ return pesel + control_sum.to_s
82
+ elsif (data_type.eql? 'negative_data_set')
83
+ return "00000000000"
84
+ else
85
+ return ""
86
+ end
87
+ end
88
+
89
+ def nip_generator(data_type)
90
+ if (data_type.eql? 'positive_data_set')
91
+ weights = Array[6, 5, 7, 2, 3, 4, 5, 6, 7]
92
+ code = rand()*998+101
93
+ number = rand()*999999
94
+ nip = "%d%d"%[code, number]
95
+ temp_cs = 0
96
+ nip_elem = nip.each_char.map{|c| c.to_i}
97
+ for i in 0..weights.length-1
98
+ temp_cs += weights[i]*nip_elem[i]
99
+ end
100
+ control_sum = temp_cs%11
101
+ return nip + control_sum.to_s
102
+ elsif (data_type.eql? 'negative_data_set')
103
+ return "000"
104
+ else
105
+ return ""
106
+ end
107
+ end
108
+ end
109
+ World(GenerateData)
110
+
111
+ module Utils
112
+ def click(element)
113
+ if (@app.config['capybara']['browser']=='phantomjs')
114
+ element.trigger('click')
115
+ else
116
+ element.click
117
+ end
118
+ end
119
+
120
+ def set_app(app)
121
+ Capybara.app_host = @app.config['project']['default_host'][app]
122
+ end
123
+
124
+ def take_screenshot
125
+ save_screenshot(@app.config['capybara']['save_and_open_page_path'] + "/manual_screenshots/#{Time.now.to_i}.png", :full => true)
126
+ end
127
+
128
+ def short_iban(iban)
129
+ first_part = iban[0..1]+" "+iban[2..3]+" "+iban[4..7]
130
+ middle_part=" ... "
131
+ last_part=iban[-4..-1]
132
+ short_iban=first_part+middle_part + last_part
133
+ return short_iban
134
+ end
135
+
136
+ def wait_for_expected_result(timespan)
137
+ _then = Time.now
138
+ while true
139
+ begin
140
+ yield
141
+ break
142
+ rescue RSpec::Expectations::ExpectationNotMetError => e
143
+ # Expectations were not met, check if we timed out, otherwise try one more time
144
+ if Time.now > _then + timespan then
145
+ puts "Timeout."
146
+ raise e
147
+ end
148
+ end
149
+ end
150
+ #for debug purpose
151
+ #puts "Waiting for expected result took #{Time.now - _then}s."
152
+ end
153
+
154
+ # Function creates localalized version of a number represented by a string based on locale_spec
155
+ # eg. 123456.55 -> 123,45.55 (with locale_spec = {:separator : ',', :delimiter '.'}
156
+ # 5123456.55 -> 5 123 45,55 (with locale_spec = {:separator : ' ', :delimiter '.'}
157
+ def i18n_number(number_str, locale_spec)
158
+ splits = number_str.split('.')
159
+
160
+ unless splits.length == 2
161
+ raise Exception.new("#{number_str} doesn't contain dot.")
162
+ end
163
+
164
+ whole_part = splits[0]
165
+ fractional_part = splits[1]
166
+ separator = locale_spec[:separator]
167
+
168
+ unless fractional_part.empty?
169
+ delimiter = locale_spec[:delimiter]
170
+ else
171
+ delimiter = ''
172
+ end
173
+
174
+ negative = false
175
+ if whole_part[0] == '-'
176
+ negative = true
177
+ whole_part = whole_part[1..-1]
178
+ end
179
+
180
+ whole_part_result = ''
181
+ for i in whole_part.length.downto(1)
182
+ j = whole_part.length - i
183
+
184
+ if j % 3 == 0 and j > 0
185
+ whole_part_result = separator + whole_part_result
186
+ end
187
+
188
+ whole_part_result = whole_part[i-1] + whole_part_result
189
+ end
190
+
191
+ unless negative
192
+ return whole_part_result + delimiter + fractional_part
193
+ else
194
+ return '-' + whole_part_result + delimiter + fractional_part
195
+ end
196
+ end
197
+ end
198
+ World(Utils)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuculungwa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Kaftanski