specfactor 0.1.7 → 0.1.8.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/.DS_Store +0 -0
- data/Gemfile.lock +3 -1
- data/README.md +45 -0
- data/lib/specfac.rb +82 -18
- data/lib/{e2e_module.rb → specfac/modules/e2e_module.rb} +1 -1
- data/lib/{factory_module.rb → specfac/modules/factory_module.rb} +1 -1
- data/lib/{spec_module.rb → specfac/modules/spec_module.rb} +1 -1
- data/lib/{support_module.rb → specfac/modules/support_module.rb} +0 -0
- data/lib/{specfac_utils.rb → specfac/modules/utils.rb} +0 -0
- data/lib/specfac/options.json +1 -0
- data/lib/specfac/version.rb +1 -1
- data/specfac.gemspec +1 -0
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd878e0e62b69569097cfc2349b148e77efdc9bd6214061d307fad49541025ee
|
4
|
+
data.tar.gz: 5cd2423a4813d49a9821fc74d13471efe8beebb1ed628e8517ac010b466b6df7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638c566c0df5dd98a09d5471b0b31bf209bd87bb297ffd741636e43617124e09ebbe843335aae2b97618bcd862e7164d2a007591ba0154412d618d928a61e482
|
7
|
+
data.tar.gz: 4de1048cac6bdecb3f04db1b2e586c84b3685ad83136a9403d6b1d8c1aed08f1756717443667ade8423c1d8b83f86e4824b442856762b188979844b323deafb9
|
data/.DS_Store
ADDED
Binary file
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
specfactor (0.1.
|
4
|
+
specfactor (0.1.8.1)
|
5
5
|
activesupport (~> 5.2.0)
|
6
6
|
thor (~> 0.20)
|
7
7
|
|
@@ -13,6 +13,7 @@ GEM
|
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
15
15
|
tzinfo (~> 1.1)
|
16
|
+
byebug (10.0.2)
|
16
17
|
concurrent-ruby (1.0.5)
|
17
18
|
diff-lcs (1.3)
|
18
19
|
i18n (1.1.0)
|
@@ -42,6 +43,7 @@ PLATFORMS
|
|
42
43
|
|
43
44
|
DEPENDENCIES
|
44
45
|
bundler (~> 1.16)
|
46
|
+
byebug
|
45
47
|
rake (~> 10.0)
|
46
48
|
rspec (~> 3.0)
|
47
49
|
specfactor!
|
data/README.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
Specfactor is a gem that generates commonly used tests for commonly used controller actions.
|
4
4
|
|
5
|
+
<p style="margin: 0 auto">
|
6
|
+
<img src="https://img.shields.io/badge/version-0.1.8-green.svg">
|
7
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg">
|
8
|
+
<img src="https://img.shields.io/badge/downloads-1000+-red.svg">
|
9
|
+
<img src="https://img.shields.io/badge/development-PRs Welcome-green.svg">
|
10
|
+
</p>
|
11
|
+
|
5
12
|
## Installation
|
6
13
|
|
7
14
|
Specfactor is dependent on these gems:
|
@@ -63,6 +70,44 @@ Or generate both E2E tests and the Factory:
|
|
63
70
|
|
64
71
|
Currently, tests can be generated for :index, :show, :new, :create, :edit, :update, and :destroy.
|
65
72
|
|
73
|
+
## Customizing Generated Tests
|
74
|
+
|
75
|
+
Specfactor allows for customization of modules used to generate tests. First, type:
|
76
|
+
|
77
|
+
specfac extract <path to copy modules to>
|
78
|
+
|
79
|
+
Please indicate a path such as __Users/YOUR NAME/Desktop__.
|
80
|
+
Do not include a beginning or ending "/". If you run into issues where Specfactor stops executing, it may be due to an invalid path supplied in the __extract__ command.
|
81
|
+
If this is the case, you can access the path variable directly by going to your Ruby directory and
|
82
|
+
modifying the options.json file.
|
83
|
+
|
84
|
+
My directory is at __.rvm/gems/ruby-2.4.4/gems/specfactor/lib/specfac/options.json__
|
85
|
+
|
86
|
+
Here is an example:
|
87
|
+
|
88
|
+
specfac extract Users/viktharien/Desktop
|
89
|
+
|
90
|
+
This will create a <code>modules</code> folder on my desktop. Inside the folder will be five ruby files:
|
91
|
+
|
92
|
+
spec_module.rb
|
93
|
+
factory_module.rb
|
94
|
+
support_module.rb
|
95
|
+
e2e_module.rb
|
96
|
+
utils.rb
|
97
|
+
|
98
|
+
<code>spec_module</code> contains the templates for controller tests.
|
99
|
+
|
100
|
+
<code>factory_module</code> contains the templates for FactoryBot factories.
|
101
|
+
|
102
|
+
<code>support_module</code> contains the templates for DatabaseCleaner and FactoryBot configuration.
|
103
|
+
|
104
|
+
<code>e2e_module</code> contains the templates for Capybara tests.
|
105
|
+
|
106
|
+
<code>utils</code> contains utility code used by the templates, so don't modify or else things will break.
|
107
|
+
|
108
|
+
Replace or modify the code in these files and the next time you use Specfactor to generate tests,
|
109
|
+
your modifications will be used.
|
110
|
+
|
66
111
|
## Other Commands
|
67
112
|
|
68
113
|
To generate configuration settings for DatabaseCleaner and FactoryBot:
|
data/lib/specfac.rb
CHANGED
@@ -1,19 +1,56 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'json'
|
2
|
+
require 'fileutils'
|
3
3
|
require 'thor'
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require 'thor/group'
|
5
|
+
gem_path = 'specfac'
|
6
|
+
mod_path = 'modules'
|
7
|
+
lib_path = "/lib/#{gem_path}"
|
8
|
+
abs_dir_path = File.join(File.dirname(File.dirname(File.absolute_path(__FILE__))))
|
9
|
+
path_join = lambda { |dir_path, file_path| dir_path + file_path }
|
10
|
+
options_path = path_join.call(abs_dir_path,"#{lib_path}/options.json")
|
11
|
+
options = JSON.parse(File.read(options_path))
|
12
|
+
selector = options['path']
|
13
|
+
|
14
|
+
|
15
|
+
actual_path = if selector == 'root'
|
16
|
+
gem_path
|
17
|
+
else
|
18
|
+
selector = selector[0] == "/" ? selector : "/#{selector}"
|
19
|
+
$LOAD_PATH.unshift(selector)
|
20
|
+
|
21
|
+
if !Dir.exists?("#{selector}/#{mod_path}")
|
22
|
+
Dir.mkdir("#{selector}/#{mod_path}")
|
23
|
+
FileUtils.cp_r(path_join.call(abs_dir_path,"#{lib_path}/#{mod_path}/"), selector)
|
24
|
+
end
|
25
|
+
selector
|
26
|
+
end
|
27
|
+
|
28
|
+
#### After directory preparation, require modules ####
|
29
|
+
|
30
|
+
require "#{gem_path}"
|
31
|
+
require "#{gem_path}/version"
|
32
|
+
require "#{actual_path}/#{mod_path}/spec_module"
|
33
|
+
require "#{actual_path}/#{mod_path}/factory_module"
|
34
|
+
require "#{actual_path}/#{mod_path}/support_module"
|
35
|
+
require "#{actual_path}/#{mod_path}/e2e_module"
|
36
|
+
|
8
37
|
module Specfac
|
9
38
|
class CLI < Thor
|
39
|
+
include Thor::Actions
|
10
40
|
include Utils
|
11
41
|
include SpecModule
|
12
42
|
include FactoryModule
|
13
43
|
include SupportModule
|
14
44
|
include E2eModule
|
15
45
|
|
16
|
-
attr_accessor :dir_support,
|
46
|
+
attr_accessor :dir_support,
|
47
|
+
:dir_controllers,
|
48
|
+
:dir_factories,
|
49
|
+
:dir_features,
|
50
|
+
:working_dirs,
|
51
|
+
:working_file,
|
52
|
+
:available_methods,
|
53
|
+
:paths
|
17
54
|
|
18
55
|
######### AVAILABLE COMMANDS
|
19
56
|
|
@@ -25,6 +62,21 @@ module Specfac
|
|
25
62
|
# puts args
|
26
63
|
# end
|
27
64
|
|
65
|
+
# -----
|
66
|
+
#
|
67
|
+
#
|
68
|
+
|
69
|
+
|
70
|
+
desc "extract [destination]", "Extracts the Specfactor base modules to the destination specified for customization"
|
71
|
+
method_option :aliases => "ex"
|
72
|
+
def extract(dest)
|
73
|
+
@paths = $paths
|
74
|
+
@paths[:options]["path"] = dest
|
75
|
+
puts "Setting extract destination..."
|
76
|
+
create_file(@paths[:options_path])
|
77
|
+
opener(nil, @paths[:options].to_json, "w", @paths[:options_path])
|
78
|
+
end
|
79
|
+
|
28
80
|
# -----
|
29
81
|
|
30
82
|
desc "generate [controller] [actions]", "Generates tests for specified actions. Separate actions with spaces."
|
@@ -59,16 +111,15 @@ module Specfac
|
|
59
111
|
def setup(*args)
|
60
112
|
init_vars
|
61
113
|
@working_file = "#{@dir_support}/specfac/config.rb"
|
114
|
+
create_file(@working_file)
|
62
115
|
args != nil ? args.each {|arg| opener("support", SupportModule.public_send(arg.to_sym), "a")} : nil
|
63
|
-
puts "Generating support: #{@working_file}"
|
64
|
-
sleep 1
|
65
|
-
puts "> completed"
|
66
116
|
end
|
67
117
|
|
68
118
|
######## UTILITY METHODS
|
69
119
|
#
|
70
120
|
|
71
121
|
no_commands do
|
122
|
+
|
72
123
|
def init_vars(options=nil)
|
73
124
|
@working_dirs = ["spec", "controllers", "factories", "support", "features"]
|
74
125
|
@dir_support = "#{@working_dirs[0]}/#{@working_dirs[3]}"
|
@@ -102,7 +153,7 @@ module Specfac
|
|
102
153
|
|
103
154
|
@working_file = "#{@dir_controllers}/#{controller.downcase}_controller_spec.rb"
|
104
155
|
# Spec tests
|
105
|
-
|
156
|
+
create_file(@working_file)
|
106
157
|
opener(
|
107
158
|
"spec",
|
108
159
|
["require 'rails_helper'","RSpec.describe #{controller.capitalize}Controller, type: :controller do"],
|
@@ -117,8 +168,9 @@ module Specfac
|
|
117
168
|
|
118
169
|
if options
|
119
170
|
if options[:f]
|
120
|
-
|
171
|
+
|
121
172
|
@working_file = "#{@dir_factories}/#{Utils.pluralize(controller.downcase)}.rb"
|
173
|
+
create_file(@working_file)
|
122
174
|
opener("factory", FactoryModule.create, "w")
|
123
175
|
opener("end", nil, "a")
|
124
176
|
end
|
@@ -126,8 +178,8 @@ module Specfac
|
|
126
178
|
# end to end tests
|
127
179
|
|
128
180
|
if options[:e]
|
129
|
-
puts
|
130
181
|
@working_file = "#{@dir_features}/#{Utils.pluralize(controller.downcase)}_spec.rb"
|
182
|
+
create_file(@working_file)
|
131
183
|
opener("feature",
|
132
184
|
["require 'rails_helper'", "describe 'navigation' do"],
|
133
185
|
"w")
|
@@ -139,22 +191,19 @@ module Specfac
|
|
139
191
|
|
140
192
|
end
|
141
193
|
|
142
|
-
def opener(mode, lines, open_type)
|
194
|
+
def opener(mode, lines, open_type, file = @working_file)
|
143
195
|
filer = lambda do |type, output|
|
144
|
-
File.open(
|
196
|
+
File.open(file, type) { |handle| handle.puts output}
|
145
197
|
end
|
146
198
|
|
147
199
|
if mode == "spec" || mode == "feature"
|
148
|
-
puts "Creating #{mode}: #{@working_file}."
|
149
200
|
filer.call(open_type, nil)
|
150
201
|
lines.each do |item|
|
151
202
|
filer.call("a", item)
|
152
203
|
end
|
153
204
|
elsif mode == "end"
|
154
|
-
puts "> completed"
|
155
205
|
filer.call(open_type, lines)
|
156
206
|
else
|
157
|
-
puts "Creating #{mode}: #{@working_file}"
|
158
207
|
filer.call(open_type, lines)
|
159
208
|
end
|
160
209
|
end
|
@@ -181,3 +230,18 @@ module Specfac
|
|
181
230
|
|
182
231
|
end
|
183
232
|
end
|
233
|
+
|
234
|
+
$paths = {
|
235
|
+
:gem_path => gem_path,
|
236
|
+
:lib_path => lib_path,
|
237
|
+
:mod_path => mod_path,
|
238
|
+
:abs_path => abs_dir_path,
|
239
|
+
:options_path => options_path,
|
240
|
+
:options => options,
|
241
|
+
:path_join => path_join,
|
242
|
+
:selector => selector
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"path":"root"}
|
data/lib/specfac/version.rb
CHANGED
data/specfac.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specfactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- viktharien
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- viktharien@zoho.com
|
@@ -88,6 +102,7 @@ executables:
|
|
88
102
|
extensions: []
|
89
103
|
extra_rdoc_files: []
|
90
104
|
files:
|
105
|
+
- ".DS_Store"
|
91
106
|
- ".gitignore"
|
92
107
|
- ".rspec"
|
93
108
|
- ".travis.yml"
|
@@ -99,13 +114,14 @@ files:
|
|
99
114
|
- bin/console
|
100
115
|
- bin/setup
|
101
116
|
- exe/specfac
|
102
|
-
- lib/e2e_module.rb
|
103
|
-
- lib/factory_module.rb
|
104
|
-
- lib/spec_module.rb
|
105
117
|
- lib/specfac.rb
|
118
|
+
- lib/specfac/modules/e2e_module.rb
|
119
|
+
- lib/specfac/modules/factory_module.rb
|
120
|
+
- lib/specfac/modules/spec_module.rb
|
121
|
+
- lib/specfac/modules/support_module.rb
|
122
|
+
- lib/specfac/modules/utils.rb
|
123
|
+
- lib/specfac/options.json
|
106
124
|
- lib/specfac/version.rb
|
107
|
-
- lib/specfac_utils.rb
|
108
|
-
- lib/support_module.rb
|
109
125
|
- pull_me.txt
|
110
126
|
- specfac.gemspec
|
111
127
|
homepage: https://github.com/viktharien/specfacthor
|