datum 4.0.0 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f77d49168ee185b2c925c6d8d8fbd1ff3cb068f1
4
- data.tar.gz: d19c0a88777502311e33d0f68fdbc96d51b1b3bb
3
+ metadata.gz: bb2d6d84f89ffc9d2380e4db9d82da26f7a3a9bf
4
+ data.tar.gz: b7cc6d41b42ba6ebdb0508a050ec5a78f359e60e
5
5
  SHA512:
6
- metadata.gz: dcb2e5bc40bf205726f0ee085f1b3322555da1165cf28f83a27e15216cda777dbf0d3d12b6537439d829480b2f2572cdf80cbceaeeefe93e9366fd6f3ae64f36
7
- data.tar.gz: 93044e6c559672410de7f9475a4118998ba878e61dc1b1dd40363b3378b8ddc30e7aba246ecd56f28f43fc62be0e1ab13a22b2c67aa337efd0864c6834ffbbf7
6
+ metadata.gz: 7dace5163e5d7fa38f1ebb6f675090c8a5b313846769c4fc6e917731582569bb8254a71efc0b5fb02ba14fa853caa803b28450f4d24e2baf5e9da574daec536a
7
+ data.tar.gz: 8388f9a6ec216e3e2e1fd521fb05ba8dfb847a1d6b1799e716614faa90672cc915ca3d9495cb6d14cba096e8c38a0efc9f18f0971ce8a9a28b2447d6bb0cc036
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datum
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyemill
@@ -44,18 +44,7 @@ email:
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
- files:
48
- - MIT-LICENSE
49
- - README.md
50
- - Rakefile
51
- - lib/datum.rb
52
- - lib/datum/container.rb
53
- - lib/datum/datum.rb
54
- - lib/datum/helpers.rb
55
- - lib/datum/version.rb
56
- - lib/plan9/structures.rb
57
- - lib/support/scenario.rb
58
- - lib/support/test.rb
47
+ files: []
59
48
  homepage: https://github.com/tyemill/datum
60
49
  licenses:
61
50
  - MIT
data/MIT-LICENSE DELETED
@@ -1,44 +0,0 @@
1
- Copyright 2015 Tyemill
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- #### From https://github.com/iconara/immutable_struct/blob/master/LICENSE
23
- #### Provided due to use of immutable_struct/blob/master/lib/immutable_struct.rb
24
-
25
- Copyright (c) 2010 Theo Hultberg
26
-
27
- Permission is hereby granted, free of charge, to any person obtaining
28
- a copy of this software and associated documentation files (the
29
- "Software"), to deal in the Software without restriction, including
30
- without limitation the rights to use, copy, modify, merge, publish,
31
- distribute, sublicense, and/or sell copies of the Software, and to
32
- permit persons to whom the Software is furnished to do so, subject to
33
- the following conditions:
34
-
35
- The above copyright notice and this permission notice shall be
36
- included in all copies or substantial portions of the Software.
37
-
38
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
42
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
43
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
44
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,12 +0,0 @@
1
- ##### Datum is currently being updated. Hold on.
2
-
3
- ## License
4
- (The MIT License)
5
-
6
- Copyright 2012 - 2015 Tyemill LLC. http://tyemill.com
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
-
12
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,32 +0,0 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Datum'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
- Bundler::GemHelper.install_tasks
21
-
22
- require 'rake/testtask'
23
-
24
- Rake::TestTask.new(:test) do |t|
25
- t.libs << 'lib'
26
- t.libs << 'test'
27
- t.pattern = 'test/**/*_test.rb'
28
- t.verbose = false
29
- end
30
-
31
-
32
- task default: :test
@@ -1,64 +0,0 @@
1
- require "datum/helpers"
2
-
3
- module Datum
4
- # A Container object holds attributes for a single data test.
5
- class Container
6
-
7
- # @return [String] the name of the data test method
8
- attr_reader :data_method_name
9
- # @return [TestCase] the ActiveSupport::TestCase instance of the data test
10
- attr_reader :test_instance
11
-
12
- # constructor
13
- #
14
- # @param data_method_name [String] the name of test method to be called
15
- # @param tst_instance [TestCase] the instance containing the data_method_name
16
- def initialize(data_method_name, tst_instance)
17
- @data_method_name = data_method_name; @test_instance = tst_instance
18
- @loaded_data = {}; @invoked_data = {}
19
- ::Datum.send(:add_container, self,
20
- Container.key(@test_instance, @data_method_name))
21
- end
22
-
23
- # @return [int] The total number of tests / data elements / datums
24
- def count; @loaded_data.count + @invoked_data.count; end;
25
- # @return [Hash] of data
26
- def data; @loaded_data.merge(@invoked_data); end
27
-
28
- alias_method :length, :count
29
- alias_method :size, :count
30
- alias_method :test_count, :count
31
-
32
- # @param [TestCase] the ActiveSupport::TestCase instance for the data_test
33
- # @param [String] the name of the data_test method
34
- # @return [String] Container compatible Hash key
35
- def self.key tst_instance, data_method_name
36
- Helpers.build_key(tst_instance, data_method_name)
37
- end
38
-
39
- private
40
-
41
- def add_datum datum
42
- test_name = Helpers.build_test_name(data_method_name, test_count + 1)
43
- @loaded_data[Datum.key(test_instance, test_name)] = datum
44
- add_data_test test_name
45
- [count, test_name]
46
- end
47
-
48
- def invoke_datum key, tst_case
49
- @invoked_data[key] = datum = @loaded_data.delete(key)
50
- tst_case.instance_variable_set :@datum, datum
51
- tst_case.send datum.container.data_method_name
52
- end
53
-
54
- def add_data_test test_name
55
- test_instance.send(:define_method, test_name) do
56
- datum_key = Datum.key(nm = self.class.to_s, __method__)
57
- container_key = Container.key(nm,
58
- Helpers.data_method_from_test_name(__method__))
59
- ::Datum.containers[container_key].send(:invoke_datum, datum_key, self)
60
- end
61
- end
62
-
63
- end
64
- end
data/lib/datum/datum.rb DELETED
@@ -1,51 +0,0 @@
1
- require "datum/container"
2
- require "datum/helpers"
3
- require "plan9/structures"
4
-
5
- module Datum
6
- # Datum ImmutableStruct to be extended by data_test test cases
7
- class Datum < Plan9::ImmutableStruct
8
- def self.new(*attrs, &block)
9
- attrs.push "datum_id"
10
- super(*attrs, &block)
11
- end
12
-
13
- # @return [String] Datum compatible Hash key
14
- def self.key test_instance, test_name
15
- Helpers.build_key(test_instance, test_name)
16
- end
17
-
18
- protected
19
-
20
- def self.init_new(struct)
21
- super(struct)
22
- datumize_constructor!(struct)
23
- struct
24
- end
25
-
26
- private
27
- def self.datumize_constructor! struct
28
-
29
- struct.class_eval do
30
- alias_method :datum_initialize, :initialize
31
-
32
- # @return [String] The name of the test method
33
- attr_reader :test_method_name
34
- # @return [Container] A reference to the Container of this Datum
35
- attr_reader :container
36
-
37
- def initialize(*atrs)
38
- dtm_id = configure_attributes
39
- is_hash_case?(*atrs) ? atrs.first[:datum_id] = dtm_id : atrs.push(dtm_id)
40
- datum_initialize(*atrs)
41
- end
42
-
43
- private
44
- def configure_attributes
45
- @container = ::Datum.send(:current_container)
46
- (dtm_id, @test_method_name = @container.send(:add_datum, self))[0]
47
- end
48
- end
49
- end
50
- end
51
- end
data/lib/datum/helpers.rb DELETED
@@ -1,58 +0,0 @@
1
- module Datum
2
- # Various helper functions
3
- class Helpers
4
- class << self
5
-
6
- # @param test_name [String] test case name generated from data_test usage
7
- # @return [int] the index of the data_test / datum_id
8
- def index_from_test_name test_name
9
- ((test_name.to_s.split('_')[-1]).to_i)
10
- end
11
-
12
- # @param test_name [String] test case name generated from data_test usage
13
- # @return [String] name of the data_test method which generated the test
14
- def data_method_from_test_name test_name
15
- test_name.slice(/(?<=_).*(?=_)/)
16
- end
17
-
18
- # @param data_method_name [String] the name of the data_test method
19
- # @param counter [int] the index / datum_id of the current test case
20
- # @return [String] test name for current test case, index, data_test method
21
- def build_test_name data_method_name, counter
22
- "test_#{data_method_name}_#{counter}"
23
- end
24
-
25
- # @param test_instance [TestCase] the ActiveSupport::TestCase instance
26
- # @param method [String] the name of the method
27
- # @return [String] a key for usage in Datum-compatible Hash instances
28
- def build_key test_instance, method
29
- "#{test_instance}_#{method}"
30
- end
31
-
32
- # @param file_name [String] the name of the file to read
33
- # @param directory [Pathname] a Pathname representing the file's directory
34
- # @param ext [String] optional extention of the file (default: '.rb')
35
- # @return [String] the file's contents
36
- def read_file file_name, directory, ext = ".rb"
37
- File.read directory.join("#{file_name}#{ext}")
38
- end
39
-
40
- # reads a ruby file and eval's it's contents at the current code location
41
- # @param file_name [String] the name of the file to import
42
- # @param directory [Pathname] a Pathname representing the file's directory
43
- # @param current_binding [Binding] context at a particular code location
44
- def import_file file_name, directory, current_binding
45
- eval(read_file(file_name, directory), current_binding)
46
- end
47
-
48
- # @param resource [ActiveRecord::Base] an ActiveRecord Model instance
49
- # @param override_hash [Hash] Hash of attributes / values to override from
50
- # return [Hash] Hash of attributes from provided resource
51
- def clone_resource resource, override_hash = nil
52
- override_hash.nil? ? resource.dup.attributes.with_indifferent_access :
53
- resource.dup.attributes.merge(
54
- override_hash.with_indifferent_access).with_indifferent_access
55
- end
56
- end
57
- end
58
- end
data/lib/datum/version.rb DELETED
@@ -1,11 +0,0 @@
1
- module Datum
2
- VERSION = "4.0.0"
3
- end
4
-
5
-
6
-
7
- ## 0.8.1 - 0.9.2
8
- ## Original datum, proof-of-concept
9
- ##
10
- ## 4.0.0
11
- ## Full rewrite, updated with latest concepts and code -- Still in Testing
data/lib/datum.rb DELETED
@@ -1,29 +0,0 @@
1
-
2
- require "datum/helpers"
3
- require "datum/datum"
4
- require "datum/container"
5
- require "support/test"
6
- require "support/scenario"
7
-
8
- module Datum
9
- @@all_containers, @@scenario_path, @@data_path, @@datum_path = nil
10
-
11
- class << self
12
-
13
- # @return [Pathname] fully qualified path for the root of datum directory
14
- def path; @@datum_path ||= Rails.root.join('test', 'datum'); end
15
- # @return [Pathname] fully qualified path for the datum/data directory
16
- def data_path; @@data_path ||= ::Datum.path.join('data'); end
17
- # @return [Pathname] fully qualified path for the datum/scenarios directory
18
- def scenario_path; @@scenario_path ||= ::Datum.path.join('scenarios'); end
19
- # @return [Hash] Hash of all loaded Containers
20
- def containers; @@all_containers ||= {}; end
21
-
22
- private
23
- def add_container container, key
24
- ::Datum.containers[key] = container
25
- ::Datum.instance_variable_set(:"@current_container", container)
26
- end
27
- def current_container; @current_container; end;
28
- end
29
- end
@@ -1,71 +0,0 @@
1
- module Plan9
2
-
3
- # A few improvements to a Ruby Struct
4
- #
5
- # Re-organized slightly, this code is reused from 'ImmutableStruct'
6
- # by Theo Hultberg. See https://github.com/iconara/immutable_struct
7
- # Copyright notice mentioned in the LICENSE file.
8
- #
9
- class ImprovedStruct
10
- def self.new(*attrs, &block)
11
- init_new(Struct.new(*attrs, &block))
12
- end
13
- protected
14
- def self.init_new(struct)
15
- optionalize_constructor!(struct)
16
- extend_dup!(struct)
17
- struct
18
- end
19
- private
20
- def self.optionalize_constructor!(struct)
21
- struct.class_eval do
22
- alias_method :struct_initialize, :initialize
23
-
24
- def initialize(*attrs)
25
- if is_hash_case?(*attrs)
26
- struct_initialize(*members.map { |m| attrs.first[m.to_sym] })
27
- else
28
- struct_initialize(*attrs)
29
- end
30
- end
31
-
32
- protected
33
- # @return (bool) true if attrs are Hash, false otherwise
34
- def is_hash_case?(*a)
35
- members.size > 1 && a && a.size == 1 && a.first.instance_of?(Hash)
36
- end
37
- end
38
- end
39
-
40
- def self.extend_dup!(struct)
41
- struct.class_eval do
42
- def dup(overrides={})
43
- self.class.new(to_h.merge(overrides))
44
- end
45
- end
46
- end
47
- end
48
-
49
- # A read-only Struct
50
- #
51
- # Re-organized slightly, this code is reused from 'ImmutableStruct'
52
- # by Theo Hultberg. See https://github.com/iconara/immutable_struct
53
- # Copyright notice mentioned in the LICENSE file.
54
- class ImmutableStruct < ImprovedStruct
55
- protected
56
- def self.init_new(struct)
57
- make_immutable!(struct)
58
- super(struct)
59
- end
60
-
61
- private
62
- def self.make_immutable!(struct)
63
- # removes the member= method, to prevent write
64
- struct.send(:undef_method, "[]=".to_sym)
65
- struct.members.each do |member|
66
- struct.send(:undef_method, "#{member}=".to_sym)
67
- end
68
- end
69
-
70
- end
71
- end
@@ -1,14 +0,0 @@
1
-
2
- # for use in a scenario file, imports an existing scenario's code and objects
3
- # @param scenario_name (Symbol) the name of a scenario file
4
- def __import scenario_name
5
- ::Datum::Helpers.import_file scenario_name, ::Datum.scenario_path, binding
6
- end
7
-
8
- # for use in a scenario file, clones the attributes of an existing instance
9
- # @param resource [ActiveRecord::Base] an ActiveRecord Model instance
10
- # @param override_hash [Hash] Hash of attributes / values to override from
11
- # return [Hash] Hash of attributes from provided resource
12
- def __clone resource, override_hash = nil
13
- ::Datum::Helpers.clone_resource resource, override_hash
14
- end
data/lib/support/test.rb DELETED
@@ -1,27 +0,0 @@
1
-
2
-
3
- require "datum/helpers"
4
- require "datum/container"
5
- require "datum/datum"
6
-
7
- # Extends ActiveSupport::Test with the process_scenario method
8
- #
9
- # @note supports most extending test types (functional, integration, etc)
10
- class ActiveSupport::TestCase
11
- include Datum
12
- # imports a scenario file into the context of current test
13
- # @param scenario_name (Symbol) the name of a scenario file
14
- def process_scenario scenario_name
15
- __import(scenario_name)
16
- end
17
- end
18
-
19
- # Used to define a test to work in conjuction with Datum struct extensions
20
- # found in a file with the same name in the test/datum/data directory
21
- # @param name (String) name of the file in the datum/data directory
22
- # @param block (block) a block of Ruby code
23
- def data_test name, &block
24
- ::Datum::Container.new(name, self)
25
- self.send(:define_method, name, &block)
26
- self.class_eval(::Datum::Helpers.read_file(name, ::Datum.data_path))
27
- end