fixturizer 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: aac283c9566f5b74f5c0c8b1d174e01904f536778f6988f6dbf8d64cbe7d3534
4
- data.tar.gz: cb55911646494e39c98df07349f105453d63ea79509f030686f1b3177b5ef733
3
+ metadata.gz: 2b32aa16a54c913b66e8d68df00c968faea177694473669e1041e5f120158641
4
+ data.tar.gz: 7896981fd9376c0929896894f306bd47653058aecaffb9f293df3143f9ebe3e0
5
5
  SHA512:
6
- metadata.gz: b4a3ab904e5f5136c69550b27919c2fc78297f95b82159721837bbf7bf771459c09f901e6de0acd44427f86b2cf3a41b85cb6fba4b36729b5c363192647a5cc5
7
- data.tar.gz: f2ca679fc8c541f66c8523ca1964e0d5b624310ac197e0c719c828219379d925bca3c315614f0616edb2548915700ad815479f9e06a4983ea6c8dc0733c23343
6
+ metadata.gz: 11f9ea54665b8be2fe7c2db16b0805d683d348f144d6cd7367dbecf04b562c78a6429b394c2511913882b6a926f267829f2efda6442364548fb38d629415b76f
7
+ data.tar.gz: 1a4714aa619eeef6ff7142a848b5d8d04d452a577353827d34ea463d0bebc4e77592256ce631139bdd2b9ab086eecc00ab388269ffefb7585c01fa2c0b12373e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/lib/dependencies.rb CHANGED
@@ -7,3 +7,4 @@ require 'logger'
7
7
  require 'mongoid'
8
8
  require 'fixturizer/version'
9
9
  require 'yaml'
10
+ require 'json'
@@ -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
- # Fixturizer::Engines::Models::new(filename: './config/rules.yml').drop_database
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
+
@@ -12,7 +12,7 @@ module Fixturizer
12
12
  options[:to_file] = to_file
13
13
  Fixturizer::Services.get.serializer(name: format,
14
14
  parameters: {
15
- data:, options:
15
+ data: data, options: options
16
16
  }).apply
17
17
  end
18
18
  end
@@ -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
@@ -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
@@ -6,4 +6,5 @@ require_relative 'fixturizer/configuration'
6
6
  require_relative 'fixturizer/adapters/init'
7
7
  require_relative 'fixturizer/engines/init'
8
8
  require_relative 'fixturizer/serializers/init'
9
+ require_relative 'fixturizer/getters/init'
9
10
  require_relative 'fixturizer/services'
data/samples/Gemfile CHANGED
@@ -7,7 +7,7 @@ gem 'rackup', '~> 2.1'
7
7
  gem 'sinatra', '~> 4.0.0'
8
8
 
9
9
  group :test, :development do
10
- gem 'fixturizer', '~> 0.1.0'
10
+ gem 'fixturizer', '~> 0.4.0'
11
11
  gem 'rack-rest-rspec', '~> 0.0.3'
12
12
  gem 'rack-test', '~> 2.0.2'
13
13
  gem 'rake', '~> 13.0'
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
@@ -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
- 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
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
@@ -0,0 +1,10 @@
1
+ {
2
+ "body": "test Body",
3
+ "list": [
4
+ "one",
5
+ 2,
6
+ {
7
+ "three": 3
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,6 @@
1
+ ---
2
+ body: test Body
3
+ list:
4
+ - "one"
5
+ - 2
6
+ - {three: 3}
@@ -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.0
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: