to_factory 0.1.0 → 0.1.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.
- data/.travis.yml +1 -4
- data/README.md +27 -6
- data/Rakefile +12 -2
- data/lib/to_factory/generation/attribute.rb +22 -16
- data/lib/to_factory/generation/factory.rb +0 -1
- data/lib/to_factory/parsing/klass_inference.rb +34 -0
- data/lib/to_factory/parsing/new_syntax.rb +10 -0
- data/lib/to_factory/parsing/old_syntax.rb +4 -0
- data/lib/to_factory/parsing/syntax.rb +8 -23
- data/lib/to_factory/version.rb +1 -1
- data/lib/to_factory.rb +5 -0
- data/spec/db/migrate/5_add_serialized_attributes_to_users.rb +9 -0
- data/spec/example_factories/new_syntax/admin.rb +1 -0
- data/spec/example_factories/new_syntax/admin_with_header.rb +1 -0
- data/spec/example_factories/new_syntax/user.rb +1 -0
- data/spec/example_factories/new_syntax/user_admin.rb +2 -0
- data/spec/example_factories/new_syntax/user_admin_super_admin.rb +13 -0
- data/spec/example_factories/new_syntax/user_admin_with_header.rb +2 -0
- data/spec/example_factories/new_syntax/user_with_header.rb +1 -0
- data/spec/example_factories/old_syntax/admin.rb +1 -0
- data/spec/example_factories/old_syntax/user.rb +1 -0
- data/spec/example_factories/old_syntax/user_admin.rb +2 -0
- data/spec/example_factories/old_syntax/user_admin_super_admin.rb +11 -0
- data/spec/example_factories/old_syntax/user_admin_with_header.rb +2 -0
- data/spec/example_factories/old_syntax/user_with_header.rb +1 -0
- data/spec/integration/config_spec.rb +1 -1
- data/spec/integration/{generate_class_method_spec.rb → to_factory_method_spec.rb} +8 -0
- data/spec/spec_helper.rb +1 -25
- data/spec/support/data_creation.rb +36 -0
- data/spec/support/models/user.rb +1 -0
- data/spec/unit/generation/attribute_spec.rb +27 -0
- data/spec/unit/parsing/file_spec.rb +10 -0
- data/spec/unit/parsing/klass_inference_spec.rb +29 -0
- data/to_factory.gemspec +1 -1
- metadata +20 -9
- data/spec/support/terse_expect_syntax.rb +0 -23
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -11,12 +11,13 @@ ToFactory
|
|
11
11
|
|
12
12
|
Easily add factories with valid data for an existing project.
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
* auto-generate all factories
|
15
|
+
* adhoc generate from existing records
|
16
|
+
* unintrusively update factory files in place
|
17
|
+
* Parses and writes both new `FactoryGirl`, syntax or older `Factory.define` syntax
|
16
18
|
|
17
|
-
Tested against Ruby 1.8.7, 1.9.
|
19
|
+
Tested against Ruby 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.0
|
18
20
|
|
19
|
-
Reads and writes both new `FactoryGirl`, syntax or older `Factory.define` syntax
|
20
21
|
|
21
22
|
#Installation
|
22
23
|
___________
|
@@ -30,12 +31,24 @@ group :test, :development do
|
|
30
31
|
end
|
31
32
|
```
|
32
33
|
|
33
|
-
|
34
|
+
|
35
|
+
#Warning
|
36
|
+
`ToFactory` writes into the `spec/factories` folder. Whilst it
|
37
|
+
is tested and avoids overwriting existing factories,
|
38
|
+
it is recommended that you execute after committing or when in a known
|
39
|
+
safe state.
|
40
|
+
|
41
|
+
#Example
|
42
|
+
```bash
|
43
|
+
git add spec/factories
|
44
|
+
git commit -m "I know what I am doing"
|
45
|
+
rails c
|
46
|
+
>ToFactory()
|
47
|
+
```
|
34
48
|
|
35
49
|
```ruby
|
36
50
|
#Generate all factories
|
37
51
|
ToFactory()
|
38
|
-
|
39
52
|
#outputs the first record of each ActiveRecord::Base subclass in the models folder
|
40
53
|
#to spec/factories
|
41
54
|
|
@@ -50,6 +63,11 @@ ToFactory(exclude: [User, Project])
|
|
50
63
|
#Use Adhoc instances from the console
|
51
64
|
ToFactory User.last
|
52
65
|
|
66
|
+
#List defined factory names
|
67
|
+
ToFactory.definitions
|
68
|
+
#=> [:user, :admin, :project]
|
69
|
+
|
70
|
+
|
53
71
|
#writes to spec/factories/user.rb
|
54
72
|
FactoryGirl.define
|
55
73
|
factory(:user) do |u|
|
@@ -69,6 +87,9 @@ ToFactory :admin => User.last
|
|
69
87
|
|
70
88
|
```
|
71
89
|
|
90
|
+
#Known bugs/limitations
|
91
|
+
* Factory generation does not follow a hierarchical order, so factory files may require manual editing for now.
|
92
|
+
|
72
93
|
#Other useful projects
|
73
94
|
|
74
95
|
If you are adding specs to an existing project you may want to look at:
|
data/Rakefile
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
3
|
namespace :spec do
|
4
|
-
|
5
|
-
task :migrate_db do
|
4
|
+
def setup_db
|
6
5
|
require 'logger'
|
7
6
|
require 'active_record'
|
8
7
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "spec/db/test.sqlite3")
|
9
8
|
ActiveRecord::Base.logger = Logger.new(File.open('tmp/database.log', 'a'))
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
|
12
|
+
task :migrate_db do
|
13
|
+
setup_db
|
10
14
|
ActiveRecord::Migrator.migrate('spec/db/migrate')
|
11
15
|
end
|
16
|
+
|
17
|
+
desc "Migrate down"
|
18
|
+
task :migrate_down do
|
19
|
+
setup_db
|
20
|
+
ActiveRecord::Migrator.down('spec/db/migrate')
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
begin
|
@@ -7,39 +7,45 @@ module ToFactory
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_s
|
10
|
-
|
10
|
+
setter = "#{@attribute}#{inspect_value(@value)}"
|
11
11
|
|
12
12
|
if ToFactory.new_syntax?
|
13
|
-
" #{
|
13
|
+
" #{setter}"
|
14
14
|
else
|
15
|
-
" o.#{
|
15
|
+
" o.#{setter}"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def ==(other)
|
24
|
-
to_s == other.to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def inspect_value(value)
|
30
|
-
case value
|
19
|
+
def inspect_value(value, nested=false)
|
20
|
+
formatted = case value
|
31
21
|
when Time, DateTime
|
32
22
|
time = in_utc(value).strftime("%Y-%m-%dT%H:%M%Z").inspect
|
33
23
|
time.gsub(/UTC"$/, "Z\"").gsub(/GMT"$/, "Z\"")
|
34
24
|
when BigDecimal
|
35
25
|
value.to_f.inspect
|
36
26
|
when Hash
|
37
|
-
|
27
|
+
formatted = value.keys.inject([]) do |a, key|
|
28
|
+
formatted_key = inspect_value(key, true)
|
29
|
+
formatted_value = inspect_value(value.fetch(key), true)
|
30
|
+
a << "#{formatted_key} => #{formatted_value}"
|
31
|
+
end.join(', ')
|
32
|
+
|
33
|
+
if nested
|
34
|
+
"{#{formatted}}"
|
35
|
+
else
|
36
|
+
"({#{formatted}})"
|
37
|
+
end
|
38
38
|
when Array
|
39
39
|
value.map{|v| inspect_value(v)}
|
40
40
|
else
|
41
41
|
value.inspect
|
42
42
|
end
|
43
|
+
|
44
|
+
if !value.is_a?(Hash) && !nested
|
45
|
+
formatted = " #{formatted}"
|
46
|
+
end
|
47
|
+
|
48
|
+
formatted
|
43
49
|
end
|
44
50
|
|
45
51
|
def in_utc(time)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ToFactory
|
2
|
+
module Parsing
|
3
|
+
CannotInferClass = Class.new ArgumentError
|
4
|
+
|
5
|
+
class KlassInference
|
6
|
+
def initialize
|
7
|
+
@mapping = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup(factory_names_and_parents)
|
11
|
+
factory_names_and_parents.each do |factory_name, parent|
|
12
|
+
@mapping[factory_name.to_s] = to_const(parent || factory_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def infer(factory_name)
|
17
|
+
result = @mapping[factory_name.to_s]
|
18
|
+
return result if result.is_a? Class
|
19
|
+
|
20
|
+
raise CannotInferClass.new(factory_name) if result.nil?
|
21
|
+
|
22
|
+
infer(result)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def to_const(factory_name)
|
28
|
+
factory_name.to_s.camelize.constantize
|
29
|
+
rescue NameError
|
30
|
+
factory_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -4,6 +4,16 @@ module ToFactory
|
|
4
4
|
def header?
|
5
5
|
sexp[1][1][1] == :FactoryGirl rescue false
|
6
6
|
end
|
7
|
+
|
8
|
+
def parent_from(x)
|
9
|
+
# e.g.
|
10
|
+
#s(:call, nil, :factory, s(:lit, :admin), s(:hash, s(:lit, :parent), s(:lit, :"to_factory/user")))
|
11
|
+
x[1][4][2][1]
|
12
|
+
rescue NoMethodError
|
13
|
+
# e.g.
|
14
|
+
#s(:call, nil, :factory, s(:lit, :"to_factory/user"))
|
15
|
+
x[1][3][1]
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "to_factory/parsing/klass_inference"
|
2
|
+
|
1
3
|
module ToFactory
|
2
4
|
module Parsing
|
3
5
|
class Syntax
|
@@ -14,9 +16,10 @@ module ToFactory
|
|
14
16
|
def parse
|
15
17
|
result = {}
|
16
18
|
@klass_inference = KlassInference.new
|
19
|
+
@klass_inference.setup(all_factories)
|
17
20
|
|
18
|
-
|
19
|
-
klass = @klass_inference.infer(factory_name
|
21
|
+
all_factories.each do |factory_name, parent_name, ruby|
|
22
|
+
klass = @klass_inference.infer(factory_name)
|
20
23
|
result[klass] ||= {}
|
21
24
|
result[klass][factory_name] = ruby
|
22
25
|
end
|
@@ -36,16 +39,12 @@ module ToFactory
|
|
36
39
|
header? ? sexp[3] : sexp
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
40
|
-
factories.
|
41
|
-
|
42
|
+
def all_factories
|
43
|
+
factories.map do |x|
|
44
|
+
[name_from(x), parent_from(x), to_ruby(x)]
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
45
|
-
def parent_from(x)
|
46
|
-
x[1][-1][-1][-1] rescue name_from(x)
|
47
|
-
end
|
48
|
-
|
49
48
|
def name_from(sexp)
|
50
49
|
sexp[1][3][1]
|
51
50
|
end
|
@@ -67,20 +66,6 @@ module ToFactory
|
|
67
66
|
def ruby_parser
|
68
67
|
@ruby_parseer ||= RubyParser.new
|
69
68
|
end
|
70
|
-
|
71
|
-
class KlassInference
|
72
|
-
def initialize
|
73
|
-
@mapping = {}
|
74
|
-
end
|
75
|
-
|
76
|
-
def infer(klass, parent_klass=nil)
|
77
|
-
@mapping[klass] ||= klass.to_s.camelize.constantize
|
78
|
-
rescue
|
79
|
-
infer(parent_klass)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
69
|
end
|
85
70
|
end
|
86
71
|
end
|
data/lib/to_factory/version.rb
CHANGED
data/lib/to_factory.rb
CHANGED
@@ -2,6 +2,7 @@ factory(:"to_factory/user") do
|
|
2
2
|
birthday "2014-07-08T15:30Z"
|
3
3
|
email "test@example.com"
|
4
4
|
name "Jeff"
|
5
|
+
some_attributes({:a => 1})
|
5
6
|
some_id 8
|
6
7
|
end
|
7
8
|
|
@@ -9,5 +10,6 @@ factory(:admin, :parent => :"to_factory/user") do
|
|
9
10
|
birthday "2014-07-08T15:30Z"
|
10
11
|
email "admin@example.com"
|
11
12
|
name "Admin"
|
13
|
+
some_attributes({:a => 1})
|
12
14
|
some_id 9
|
13
15
|
end
|
@@ -3,6 +3,7 @@ FactoryGirl.define do
|
|
3
3
|
birthday "2014-07-08T15:30Z"
|
4
4
|
email "test@example.com"
|
5
5
|
name "Jeff"
|
6
|
+
some_attributes({:a => 1})
|
6
7
|
some_id 8
|
7
8
|
end
|
8
9
|
|
@@ -10,6 +11,7 @@ FactoryGirl.define do
|
|
10
11
|
birthday "2014-07-08T15:30Z"
|
11
12
|
email "admin@example.com"
|
12
13
|
name "Admin"
|
14
|
+
some_attributes({:a => 1})
|
13
15
|
some_id 9
|
14
16
|
end
|
15
17
|
end
|
@@ -2,6 +2,7 @@ Factory.define(:"to_factory/user") do |o|
|
|
2
2
|
o.birthday "2014-07-08T15:30Z"
|
3
3
|
o.email "test@example.com"
|
4
4
|
o.name "Jeff"
|
5
|
+
o.some_attributes({:a => 1})
|
5
6
|
o.some_id 8
|
6
7
|
end
|
7
8
|
|
@@ -9,5 +10,6 @@ Factory.define(:admin, :parent => :"to_factory/user") do |o|
|
|
9
10
|
o.birthday "2014-07-08T15:30Z"
|
10
11
|
o.email "admin@example.com"
|
11
12
|
o.name "Admin"
|
13
|
+
o.some_attributes({:a => 1})
|
12
14
|
o.some_id 9
|
13
15
|
end
|
@@ -2,6 +2,7 @@ Factory.define(:"to_factory/user") do |o|
|
|
2
2
|
o.birthday "2014-07-08T15:30Z"
|
3
3
|
o.email "test@example.com"
|
4
4
|
o.name "Jeff"
|
5
|
+
o.some_attributes({:a => 1})
|
5
6
|
o.some_id 8
|
6
7
|
end
|
7
8
|
|
@@ -9,5 +10,6 @@ Factory.define(:admin, :parent => :"to_factory/user") do |o|
|
|
9
10
|
o.birthday "2014-07-08T15:30Z"
|
10
11
|
o.email "admin@example.com"
|
11
12
|
o.name "Admin"
|
13
|
+
o.some_attributes({:a => 1})
|
12
14
|
o.some_id 9
|
13
15
|
end
|
@@ -15,6 +15,14 @@ describe ToFactory do
|
|
15
15
|
let(:expected_user_file) { File.read "./spec/example_factories/#{version}_syntax/user_with_header.rb"}
|
16
16
|
let(:expected_project_file) { File.read "./spec/example_factories/#{version}_syntax/project_with_header.rb"}
|
17
17
|
|
18
|
+
describe "ToFactory.definitions" do
|
19
|
+
it do
|
20
|
+
ToFactory()
|
21
|
+
expect(ToFactory.definitions).to match_array ["to_factory/user", "to_factory/project"]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
18
26
|
describe "Object#ToFactory" do
|
19
27
|
it "generates all factories" do
|
20
28
|
ToFactory()
|
data/spec/spec_helper.rb
CHANGED
@@ -26,31 +26,8 @@ require "to_factory"
|
|
26
26
|
|
27
27
|
require "./spec/support/models/user"
|
28
28
|
require "./spec/support/models/project"
|
29
|
-
require "./spec/support/terse_expect_syntax"
|
30
29
|
require "./spec/support/match_sexp"
|
31
|
-
|
32
|
-
module ToFactory::DataCreation
|
33
|
-
def create_all!
|
34
|
-
create_user!
|
35
|
-
create_admin!
|
36
|
-
end
|
37
|
-
|
38
|
-
def create_project!
|
39
|
-
ToFactory::Project.create({:name => "My Project", :objective => "easy testing", :some_id => 9 })
|
40
|
-
end
|
41
|
-
|
42
|
-
def birthday
|
43
|
-
Time.find_zone("UTC").parse("2014-07-08T15:30Z")
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_user!
|
47
|
-
ToFactory::User.create :name => "Jeff", :email => "test@example.com", :some_id => 8, :birthday => birthday
|
48
|
-
end
|
49
|
-
|
50
|
-
def create_admin!
|
51
|
-
ToFactory::User.create :name => "Admin", :email => "admin@example.com", :some_id => 9, :birthday => birthday
|
52
|
-
end
|
53
|
-
end
|
30
|
+
require "./spec/support/data_creation"
|
54
31
|
|
55
32
|
module ToFactory::SpecSyntaxHelpers
|
56
33
|
def version
|
@@ -59,7 +36,6 @@ module ToFactory::SpecSyntaxHelpers
|
|
59
36
|
end
|
60
37
|
|
61
38
|
RSpec.configure do |config|
|
62
|
-
config.include TerseExpectSyntax
|
63
39
|
config.include ToFactory::DataCreation
|
64
40
|
config.include ToFactory::SpecSyntaxHelpers
|
65
41
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ToFactory::DataCreation
|
2
|
+
def create_all!
|
3
|
+
create_user!
|
4
|
+
create_admin!
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_project!
|
8
|
+
ToFactory::Project.create({:name => "My Project", :objective => "easy testing", :some_id => 9 })
|
9
|
+
end
|
10
|
+
|
11
|
+
def birthday
|
12
|
+
Time.find_zone("UTC").parse("2014-07-08T15:30Z")
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_user!
|
16
|
+
ToFactory::User.create(
|
17
|
+
:name => "Jeff",
|
18
|
+
:email => "test@example.com",
|
19
|
+
:some_attributes => {:a => 1},
|
20
|
+
:some_id => 8,
|
21
|
+
:birthday => birthday
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_admin!
|
26
|
+
ToFactory::User.create(
|
27
|
+
:name => "Admin",
|
28
|
+
:email => "admin@example.com",
|
29
|
+
:some_attributes => {:a => 1},
|
30
|
+
:some_id => 9,
|
31
|
+
:birthday => birthday
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
data/spec/support/models/user.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
describe ToFactory::Generation::Attribute do
|
2
|
+
let(:attribute) { ToFactory::Generation::Attribute.new(:some_attributes, {:a => 1}) }
|
3
|
+
|
4
|
+
describe "#to_s" do
|
5
|
+
it do
|
6
|
+
expect(attribute.to_s).to include "some_attributes({:a => 1})"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#inspect_value" do
|
11
|
+
it do
|
12
|
+
expect(attribute.inspect_value({:a => 1})).to eq "({:a => 1})"
|
13
|
+
end
|
14
|
+
|
15
|
+
it do
|
16
|
+
hash = ActiveSupport::OrderedHash.new
|
17
|
+
hash[{"with" => :hash}] = "keys"
|
18
|
+
hash[2] = "integers"
|
19
|
+
hash[:a] = {:nested => "hash"}
|
20
|
+
|
21
|
+
expected = '({{"with" => :hash} => "keys", 2 => "integers", :a => {:nested => "hash"}})'
|
22
|
+
|
23
|
+
expect(attribute.inspect_value(hash)).to eq expected
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -36,6 +36,16 @@ describe ToFactory::Parsing::File do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "#parse" do
|
39
|
+
context "with multiple levels of parent classes" do
|
40
|
+
let(:filename) { "spec/example_factories/#{version}_syntax/#{'user_admin_super_admin'}.rb"}
|
41
|
+
|
42
|
+
it do
|
43
|
+
result = parser.parse
|
44
|
+
|
45
|
+
expect(result[ToFactory::User].keys).to match_array [:super_admin, :admin, :"to_factory/user"]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
39
49
|
context "file: user" do
|
40
50
|
let(:filename) { "spec/example_factories/#{version}_syntax/#{'user'}.rb"}
|
41
51
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe ToFactory::Parsing::KlassInference do
|
2
|
+
let(:inference) { ToFactory::Parsing::KlassInference.new }
|
3
|
+
|
4
|
+
mappings = #klass, parent, result
|
5
|
+
[:admin, :"to_factory/user", ToFactory::User],
|
6
|
+
[:some_project, :"to_factory/project", ToFactory::Project],
|
7
|
+
[:sub_project, :"some_project", ToFactory::Project],
|
8
|
+
[:super_admin, :admin, ToFactory::User],
|
9
|
+
[:"to_factory/user", nil, ToFactory::User]
|
10
|
+
|
11
|
+
|
12
|
+
to_infer = mappings.map{|a| a[0..1]}
|
13
|
+
|
14
|
+
before do
|
15
|
+
inference.setup to_infer
|
16
|
+
end
|
17
|
+
|
18
|
+
mappings.each do |klass, parent, expected|
|
19
|
+
it "having #{klass} and #{parent.inspect} implies #{expected} "do
|
20
|
+
result = inference.infer(klass)
|
21
|
+
expect(result).to eq expected
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it do
|
26
|
+
|
27
|
+
expect(lambda{inference.infer("unknown")}).to raise_error
|
28
|
+
end
|
29
|
+
end
|
data/to_factory.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Mark Burns"]
|
10
10
|
spec.email = ["markthedeveloper@gmail.com"]
|
11
11
|
spec.summary = %q{Turn ActiveRecord instances into factories}
|
12
|
-
spec.description = %q{
|
12
|
+
spec.description = %q{Autogenerate and append/create factory_girl definitions from the console}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mark Burns
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2015-01-
|
18
|
+
date: 2015-01-08 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -173,7 +173,7 @@ dependencies:
|
|
173
173
|
version: "10.0"
|
174
174
|
type: :development
|
175
175
|
version_requirements: *id010
|
176
|
-
description:
|
176
|
+
description: Autogenerate and append/create factory_girl definitions from the console
|
177
177
|
email:
|
178
178
|
- markthedeveloper@gmail.com
|
179
179
|
executables: []
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- lib/to_factory/generation/attribute.rb
|
203
203
|
- lib/to_factory/generation/factory.rb
|
204
204
|
- lib/to_factory/parsing/file.rb
|
205
|
+
- lib/to_factory/parsing/klass_inference.rb
|
205
206
|
- lib/to_factory/parsing/new_syntax.rb
|
206
207
|
- lib/to_factory/parsing/old_syntax.rb
|
207
208
|
- lib/to_factory/parsing/syntax.rb
|
@@ -210,37 +211,42 @@ files:
|
|
210
211
|
- spec/db/migrate/2_create_projects.rb
|
211
212
|
- spec/db/migrate/3_create_not_namespaced.rb
|
212
213
|
- spec/db/migrate/4_add_birthday_to_users.rb
|
214
|
+
- spec/db/migrate/5_add_serialized_attributes_to_users.rb
|
213
215
|
- spec/example_factories/new_syntax/admin.rb
|
214
216
|
- spec/example_factories/new_syntax/admin_with_header.rb
|
215
217
|
- spec/example_factories/new_syntax/project_with_header.rb
|
216
218
|
- spec/example_factories/new_syntax/user.rb
|
217
219
|
- spec/example_factories/new_syntax/user_admin.rb
|
220
|
+
- spec/example_factories/new_syntax/user_admin_super_admin.rb
|
218
221
|
- spec/example_factories/new_syntax/user_admin_with_header.rb
|
219
222
|
- spec/example_factories/new_syntax/user_with_header.rb
|
220
223
|
- spec/example_factories/old_syntax/admin.rb
|
221
224
|
- spec/example_factories/old_syntax/project_with_header.rb
|
222
225
|
- spec/example_factories/old_syntax/user.rb
|
223
226
|
- spec/example_factories/old_syntax/user_admin.rb
|
227
|
+
- spec/example_factories/old_syntax/user_admin_super_admin.rb
|
224
228
|
- spec/example_factories/old_syntax/user_admin_with_header.rb
|
225
229
|
- spec/example_factories/old_syntax/user_with_header.rb
|
226
230
|
- spec/integration/config_spec.rb
|
227
231
|
- spec/integration/file_sync_spec.rb
|
228
232
|
- spec/integration/file_writer_spec.rb
|
229
|
-
- spec/integration/generate_class_method_spec.rb
|
230
233
|
- spec/integration/lint_spec.rb
|
234
|
+
- spec/integration/to_factory_method_spec.rb
|
231
235
|
- spec/spec_helper.rb
|
236
|
+
- spec/support/data_creation.rb
|
232
237
|
- spec/support/match_sexp.rb
|
233
238
|
- spec/support/models/not_active_record.rb
|
234
239
|
- spec/support/models/project.rb
|
235
240
|
- spec/support/models/user.rb
|
236
|
-
- spec/support/terse_expect_syntax.rb
|
237
241
|
- spec/unit/collation_spec.rb
|
238
242
|
- spec/unit/definition_group_spec.rb
|
239
243
|
- spec/unit/file_writer_spec.rb
|
240
244
|
- spec/unit/finders/factory_spec.rb
|
241
245
|
- spec/unit/finders/model_spec.rb
|
246
|
+
- spec/unit/generation/attribute_spec.rb
|
242
247
|
- spec/unit/generator_spec.rb
|
243
248
|
- spec/unit/parsing/file_spec.rb
|
249
|
+
- spec/unit/parsing/klass_inference_spec.rb
|
244
250
|
- tmp/.keep
|
245
251
|
- to_factory.gemspec
|
246
252
|
has_rdoc: true
|
@@ -282,34 +288,39 @@ test_files:
|
|
282
288
|
- spec/db/migrate/2_create_projects.rb
|
283
289
|
- spec/db/migrate/3_create_not_namespaced.rb
|
284
290
|
- spec/db/migrate/4_add_birthday_to_users.rb
|
291
|
+
- spec/db/migrate/5_add_serialized_attributes_to_users.rb
|
285
292
|
- spec/example_factories/new_syntax/admin.rb
|
286
293
|
- spec/example_factories/new_syntax/admin_with_header.rb
|
287
294
|
- spec/example_factories/new_syntax/project_with_header.rb
|
288
295
|
- spec/example_factories/new_syntax/user.rb
|
289
296
|
- spec/example_factories/new_syntax/user_admin.rb
|
297
|
+
- spec/example_factories/new_syntax/user_admin_super_admin.rb
|
290
298
|
- spec/example_factories/new_syntax/user_admin_with_header.rb
|
291
299
|
- spec/example_factories/new_syntax/user_with_header.rb
|
292
300
|
- spec/example_factories/old_syntax/admin.rb
|
293
301
|
- spec/example_factories/old_syntax/project_with_header.rb
|
294
302
|
- spec/example_factories/old_syntax/user.rb
|
295
303
|
- spec/example_factories/old_syntax/user_admin.rb
|
304
|
+
- spec/example_factories/old_syntax/user_admin_super_admin.rb
|
296
305
|
- spec/example_factories/old_syntax/user_admin_with_header.rb
|
297
306
|
- spec/example_factories/old_syntax/user_with_header.rb
|
298
307
|
- spec/integration/config_spec.rb
|
299
308
|
- spec/integration/file_sync_spec.rb
|
300
309
|
- spec/integration/file_writer_spec.rb
|
301
|
-
- spec/integration/generate_class_method_spec.rb
|
302
310
|
- spec/integration/lint_spec.rb
|
311
|
+
- spec/integration/to_factory_method_spec.rb
|
303
312
|
- spec/spec_helper.rb
|
313
|
+
- spec/support/data_creation.rb
|
304
314
|
- spec/support/match_sexp.rb
|
305
315
|
- spec/support/models/not_active_record.rb
|
306
316
|
- spec/support/models/project.rb
|
307
317
|
- spec/support/models/user.rb
|
308
|
-
- spec/support/terse_expect_syntax.rb
|
309
318
|
- spec/unit/collation_spec.rb
|
310
319
|
- spec/unit/definition_group_spec.rb
|
311
320
|
- spec/unit/file_writer_spec.rb
|
312
321
|
- spec/unit/finders/factory_spec.rb
|
313
322
|
- spec/unit/finders/model_spec.rb
|
323
|
+
- spec/unit/generation/attribute_spec.rb
|
314
324
|
- spec/unit/generator_spec.rb
|
315
325
|
- spec/unit/parsing/file_spec.rb
|
326
|
+
- spec/unit/parsing/klass_inference_spec.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module TerseExpectSyntax
|
2
|
-
class Returner
|
3
|
-
def initialize(to_call)
|
4
|
-
@to_call=to_call
|
5
|
-
end
|
6
|
-
def r(*args)
|
7
|
-
@to_call.call(*args)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
#x( @a, :b, "c").r d
|
12
|
-
#becomes
|
13
|
-
#expect(@a).to_receive(:b).with("c").and_return d
|
14
|
-
def x(target, expected_method, *received_args)
|
15
|
-
receiver = expect(target).to receive(expected_method)
|
16
|
-
if received_args.any?
|
17
|
-
receiver = receiver.with(*received_args)
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
Returner.new(lambda {|*return_args| receiver.and_return(*return_args) })
|
22
|
-
end
|
23
|
-
end
|