fixturizer 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/dependencies.rb +1 -0
- data/lib/fixturizer/getters/init.rb +28 -0
- data/lib/fixturizer/getters/json.rb +16 -0
- data/lib/fixturizer/getters/yaml.rb +16 -0
- data/lib/fixturizer/rake/rules/database.rake +2 -1
- data/lib/fixturizer/rspec/helpers/getter.rb +24 -0
- data/lib/fixturizer/rspec/helpers/serializer.rb +1 -1
- data/lib/fixturizer/services.rb +4 -0
- data/lib/fixturizer/settings.rb +2 -1
- data/lib/fixturizer.rb +1 -0
- data/samples/Gemfile +1 -1
- data/samples/Rakefile +7 -0
- data/samples/spec/app_spec.rb +45 -11
- data/samples/spec/fixtures/data.json +10 -0
- data/samples/spec/fixtures/data.yml +6 -0
- data/samples/spec/spec_helper.rb +6 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b32aa16a54c913b66e8d68df00c968faea177694473669e1041e5f120158641
|
4
|
+
data.tar.gz: 7896981fd9376c0929896894f306bd47653058aecaffb9f293df3143f9ebe3e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f9ea54665b8be2fe7c2db16b0805d683d348f144d6cd7367dbecf04b562c78a6429b394c2511913882b6a926f267829f2efda6442364548fb38d629415b76f
|
7
|
+
data.tar.gz: 1a4714aa619eeef6ff7142a848b5d8d04d452a577353827d34ea463d0bebc4e77592256ce631139bdd2b9ab086eecc00ab388269ffefb7585c01fa2c0b12373e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/dependencies.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Getters
|
5
|
+
class Template
|
6
|
+
attr_reader :filename, :data
|
7
|
+
|
8
|
+
def initialize(filename:, options: nil)
|
9
|
+
@filename = filename
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def retrieve
|
14
|
+
raise "Abstract template, don't use"
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_file(file)
|
18
|
+
return File.readlines(file).join
|
19
|
+
rescue Errno::EACCES
|
20
|
+
puts "Error: Permission denied to read the file #{file}."
|
21
|
+
rescue StandardError => e
|
22
|
+
puts "Error: #{e.message}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Dir["#{File.dirname(__FILE__)}/*.rb"].each { |file| require file unless File.basename(file) == 'init.rb' }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Getters
|
5
|
+
class Json < Template
|
6
|
+
def retrieve
|
7
|
+
result = nil
|
8
|
+
data = read_file(@filename)
|
9
|
+
result = JSON.parse(data, symbolize_names: @options[:symbolize])
|
10
|
+
return result
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Getters
|
5
|
+
class Yaml < Template
|
6
|
+
def retrieve
|
7
|
+
result = nil
|
8
|
+
data = read_file(@filename)
|
9
|
+
result = YAML.load(data, symbolize_names: @options[:symbolize])
|
10
|
+
return result
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -5,12 +5,13 @@ namespace :fixturizer do
|
|
5
5
|
desc 'Drop database'
|
6
6
|
task :drop do
|
7
7
|
Fixturizer::Services.get.engine(name: :models).drop_database
|
8
|
-
|
8
|
+
puts "Database successfully dropped" if Fixturizer::Services.settings.verbose
|
9
9
|
end
|
10
10
|
|
11
11
|
desc 'Populate database'
|
12
12
|
task :populate do
|
13
13
|
Fixturizer::Services.get.engine(name: :models).populate
|
14
|
+
puts "Database successfully populated" if Fixturizer::Services.settings.verbose
|
14
15
|
end
|
15
16
|
|
16
17
|
desc 'Check database connection'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Rspec
|
5
|
+
module Helpers
|
6
|
+
class Getter
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def from(format:, symbolize: true, file: )
|
10
|
+
options = {symbolize: symbolize}
|
11
|
+
Fixturizer::Services.get.getter(name: format,
|
12
|
+
parameters: {
|
13
|
+
filename: file, options: options
|
14
|
+
}).retrieve
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_content
|
22
|
+
Fixturizer::Rspec::Helpers::Getter.instance
|
23
|
+
end
|
24
|
+
|
data/lib/fixturizer/services.rb
CHANGED
@@ -35,6 +35,10 @@ module Fixturizer
|
|
35
35
|
service(type: :engines, name:, parameters:)
|
36
36
|
end
|
37
37
|
|
38
|
+
def getter(name:, parameters: nil)
|
39
|
+
service(type: :getters, name:, parameters:)
|
40
|
+
end
|
41
|
+
|
38
42
|
def serializer(name:, parameters: nil)
|
39
43
|
service(type: :serializers, name:, parameters:)
|
40
44
|
end
|
data/lib/fixturizer/settings.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
module Fixturizer
|
4
4
|
class Settings
|
5
|
-
attr_accessor :configuration_filename, :log_target
|
5
|
+
attr_accessor :configuration_filename, :log_target, :verbose
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@configuration_filename = './config/rules.yml'
|
9
9
|
@log_target = '/tmp/fixturizer.log'
|
10
|
+
@verbose = false
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/fixturizer.rb
CHANGED
data/samples/Gemfile
CHANGED
data/samples/Rakefile
CHANGED
@@ -19,3 +19,10 @@ task :routes do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
require 'fixturizer/rake/manage'
|
22
|
+
|
23
|
+
|
24
|
+
Fixturizer::Services.configure do |settings|
|
25
|
+
settings.configuration_filename = './config/rules.yml'
|
26
|
+
settings.log_target = '/tmp/fixturizer.log'
|
27
|
+
settings.verbose = (ENV['VERBOSE'])? true : false
|
28
|
+
end
|
data/samples/spec/app_spec.rb
CHANGED
@@ -81,17 +81,17 @@ RSpec.describe 'Test Fixturizer' do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
context 'Database : drop and populate' do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
84
|
+
# context 'Database : drop and populate' do
|
85
|
+
# it 'must be possible to drop database with helper ' do
|
86
|
+
# expect(database.drop).to be true
|
87
|
+
# end
|
88
|
+
# it 'must be possible to populate database with helper ' do
|
89
|
+
# expect(database.populate).to be true
|
90
|
+
# end
|
91
|
+
|
92
|
+
# it { expect(database).to be_correctly_dropped }
|
93
|
+
# it { expect(database).to be_correctly_populated }
|
94
|
+
# end
|
95
95
|
|
96
96
|
context 'Serializers : test ' do
|
97
97
|
it 'must be possible to serialize data to JSON' do
|
@@ -131,4 +131,38 @@ RSpec.describe 'Test Fixturizer' do
|
|
131
131
|
File.unlink(filename)
|
132
132
|
end
|
133
133
|
end
|
134
|
+
|
135
|
+
|
136
|
+
context 'Getters : test ' do
|
137
|
+
it 'must be possible to get content data from YAML file' do
|
138
|
+
filename = './spec/fixtures/data.yml'
|
139
|
+
result = get_content.from file: filename, format: :yaml
|
140
|
+
expect(result[:body]).to eq "test Body"
|
141
|
+
expect(result[:list].size).to eq 3
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'must be possible to get content data from YAML file without symbols keys' do
|
145
|
+
filename = './spec/fixtures/data.yml'
|
146
|
+
result = get_content.from file: filename, format: :yaml, symbolize: false
|
147
|
+
expect(result["body"]).to eq "test Body"
|
148
|
+
expect(result["list"].size).to eq 3
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'must be possible to get content data from JSON file' do
|
152
|
+
filename = './spec/fixtures/data.json'
|
153
|
+
result = get_content.from file: filename, format: :json
|
154
|
+
expect(result[:body]).to eq "test Body"
|
155
|
+
expect(result[:list].size).to eq 3
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'must be possible to get content data from JSON file without symbols keys' do
|
159
|
+
filename = './spec/fixtures/data.json'
|
160
|
+
result = get_content.from file: filename, format: :json, symbolize: false
|
161
|
+
expect(result["body"]).to eq "test Body"
|
162
|
+
expect(result["list"].size).to eq 3
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
134
168
|
end
|
data/samples/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'fixturizer/rspec/prepare'
|
5
|
+
|
6
|
+
Fixturizer::Services.configure do |settings|
|
7
|
+
settings.configuration_filename = './config/rules.yml'
|
8
|
+
settings.log_target = '/tmp/fixturizer.log'
|
9
|
+
end
|
10
|
+
|
5
11
|
require_relative '../app'
|
6
12
|
|
7
13
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixturizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre ALPHONSE
|
@@ -210,10 +210,14 @@ files:
|
|
210
210
|
- lib/fixturizer/engines/init.rb
|
211
211
|
- lib/fixturizer/engines/models.rb
|
212
212
|
- lib/fixturizer/engines/records.rb
|
213
|
+
- lib/fixturizer/getters/init.rb
|
214
|
+
- lib/fixturizer/getters/json.rb
|
215
|
+
- lib/fixturizer/getters/yaml.rb
|
213
216
|
- lib/fixturizer/rake/manage.rb
|
214
217
|
- lib/fixturizer/rake/rules/database.rake
|
215
218
|
- lib/fixturizer/rspec/helpers/database.rb
|
216
219
|
- lib/fixturizer/rspec/helpers/datasets.rb
|
220
|
+
- lib/fixturizer/rspec/helpers/getter.rb
|
217
221
|
- lib/fixturizer/rspec/helpers/records.rb
|
218
222
|
- lib/fixturizer/rspec/helpers/serializer.rb
|
219
223
|
- lib/fixturizer/rspec/matchers/database_be_correctly_dropped.rb
|
@@ -232,6 +236,8 @@ files:
|
|
232
236
|
- samples/config.ru
|
233
237
|
- samples/config/rules.yml
|
234
238
|
- samples/spec/app_spec.rb
|
239
|
+
- samples/spec/fixtures/data.json
|
240
|
+
- samples/spec/fixtures/data.yml
|
235
241
|
- samples/spec/spec_helper.rb
|
236
242
|
homepage: https://github.com/Ultragreen/fixturizer
|
237
243
|
licenses:
|