test-factory 0.4.3 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDg0Nzk0MDdiOGIyMDAzNjlmMTA1NTUxYTlhN2ViMTViNDRjODMzOQ==
4
+ Y2IzNTk5NjIwMTI3ZDRiMzcyZmE1MDcxZDg1MTVjODZjMWRmODRkYQ==
5
5
  data.tar.gz: !binary |-
6
- YWU1ZTk0YmJlMmVkMzU1MzIwNTVlNzMzNDJhOWFiYjE0ZTQ5OTkwMQ==
6
+ NDM0ZTRlYmI0ZmI5NDAzYTk0YWViMmM3NWE5NTk0MGQzY2I3YzFmOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OWI1NTgxMmZkOWU5OTMyNWY5N2I0YjQ5Y2RkZTNlMWMzOTQwOTI2NmY3YjYz
10
- OGQzMTU2NzJhMjdkN2U4NTJiMmZiMmMxNTY0MjVmYWFiZmNlZjIzNGY1MGJk
11
- MDMwZmVlM2M1NWE3NmYwY2M5Yjk0ODNkMWQ4MzI1ZjZmYTdjMGU=
9
+ ZmE2NDVmMGY4NTAzZWIzMTFhZjZlN2FlNWQxNTUwOTJhMzU2YjJkOGQ2NTk4
10
+ ZGYwMDE0NTg0ZjBhZDBkNGU0MTdlYWM3NDBlNGU1NGJjZjNhYTNhY2NhNGNm
11
+ YzY5OGEyZjg2ODU2OTExZWZhODRhYzM5NDFlODVlMWZjYWE3ODY=
12
12
  data.tar.gz: !binary |-
13
- ZWU4N2NjYTQzOGM0NDA4MTU4YTBiOWRlZmE1OWQ2NTE3NjgyODg5YTg0MDcx
14
- ZDIwYWQ5ZDgxNjFiZjlhZDkyZjkyMzNhMTdmYTU0ZmE1NjcyNzhlOTJmYTdi
15
- NThjN2QzZjEwYmQ3ZTZmMzdhMDgwNWExODQ4NDFkMzM0ZjRmMGM=
13
+ MjI4ODUxNDcwZWE5YjJjZjllN2ZmYzAzOGUyZjk3NTIxMWRlOTA2ZDNhOGEy
14
+ OGE3YTYxMjM0MTVkNTVmM2RlYjhhMTQyYjI0ZmFjMzc0MDY3ZDY4NzcwNWUz
15
+ NGUwZGFmZTMyODBhODE3MzllZTc5ZWM2NDQwMzRkMTA5NWI4ODQ=
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -51,6 +51,16 @@ class CollectionsFactory < Array
51
51
  new_collection
52
52
  end
53
53
 
54
+ # Used in conjunction with the Parent object containing
55
+ # the collection.
56
+ #
57
+ # The parent sends updated information to the collection(s)
58
+ # using #notify_collections
59
+ #
60
+ def notify_members *updates
61
+ self.each { |member| member.update_from_parent *updates }
62
+ end
63
+
54
64
  end
55
65
 
56
66
  # Just an alias class name.
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,16 +12,58 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Provides a set of tools used to create your Data Object classes.
16
- module DataFactory
15
+ # The Superclass for all of your data objects.
16
+ class DataFactory
17
+
18
+ include Foundry
19
+
20
+ # Since Data Objects are not "Marshallable", and they generally
21
+ # contain lots of types of data in their instance variables,
22
+ # we have this method. This will create and return a 'deep copy' of
23
+ # the data object as well as any and all nested data objects
24
+ # and collections it contains.
25
+ #
26
+ # Please note that this method will fail if you are putting
27
+ # Data Objects into Arrays or Hashes instead
28
+ # of into Collection classes
29
+ #
30
+ def data_object_copy
31
+ opts = {}
32
+ self.instance_variables.each do |var|
33
+ key = var.to_s.gsub('@','').to_sym
34
+ orig_val = instance_variable_get var
35
+ opts[key] = case
36
+ when orig_val.kind_of?(CollectionsFactory)
37
+ orig_val.copy
38
+ when orig_val.instance_of?(Array) || orig_val.instance_of?(Hash)
39
+ begin
40
+ Marshal::load(Marshal.dump(orig_val))
41
+ rescue TypeError
42
+ raise %{\nKey: #{key.inspect}\nValue: #{orig_val.inspect}\nClass: #{orig_val.class}\n\nThe copying of the Data Object has thrown a TypeError,\nwhich means the object detailed above is not "Marshallable".\nThe most likely cause is that you have put\na Data Object inside an\nArray or Hash.\nIf possible, put the Data Object into a Collection.\n\n}
43
+ end
44
+ when orig_val.kind_of?(DataFactory)
45
+ orig_val.data_object_copy
46
+ else
47
+ orig_val
48
+ end
49
+ end
50
+ self.class.new(@browser, opts)
51
+ end
17
52
 
18
53
  # Add this to the bottom of your Data Object's initialize method.
19
- # Converts the contents of the hash into the class's instance variables.
54
+ # This method does 2 things:
55
+ # 1) Converts the contents of the hash into the class's instance variables.
56
+ # 2) Grabs the names of your collection class instance variables and stores
57
+ # them in an Array. This is to allow for the data object class to send
58
+ # any needed updates to its children. See #notify_coolections for more
59
+ # details.
20
60
  # @param hash [Hash] Contains all options required for creating the needed Data Object
21
61
  #
22
62
  def set_options(hash)
63
+ @collections = []
23
64
  hash.each do |key, value|
24
65
  instance_variable_set("@#{key}", value)
66
+ @collections << key if value.kind_of?(CollectionsFactory)
25
67
  end
26
68
  end
27
69
  alias update_options set_options
@@ -253,6 +295,20 @@ module DataFactory
253
295
  end
254
296
  end
255
297
 
298
+ # Define this method in your data object when
299
+ # it has a parent, and that parent
300
+ # may periodically need to send
301
+ # it updated information about itself.
302
+ #
303
+ def update_from_parent(update)
304
+ raise %{
305
+ This method must be implemented in your data object
306
+ class if you plan to pass updates from a
307
+ parent object to the members of its
308
+ collections.
309
+ }
310
+ end
311
+
256
312
  # =======
257
313
  private
258
314
  # =======
@@ -274,4 +330,33 @@ module DataFactory
274
330
  end
275
331
  end
276
332
 
333
+ # Use this method in conjunction with your nested
334
+ # collection classes. The collections will notify
335
+ # their members about the passed parameters.
336
+ #
337
+ # Note: You must write a custom #update_from_parent
338
+ # method in your data object that will know what to
339
+ # do with the parameter(s) passed to it.
340
+ #
341
+ def notify_collections *updates
342
+ @collections.each {|coll| instance_variable_get("@#{coll}").notify_members *updates }
343
+ end
344
+
345
+ end
346
+
347
+ # An alias, for backwards compatibility...
348
+ class DataObject < DataFactory
349
+
350
+ warn %{
351
+ Welcome to version 0.4.5!
352
+
353
+ Please update all your Data Object classes to
354
+ inherit from DataFactory
355
+ instead of DataObject.
356
+
357
+ Note that in the future this warning will be going
358
+ away. You'll just get an error, so
359
+ be sure you update your project soon!
360
+ }
361
+
277
362
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # coding: UTF-8
2
2
 
3
- # Copyright 2012-2013 The rSmart Group, Inc.
3
+ # Copyright 2012-2014 The rSmart Group, Inc.
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@ module StringFactory
20
20
  # A random string creator that draws from all printable ASCII characters
21
21
  # from 33 to 128. Default length is 10 characters.
22
22
  # @param length [Integer] The count of characters in the string
23
- # @param s [String] Typically this will be left blank, but if included, any string created will be prepended with s. Note that the string length will still be as specified
23
+ # @param s [String] Typically this will be left blank, but if included, any string created will be prepended with s. Note that the string length will
24
+ # be longer by the size of the pre-pended string.
24
25
  #
25
26
  def random_string(length=10, s="")
26
27
  length.enum_for(:times).inject(s) { s << rand(93) + 33 }
@@ -29,7 +30,8 @@ module StringFactory
29
30
  # A random string creator that draws from all printable ASCII and High ASCII characters
30
31
  # from 33 to 256. Default length is 10 characters.
31
32
  # @param length [Integer] The count of characters in the string
32
- # @param s [String] Typically this will be left blank, but if included, any string created will be prepended with s. Note that the string length will still be as specified
33
+ # @param s [String] Typically this will be left blank, but if included, any string created will be prepended with s. Note that the string length will be
34
+ # longer by the length of the pre-pended string.
33
35
  #
34
36
  def random_high_ascii(length=10, s="")
35
37
  length.enum_for(:times).inject(s) { s << rand(223) + 33 }
data/lib/test-factory.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
1
+ # Copyright 2012-2014 The rSmart Group, Inc.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
data/test-factory.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'test-factory'
3
- s.version = '0.4.3'
3
+ s.version = '0.4.5'
4
4
  s.summary = %q{rSmart's framework for creating automated testing scripts}
5
5
  s.description = %q{This gem provides a set of modules and methods to help quickly and DRYly create a test automation framework using Ruby and Watir (or watir-webdriver).}
6
6
  s.files = Dir.glob("**/**/**")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abraham Heward
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: watir-webdriver
@@ -38,7 +38,6 @@ files:
38
38
  - lib/test-factory/collections_factory.rb
39
39
  - lib/test-factory/core_ext.rb
40
40
  - lib/test-factory/data_factory.rb
41
- - lib/test-factory/data_object.rb
42
41
  - lib/test-factory/date_factory.rb
43
42
  - lib/test-factory/foundry.rb
44
43
  - lib/test-factory/gem_ext.rb
@@ -1,53 +0,0 @@
1
- # Copyright 2012-2013 The rSmart Group, Inc.
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
-
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- # The Superclass for all of your data objects.
16
- class DataObjectFactory
17
-
18
- include Foundry
19
- include DataFactory
20
-
21
- # Since Data Objects are not "Marshallable", and they generally
22
- # contain lots of types of data in their instance variables,
23
- # we have this method. This will create and return a 'deep copy' of
24
- # the data object as well as any and all nested data objects
25
- # and collections it contains.
26
- #
27
- # Please note that this method will fail if you are putting
28
- # Data Objects into Arrays or Hashes instead
29
- # of into Collection classes
30
- #
31
- def data_object_copy
32
- opts = {}
33
- self.instance_variables.each do |var|
34
- key = var.to_s.gsub('@','').to_sym
35
- orig_val = instance_variable_get var
36
- opts[key] = case
37
- when orig_val.kind_of?(CollectionsFactory)
38
- orig_val.copy
39
- when orig_val.instance_of?(Array) || orig_val.instance_of?(Hash)
40
- Marshal::load(Marshal.dump(orig_val))
41
- when orig_val.kind_of?(DataObject)
42
- orig_val.data_object_copy
43
- else
44
- orig_val
45
- end
46
- end
47
- self.class.new(@browser, opts)
48
- end
49
-
50
- end
51
-
52
- # Empty alias class
53
- class DataObject < DataObjectFactory; end