to_factory 2.1.0 → 3.0.0.pre.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +35 -0
  3. data/.rubocop-disabled.yml +95 -0
  4. data/.rubocop-enabled.yml +1194 -0
  5. data/.rubocop.yml +938 -0
  6. data/CHANGELOG.md +11 -0
  7. data/Gemfile +6 -1
  8. data/README.md +2 -11
  9. data/Rakefile +17 -9
  10. data/lib/to_factory/collation.rb +9 -9
  11. data/lib/to_factory/file_sync.rb +10 -10
  12. data/lib/to_factory/file_writer.rb +1 -1
  13. data/lib/to_factory/finders/factory.rb +1 -1
  14. data/lib/to_factory/finders/model.rb +2 -4
  15. data/lib/to_factory/generation/attribute.rb +6 -10
  16. data/lib/to_factory/generation/factory.rb +3 -3
  17. data/lib/to_factory/klass_inference.rb +4 -6
  18. data/lib/to_factory/options_parser.rb +4 -4
  19. data/lib/to_factory/parsing/file.rb +85 -14
  20. data/lib/to_factory/representation.rb +9 -6
  21. data/lib/to_factory/version.rb +1 -1
  22. data/lib/to_factory.rb +7 -8
  23. data/spec/db/migrate/1_create_users.rb +4 -4
  24. data/spec/db/migrate/2_create_projects.rb +4 -4
  25. data/spec/db/migrate/3_create_not_namespaced.rb +4 -4
  26. data/spec/db/migrate/4_add_birthday_to_users.rb +3 -3
  27. data/spec/db/migrate/5_add_serialized_attributes_to_users.rb +3 -3
  28. data/spec/example_factories/admin.rb +6 -6
  29. data/spec/example_factories/admin_with_header.rb +7 -7
  30. data/spec/example_factories/inherited_project_with_header.rb +7 -0
  31. data/spec/example_factories/project_with_header.rb +4 -4
  32. data/spec/example_factories/user.rb +5 -5
  33. data/spec/example_factories/user_admin.rb +11 -11
  34. data/spec/example_factories/user_admin_root.rb +12 -13
  35. data/spec/example_factories/user_admin_super_admin.rb +6 -6
  36. data/spec/example_factories/user_admin_with_header.rb +12 -12
  37. data/spec/example_factories/user_with_header.rb +6 -6
  38. data/spec/integration/empty_factory_file_spec.rb +2 -2
  39. data/spec/integration/file_sync_spec.rb +16 -17
  40. data/spec/integration/file_writer_spec.rb +13 -9
  41. data/spec/integration/lint_spec.rb +4 -3
  42. data/spec/integration/multiple_to_factory_calls_spec.rb +37 -35
  43. data/spec/integration/non_active_record_classes_spec.rb +40 -0
  44. data/spec/integration/to_factory_method_spec.rb +21 -18
  45. data/spec/spec_helper.rb +8 -8
  46. data/spec/support/data_creation.rb +11 -13
  47. data/spec/support/match_sexp.rb +0 -1
  48. data/spec/support/non_active_record/inherited_project.rb +3 -0
  49. data/spec/support/non_active_record/project.rb +3 -0
  50. data/spec/support/non_active_record/some_other_service_inheriting_from_something_else.rb +4 -0
  51. data/spec/support/non_active_record/some_service.rb +2 -0
  52. data/spec/support/non_active_record/something_else.rb +2 -0
  53. data/spec/support/ruby_parser_exception_causing_string.rb +29 -29
  54. data/spec/unit/collation_spec.rb +9 -10
  55. data/spec/unit/file_writer_spec.rb +4 -8
  56. data/spec/unit/finders/factory_spec.rb +7 -9
  57. data/spec/unit/finders/model_spec.rb +6 -9
  58. data/spec/unit/generation/attribute_spec.rb +11 -12
  59. data/spec/unit/generation/factory_spec.rb +14 -16
  60. data/spec/unit/parsing/file_spec.rb +9 -9
  61. data/spec/unit/parsing/klass_inference_spec.rb +5 -7
  62. data/to_factory.gemspec +14 -10
  63. metadata +89 -31
  64. data/.travis.yml +0 -16
  65. data/lib/to_factory/parsing/syntax.rb +0 -83
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0.pre.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Burns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2022-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: factory_girl
14
+ name: factory_bot
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.5'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.5'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby2ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,44 +42,44 @@ dependencies:
42
42
  name: activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.0'
48
- type: :runtime
47
+ version: '0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.6
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.6
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.5.1
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.5.1
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: byebug
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-github
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: rspec
99
141
  requirement: !ruby/object:Gem::Requirement
@@ -112,26 +154,30 @@ dependencies:
112
154
  name: rake
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
115
- - - "~>"
157
+ - - ">="
116
158
  - !ruby/object:Gem::Version
117
- version: '10.0'
159
+ version: 12.3.3
118
160
  type: :development
119
161
  prerelease: false
120
162
  version_requirements: !ruby/object:Gem::Requirement
121
163
  requirements:
122
- - - "~>"
164
+ - - ">="
123
165
  - !ruby/object:Gem::Version
124
- version: '10.0'
125
- description: Autogenerate and append/create factory_girl definitions from the console
166
+ version: 12.3.3
167
+ description: Autogenerate and append/create factory_bot definitions from the console
126
168
  email:
127
169
  - markthedeveloper@gmail.com
128
170
  executables: []
129
171
  extensions: []
130
172
  extra_rdoc_files: []
131
173
  files:
174
+ - ".github/workflows/test.yml"
132
175
  - ".gitignore"
133
176
  - ".rspec"
134
- - ".travis.yml"
177
+ - ".rubocop-disabled.yml"
178
+ - ".rubocop-enabled.yml"
179
+ - ".rubocop.yml"
180
+ - CHANGELOG.md
135
181
  - Gemfile
136
182
  - README.md
137
183
  - Rakefile
@@ -150,7 +196,6 @@ files:
150
196
  - lib/to_factory/options_parser.rb
151
197
  - lib/to_factory/parsing/file.rb
152
198
  - lib/to_factory/parsing/ruby_parsing_helpers.rb
153
- - lib/to_factory/parsing/syntax.rb
154
199
  - lib/to_factory/representation.rb
155
200
  - lib/to_factory/version.rb
156
201
  - spec/db/migrate/1_create_users.rb
@@ -160,6 +205,7 @@ files:
160
205
  - spec/db/migrate/5_add_serialized_attributes_to_users.rb
161
206
  - spec/example_factories/admin.rb
162
207
  - spec/example_factories/admin_with_header.rb
208
+ - spec/example_factories/inherited_project_with_header.rb
163
209
  - spec/example_factories/project_with_header.rb
164
210
  - spec/example_factories/user.rb
165
211
  - spec/example_factories/user_admin.rb
@@ -173,6 +219,7 @@ files:
173
219
  - spec/integration/file_writer_spec.rb
174
220
  - spec/integration/lint_spec.rb
175
221
  - spec/integration/multiple_to_factory_calls_spec.rb
222
+ - spec/integration/non_active_record_classes_spec.rb
176
223
  - spec/integration/to_factory_method_spec.rb
177
224
  - spec/spec_helper.rb
178
225
  - spec/support/broken_models/invalid_ruby_file.rb
@@ -182,6 +229,11 @@ files:
182
229
  - spec/support/models/not_active_record.rb
183
230
  - spec/support/models/project.rb
184
231
  - spec/support/models/user.rb
232
+ - spec/support/non_active_record/inherited_project.rb
233
+ - spec/support/non_active_record/project.rb
234
+ - spec/support/non_active_record/some_other_service_inheriting_from_something_else.rb
235
+ - spec/support/non_active_record/some_service.rb
236
+ - spec/support/non_active_record/something_else.rb
185
237
  - spec/support/ruby_parser_exception_causing_string.rb
186
238
  - spec/unit/collation_spec.rb
187
239
  - spec/unit/file_writer_spec.rb
@@ -208,12 +260,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
260
  version: '0'
209
261
  required_rubygems_version: !ruby/object:Gem::Requirement
210
262
  requirements:
211
- - - ">="
263
+ - - ">"
212
264
  - !ruby/object:Gem::Version
213
- version: '0'
265
+ version: 1.3.1
214
266
  requirements: []
215
- rubyforge_project:
216
- rubygems_version: 2.4.5.1
267
+ rubygems_version: 3.3.26
217
268
  signing_key:
218
269
  specification_version: 4
219
270
  summary: Turn ActiveRecord instances into factories
@@ -225,6 +276,7 @@ test_files:
225
276
  - spec/db/migrate/5_add_serialized_attributes_to_users.rb
226
277
  - spec/example_factories/admin.rb
227
278
  - spec/example_factories/admin_with_header.rb
279
+ - spec/example_factories/inherited_project_with_header.rb
228
280
  - spec/example_factories/project_with_header.rb
229
281
  - spec/example_factories/user.rb
230
282
  - spec/example_factories/user_admin.rb
@@ -238,6 +290,7 @@ test_files:
238
290
  - spec/integration/file_writer_spec.rb
239
291
  - spec/integration/lint_spec.rb
240
292
  - spec/integration/multiple_to_factory_calls_spec.rb
293
+ - spec/integration/non_active_record_classes_spec.rb
241
294
  - spec/integration/to_factory_method_spec.rb
242
295
  - spec/spec_helper.rb
243
296
  - spec/support/broken_models/invalid_ruby_file.rb
@@ -247,6 +300,11 @@ test_files:
247
300
  - spec/support/models/not_active_record.rb
248
301
  - spec/support/models/project.rb
249
302
  - spec/support/models/user.rb
303
+ - spec/support/non_active_record/inherited_project.rb
304
+ - spec/support/non_active_record/project.rb
305
+ - spec/support/non_active_record/some_other_service_inheriting_from_something_else.rb
306
+ - spec/support/non_active_record/some_service.rb
307
+ - spec/support/non_active_record/something_else.rb
250
308
  - spec/support/ruby_parser_exception_causing_string.rb
251
309
  - spec/unit/collation_spec.rb
252
310
  - spec/unit/file_writer_spec.rb
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.3
4
- - 2.1.7
5
- - 2.0.0
6
-
7
- script: "./bin/ci"
8
- cache: bundler
9
-
10
- sudo: false
11
-
12
- branches:
13
- only:
14
- - master
15
- - stable
16
-
@@ -1,83 +0,0 @@
1
- module ToFactory
2
- module Parsing
3
- ParseException = Class.new ::Exception
4
-
5
- class CouldNotInferClassException < ::Exception
6
- attr_reader :sexp
7
-
8
- def initialize(sexp)
9
- @sexp = sexp
10
- end
11
- end
12
-
13
- class Syntax
14
- include Parsing::RubyParsingHelpers
15
- attr_accessor :contents
16
-
17
- def initialize(contents)
18
- @contents = contents
19
- end
20
-
21
- def multiple_factories?
22
- factories_sexp[0] == :block
23
- end
24
-
25
- def parse
26
- factories.map do |x|
27
- representation_from(x)
28
- end
29
-
30
- rescue Racc::ParseError, StringScanner::Error => e
31
- raise ParseException.new("Original exception: #{e.message}\n #{e.backtrace.join("\n")}\nToFactory Error parsing \n#{@contents}\n o")
32
- end
33
-
34
-
35
- def representation_from(x)
36
- Representation.new(name_from(x), parent_from(x), to_ruby(x))
37
- rescue CouldNotInferClassException => e
38
- ruby = to_ruby(e.sexp)
39
- Kernel.warn "ToFactory could not parse\n#{ruby}"
40
- NullRepresentation.new(e.sexp)
41
- end
42
-
43
- def factories
44
- if multiple_factories?
45
- factories_sexp[1..-1]
46
- else
47
- [factories_sexp]
48
- end
49
- end
50
-
51
- def factories_sexp
52
- header? ? sexp[3] : sexp
53
- end
54
-
55
- def name_from(sexp)
56
- sexp[1][3][1]
57
- rescue NoMethodError
58
- raise CouldNotInferClassException.new(sexp)
59
- end
60
-
61
- def header?
62
- sexp[1][1][1] == :FactoryGirl rescue false
63
- end
64
-
65
- def parent_from(x)
66
- # e.g.
67
- #s(:call, nil, :factory, s(:lit, :admin), s(:hash, s(:lit, :parent), s(:lit, :"to_factory/user")))
68
- x[1][4][2][1]
69
- rescue NoMethodError
70
- # e.g.
71
- #s(:call, nil, :factory, s(:lit, :"to_factory/user"))
72
- x[1][3][1]
73
- end
74
-
75
- private
76
-
77
- def sexp
78
- @sexp ||= ruby_parser.process(@contents)
79
- end
80
-
81
- end
82
- end
83
- end