datum 0.9.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +25 -1
- data/README.md +2 -130
- data/Rakefile +3 -9
- data/lib/datum/container.rb +64 -0
- data/lib/datum/datum.rb +51 -0
- data/lib/datum/helpers.rb +58 -0
- data/lib/datum/version.rb +8 -27
- data/lib/datum.rb +21 -93
- data/lib/plan9/structures.rb +71 -0
- data/lib/support/scenario.rb +14 -0
- data/lib/support/test.rb +27 -0
- metadata +29 -124
- data/lib/datum/context.rb +0 -55
- data/lib/datum/db_tasks.rb +0 -108
- data/lib/datum/driver_helper.rb +0 -109
- data/lib/datum/enable_notification.rb +0 -27
- data/lib/datum/enable_task.rb +0 -148
- data/lib/datum/railtie.rb +0 -14
- data/lib/datum/verification_task.rb +0 -154
- data/lib/datum/verify_helpers/20120726105125_create_datum_versions.rb +0 -18
- data/lib/datum/verify_helpers/datum_version.rb +0 -8
- data/lib/datum/verify_helpers/datum_version_test.rb +0 -11
- data/lib/generators/datum/USAGE +0 -0
- data/lib/generators/datum/datum_generator.rb +0 -104
- data/lib/generators/datum/templates/datum_migration.rb +0 -21
- data/lib/generators/datum/templates/datum_model.rb +0 -6
- data/lib/tasks/datum.rake +0 -49
- data/test/datum_test.rb +0 -17
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/application.rb +0 -61
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.example +0 -42
- data/test/dummy/config/database.sqlite +0 -25
- data/test/dummy/config/database.yml +0 -55
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -58
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/schema.rb +0 -16
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/test/lib/datum/utils/application.rb +0 -57
- data/test/dummy/test/lib/datum/utils/database.yml +0 -42
- data/test/dummy/test/test_helper.rb +0 -13
- data/test/dummy/test/unit/enable_task_test.rb +0 -70
- data/test/test_helper.rb +0 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f77d49168ee185b2c925c6d8d8fbd1ff3cb068f1
|
4
|
+
data.tar.gz: d19c0a88777502311e33d0f68fdbc96d51b1b3bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcb2e5bc40bf205726f0ee085f1b3322555da1165cf28f83a27e15216cda777dbf0d3d12b6537439d829480b2f2572cdf80cbceaeeefe93e9366fd6f3ae64f36
|
7
|
+
data.tar.gz: 93044e6c559672410de7f9475a4118998ba878e61dc1b1dd40363b3378b8ddc30e7aba246ecd56f28f43fc62be0e1ab13a22b2c67aa337efd0864c6834ffbbf7
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,28 @@
|
|
1
|
-
Copyright
|
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
|
2
26
|
|
3
27
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
28
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,137 +1,9 @@
|
|
1
|
-
##### Datum is currently
|
2
|
-
|
3
|
-
## Datum
|
4
|
-
|
5
|
-
Datum is a simple take on Data Driven Testing for Rails. Datum:
|
6
|
-
|
7
|
-
* Enables a table to drive a test case
|
8
|
-
* Quick conversion from data-driven via a database to via a file
|
9
|
-
* Dump tables to fixtures for scc storage
|
10
|
-
* Load tables from fixtures
|
11
|
-
* Generate datum specific migrations and models
|
12
|
-
|
13
|
-
## Rails 3
|
14
|
-
|
15
|
-
Datum is still in development. Currently, we're working with Rails 3.2.6 and Ruby 1.9.3.
|
16
|
-
|
17
|
-
For now, our target test framework is <b>Test::Unit</b>.
|
18
|
-
|
19
|
-
## Getting Started
|
20
|
-
|
21
|
-
Datum is a simple tool for data driven testing. If you have a test case that you can parameterize and want to manage your parameters via a database, Datum is fun.
|
22
|
-
|
23
|
-
### Setting Up
|
24
|
-
|
25
|
-
Add Datum to your Gemfile:
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
gem 'datum'
|
29
|
-
```
|
30
|
-
|
31
|
-
Run the bundle command to install it.
|
32
|
-
|
33
|
-
After you install Datum and add it to your Gemfile, you need to enable it:
|
34
|
-
|
35
|
-
```console
|
36
|
-
rake datum:enable
|
37
|
-
```
|
38
|
-
|
39
|
-
Enable will create several directories in your test directory. It will also prompt you to ask for permission to update your database.yml and application.rb. You MUST review both files even if you have Enable update them for you.
|
40
|
-
|
41
|
-
Additionally, Enable will further prompt you for permission to verify all core Datum functionality. Verification will include all basic Datum rake tasks along with execution of tests that use Datum's drive_with.
|
42
|
-
|
43
|
-
<span style="color: red;">WARNING:</span> Enable's verification <b>WILL DROP the Datum Database</b>. If you are re-installing Datum, be sure to back-up your Datum store BEFORE running Enable.
|
44
|
-
|
45
|
-
When finished, you are ready to create a Datum specific database and add migrations and models.
|
46
|
-
|
47
|
-
### Creating a Datum Specific Database and Tables
|
48
|
-
|
49
|
-
To create a Datum specific database:
|
50
|
-
|
51
|
-
```console
|
52
|
-
rake datum:db:create
|
53
|
-
```
|
54
|
-
|
55
|
-
To generate Datum specific migrations and models, the command and options are similar to using Rails scaffolds.
|
56
|
-
|
57
|
-
```console
|
58
|
-
rails generate datum ModelName column_one:type column_two:type
|
59
|
-
```
|
60
|
-
|
61
|
-
Models and migrations are placed in your application under test/lib/datum/models and test/lib/datum/migrate. Edit these files as needed. When you are ready to migrate use the Datum migration command.
|
62
|
-
|
63
|
-
```console
|
64
|
-
rake datum:db:migrate
|
65
|
-
```
|
66
|
-
|
67
|
-
You are now ready to put data in a newly created table.
|
68
|
-
|
69
|
-
### Binding a Test Case to a Table
|
70
|
-
|
71
|
-
When writing a unit test or functional test with <b>Test::Unit</b>, bind your test case to your table with drive_with.
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
test "vote_counter should count positive votes" do
|
75
|
-
drive_with :table_items
|
76
|
-
```
|
77
|
-
|
78
|
-
Once bound to your table, drive_with will work with the Datum infrastructure so that your test case will execute once for every row in the table.
|
79
|
-
|
80
|
-
To access the current row, use the datum accessor:
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
test "vote_counter should count positive votes" do
|
84
|
-
drive_with :table_items
|
85
|
-
puts "starting test case..."
|
86
|
-
puts "the current id of the row: #{datum.id}"
|
87
|
-
```
|
88
|
-
|
89
|
-
Will output:
|
90
|
-
|
91
|
-
```console
|
92
|
-
starting test case...
|
93
|
-
1
|
94
|
-
|
95
|
-
starting test case...
|
96
|
-
2
|
97
|
-
|
98
|
-
starting test case...
|
99
|
-
3
|
100
|
-
```
|
101
|
-
### Move Datum Table Data Beyond the Datum Database
|
102
|
-
|
103
|
-
To convert your Datum tables to fixtures (for storage in scc, etc)
|
104
|
-
|
105
|
-
```console
|
106
|
-
rake datum:db:dump
|
107
|
-
```
|
108
|
-
|
109
|
-
To get Datum data from fixtures into the Datum specific database:
|
110
|
-
|
111
|
-
```console
|
112
|
-
rake datum:db:load
|
113
|
-
```
|
114
|
-
|
115
|
-
To convert a Datum table into a file so that drive_with does <b>not</b> use the table (and is thus <b>not</b> dependent on a Datum database / settings / etc)
|
116
|
-
|
117
|
-
```console
|
118
|
-
rake datum:db:localize[table_items]
|
119
|
-
```
|
120
|
-
|
121
|
-
## Troubleshooting
|
122
|
-
|
123
|
-
### In Development
|
124
|
-
Datum is still being created and isn't officially *ready*. It's likely that we have code paths that are not fully tested and some that are plain broken. Stay tuned for a 1.0.
|
125
|
-
|
126
|
-
## Additional Information
|
127
|
-
|
128
|
-
### Tyemill
|
129
|
-
Tyemill is a technology company in Seattle, Washington. We make a few line-of-business applications and love Ruby, Rails and Open Source.
|
1
|
+
##### Datum is currently being updated. Hold on.
|
130
2
|
|
131
3
|
## License
|
132
4
|
(The MIT License)
|
133
5
|
|
134
|
-
Copyright 2012 Tyemill LLC. http://tyemill.com
|
6
|
+
Copyright 2012 - 2015 Tyemill LLC. http://tyemill.com
|
135
7
|
|
136
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:
|
137
9
|
|
data/Rakefile
CHANGED
@@ -1,16 +1,10 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
1
|
begin
|
3
2
|
require 'bundler/setup'
|
4
3
|
rescue LoadError
|
5
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
5
|
end
|
7
|
-
|
8
|
-
|
9
|
-
rescue LoadError
|
10
|
-
require 'rdoc/rdoc'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
14
8
|
|
15
9
|
RDoc::Task.new(:rdoc) do |rdoc|
|
16
10
|
rdoc.rdoc_dir = 'rdoc'
|
@@ -35,4 +29,4 @@ Rake::TestTask.new(:test) do |t|
|
|
35
29
|
end
|
36
30
|
|
37
31
|
|
38
|
-
task :
|
32
|
+
task default: :test
|
@@ -0,0 +1,64 @@
|
|
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
ADDED
@@ -0,0 +1,51 @@
|
|
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
|
@@ -0,0 +1,58 @@
|
|
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
CHANGED
@@ -1,30 +1,11 @@
|
|
1
1
|
module Datum
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "4.0.0"
|
3
3
|
end
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
##
|
8
|
-
##
|
9
|
-
##
|
10
|
-
## 0.
|
11
|
-
##
|
12
|
-
## 0.8.4
|
13
|
-
## Fixed bug with leftover verification test case.
|
14
|
-
## 0.8.5
|
15
|
-
## Fixed bug with pre-existing datum database (verification failed when
|
16
|
-
## pre-existing store exists)
|
17
|
-
## 0.8.6
|
18
|
-
## Fixed migration not observing schema version (regression)
|
19
|
-
## Updated drop to use connection instead of rake task (unreliable)
|
20
|
-
## 0.8.7
|
21
|
-
## Added db:prepare rake task
|
22
|
-
## 0.9.0
|
23
|
-
## prepare no longer uses load, instead it uses load_when_empty
|
24
|
-
## attr_accessor added to datum_version model
|
25
|
-
## 0.9.1
|
26
|
-
## updated datum_migration template to include attr_accessible for all
|
27
|
-
## attributes
|
28
|
-
## fixed datum verification to use attr_accessible
|
29
|
-
## 0.9.2
|
30
|
-
## tiny update to fix template for models
|
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
CHANGED
@@ -1,101 +1,29 @@
|
|
1
|
-
# datum helps data-driven testing.
|
2
|
-
#
|
3
|
-
# Author:: Gabriel Marius, Tyemill
|
4
|
-
# Copyright:: Copyright (c) 2012 Tyemill, llc.
|
5
|
-
# License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
|
6
1
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
|
2
|
+
require "datum/helpers"
|
3
|
+
require "datum/datum"
|
4
|
+
require "datum/container"
|
5
|
+
require "support/test"
|
6
|
+
require "support/scenario"
|
11
7
|
|
12
8
|
module Datum
|
13
|
-
|
14
|
-
alias_method :original_initialize, :initialize
|
15
|
-
|
16
|
-
|
17
|
-
def initialize(tst)
|
18
|
-
log NEW_TST
|
19
|
-
original_initialize tst
|
20
|
-
end
|
21
|
-
|
22
|
-
def drive_with table
|
23
|
-
datum_helper::load_data table if !datum_context::initialized?
|
24
|
-
@@driver_row = datum_context.next_row
|
25
|
-
log "drive_with table: #{table}"
|
26
|
-
#log "drive_with row: #{@@driver_row.attributes}" unless @@driver_row.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
def datum
|
30
|
-
return @@driver_row
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
@@driver_row = nil
|
35
|
-
NEW_TST = "@@@ N E W T S T C A S E @@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
36
|
-
def log msg
|
37
|
-
datum_helper.log msg
|
38
|
-
end
|
39
|
-
|
40
|
-
def datum_helper
|
41
|
-
return Datum::DriverHelper
|
42
|
-
end
|
43
|
-
|
44
|
-
def datum_context
|
45
|
-
return Datum::Context
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
MiniTest::Unit.class_eval do
|
51
|
-
alias_method :original__run_suite, :_run_suite
|
9
|
+
@@all_containers, @@scenario_path, @@data_path, @@datum_path = nil
|
52
10
|
|
53
|
-
|
54
|
-
header = "#{type}_suite_header"
|
55
|
-
puts send(header, suite) if respond_to? header
|
11
|
+
class << self
|
56
12
|
|
57
|
-
|
58
|
-
|
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
|
59
21
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
while datum_context::continue? || p_test != test_case do
|
65
|
-
__runner assertions, test_case, suite
|
66
|
-
p_test = test_case
|
67
|
-
end
|
68
|
-
}
|
69
|
-
return assertions.size, assertions.inject(0) { |sum, n| sum + n }
|
22
|
+
private
|
23
|
+
def add_container container, key
|
24
|
+
::Datum.containers[key] = container
|
25
|
+
::Datum.instance_variable_set(:"@current_container", container)
|
70
26
|
end
|
71
|
-
|
72
|
-
def __runner(assertions, test_case, suite)
|
73
|
-
testcase_result = inner_runner(test_case, suite)
|
74
|
-
assertions.push testcase_result
|
75
|
-
end
|
76
|
-
|
77
|
-
def inner_runner(method, suite)
|
78
|
-
inst = suite.new method
|
79
|
-
inst._assertions = 0
|
80
|
-
print "#{suite}##{method} = " if @verbose
|
81
|
-
@start_time = Time.now
|
82
|
-
datum_init = datum_context::initialized?
|
83
|
-
result = inst.run self
|
84
|
-
time = Time.now - @start_time
|
85
|
-
print "%.2f s = " % time if @verbose
|
86
|
-
result = Datum::DriverHelper::add_datum_exec_ext datum_init, result
|
87
|
-
print result
|
88
|
-
puts if @verbose
|
89
|
-
|
90
|
-
inst._assertions
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
def datum_context
|
95
|
-
return Datum::Context
|
96
|
-
end
|
97
|
-
|
27
|
+
def current_container; @current_container; end;
|
98
28
|
end
|
99
|
-
|
100
|
-
|
101
|
-
end
|
29
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
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
ADDED
@@ -0,0 +1,27 @@
|
|
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
|