to_factory 2.1.0 → 3.0.0.pre.pre
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 +5 -5
- data/.github/workflows/test.yml +35 -0
- data/.rubocop-disabled.yml +95 -0
- data/.rubocop-enabled.yml +1194 -0
- data/.rubocop.yml +938 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +6 -1
- data/README.md +2 -11
- data/Rakefile +17 -9
- data/lib/to_factory/collation.rb +9 -9
- data/lib/to_factory/file_sync.rb +10 -10
- data/lib/to_factory/file_writer.rb +1 -1
- data/lib/to_factory/finders/factory.rb +1 -1
- data/lib/to_factory/finders/model.rb +2 -4
- data/lib/to_factory/generation/attribute.rb +6 -10
- data/lib/to_factory/generation/factory.rb +3 -3
- data/lib/to_factory/klass_inference.rb +4 -6
- data/lib/to_factory/options_parser.rb +4 -4
- data/lib/to_factory/parsing/file.rb +85 -14
- data/lib/to_factory/representation.rb +9 -6
- data/lib/to_factory/version.rb +1 -1
- data/lib/to_factory.rb +7 -8
- data/spec/db/migrate/1_create_users.rb +4 -4
- data/spec/db/migrate/2_create_projects.rb +4 -4
- data/spec/db/migrate/3_create_not_namespaced.rb +4 -4
- data/spec/db/migrate/4_add_birthday_to_users.rb +3 -3
- data/spec/db/migrate/5_add_serialized_attributes_to_users.rb +3 -3
- data/spec/example_factories/admin.rb +6 -6
- data/spec/example_factories/admin_with_header.rb +7 -7
- data/spec/example_factories/inherited_project_with_header.rb +7 -0
- data/spec/example_factories/project_with_header.rb +4 -4
- data/spec/example_factories/user.rb +5 -5
- data/spec/example_factories/user_admin.rb +11 -11
- data/spec/example_factories/user_admin_root.rb +12 -13
- data/spec/example_factories/user_admin_super_admin.rb +6 -6
- data/spec/example_factories/user_admin_with_header.rb +12 -12
- data/spec/example_factories/user_with_header.rb +6 -6
- data/spec/integration/empty_factory_file_spec.rb +2 -2
- data/spec/integration/file_sync_spec.rb +16 -17
- data/spec/integration/file_writer_spec.rb +13 -9
- data/spec/integration/lint_spec.rb +4 -3
- data/spec/integration/multiple_to_factory_calls_spec.rb +37 -35
- data/spec/integration/non_active_record_classes_spec.rb +40 -0
- data/spec/integration/to_factory_method_spec.rb +21 -18
- data/spec/spec_helper.rb +8 -8
- data/spec/support/data_creation.rb +11 -13
- data/spec/support/match_sexp.rb +0 -1
- data/spec/support/non_active_record/inherited_project.rb +3 -0
- data/spec/support/non_active_record/project.rb +3 -0
- data/spec/support/non_active_record/some_other_service_inheriting_from_something_else.rb +4 -0
- data/spec/support/non_active_record/some_service.rb +2 -0
- data/spec/support/non_active_record/something_else.rb +2 -0
- data/spec/support/ruby_parser_exception_causing_string.rb +29 -29
- data/spec/unit/collation_spec.rb +9 -10
- data/spec/unit/file_writer_spec.rb +4 -8
- data/spec/unit/finders/factory_spec.rb +7 -9
- data/spec/unit/finders/model_spec.rb +6 -9
- data/spec/unit/generation/attribute_spec.rb +11 -12
- data/spec/unit/generation/factory_spec.rb +14 -16
- data/spec/unit/parsing/file_spec.rb +9 -9
- data/spec/unit/parsing/klass_inference_spec.rb +5 -7
- data/to_factory.gemspec +14 -10
- metadata +89 -31
- data/.travis.yml +0 -16
- data/lib/to_factory/parsing/syntax.rb +0 -83
@@ -5,7 +5,7 @@ module ToFactory::DataCreation
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def create_project!
|
8
|
-
ToFactory::Project.create(
|
8
|
+
ToFactory::Project.create(name: "My Project", objective: "easy testing", some_id: 9)
|
9
9
|
end
|
10
10
|
|
11
11
|
def birthday
|
@@ -14,23 +14,21 @@ module ToFactory::DataCreation
|
|
14
14
|
|
15
15
|
def create_user!
|
16
16
|
ToFactory::User.create(
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
17
|
+
name: "Jeff",
|
18
|
+
email: "test@example.com",
|
19
|
+
some_attributes: { a: 1 },
|
20
|
+
some_id: 8,
|
21
|
+
birthday: birthday
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
25
|
def create_admin!
|
26
26
|
ToFactory::User.create(
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
27
|
+
name: "Admin",
|
28
|
+
email: "admin@example.com",
|
29
|
+
some_attributes: { a: 1 },
|
30
|
+
some_id: 9,
|
31
|
+
birthday: birthday
|
32
32
|
)
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
36
|
-
|
data/spec/support/match_sexp.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
"
|
2
|
-
\ \ \ - \ \
|
3
|
-
|
4
|
-
|
5
|
-
,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
\
|
11
|
-
|
12
|
-
|
13
|
-
\
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
,
|
24
|
-
|
25
|
-
\ \
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
"
|
2
|
+
\ \ \ - \ \
|
3
|
+
|
4
|
+
|
5
|
+
,
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
\
|
11
|
+
|
12
|
+
|
13
|
+
\
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
,
|
24
|
+
|
25
|
+
\ \
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
30
|
|
31
31
|
\ "
|
data/spec/unit/collation_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
describe ToFactory::Collation do
|
2
2
|
describe "detect_collisions!" do
|
3
|
-
let(:collation) { ToFactory::Collation.new(a,b) }
|
4
|
-
let(:a) { [double(:
|
5
|
-
let(:b) { [double(:
|
3
|
+
let(:collation) { ToFactory::Collation.new(a, b) }
|
4
|
+
let(:a) { [double(name: "a")] }
|
5
|
+
let(:b) { [double(name: "a")] }
|
6
6
|
|
7
7
|
def perform
|
8
8
|
collation.detect_collisions!(a, b)
|
9
9
|
end
|
10
10
|
|
11
11
|
it do
|
12
|
-
expect
|
12
|
+
expect { perform }.to raise_error ToFactory::AlreadyExists
|
13
13
|
end
|
14
14
|
|
15
15
|
context "non matching keys" do
|
16
|
-
let(:a) { [double(:
|
17
|
-
let(:b) { [double(:
|
16
|
+
let(:a) { [double(name: "a")] }
|
17
|
+
let(:b) { [double(name: "b")] }
|
18
18
|
|
19
19
|
it do
|
20
20
|
expect(perform).to eq nil
|
@@ -29,14 +29,13 @@ describe ToFactory::Collation do
|
|
29
29
|
let(:super_admin) { ToFactory::Representation.new("super_admin", "admin", "Factory.define(:super_admin, :parent => :admin) { |o| o.name(\"Super Admin\") }") }
|
30
30
|
|
31
31
|
it do
|
32
|
-
new_definitions = [
|
33
|
-
pre_existing = [
|
32
|
+
new_definitions = [root]
|
33
|
+
pre_existing = [admin, user, super_admin]
|
34
34
|
|
35
35
|
result = ToFactory::Collation.organize(new_definitions, pre_existing)
|
36
36
|
result = result["to_factory/user"]
|
37
|
-
expect(result.map &:hierarchy_order).to eq [1,2,3,4]
|
37
|
+
expect(result.map &:hierarchy_order).to eq [1, 2, 3, 4]
|
38
38
|
expect(result).to eq [user, admin, super_admin, root]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
@@ -12,17 +12,13 @@ describe ToFactory::FileWriter do
|
|
12
12
|
|
13
13
|
it "adds factories for all models" do
|
14
14
|
user_representation = double :name => :user, "definition" => "factory a"
|
15
|
-
project_representation = double :
|
16
|
-
fw.write(
|
17
|
-
|
18
|
-
})
|
15
|
+
project_representation = double name: "project", definition: "factory b"
|
16
|
+
fw.write("to_factory/user" => [user_representation],
|
17
|
+
"to_factory/project" => [project_representation])
|
19
18
|
|
20
|
-
expect(user_file).to match /
|
19
|
+
expect(user_file).to match /FactoryBot.define do/
|
21
20
|
expect(user_file).to include "factory a"
|
22
21
|
expect(project_file).to include "factory b"
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
24
|
end
|
@@ -3,24 +3,22 @@ describe ToFactory::Finders::Factory do
|
|
3
3
|
before do
|
4
4
|
FileUtils.mkdir_p "./tmp/factories/to_factory"
|
5
5
|
FileUtils.cp "./spec/example_factories/user_admin_with_header.rb",
|
6
|
-
|
6
|
+
"./tmp/factories/to_factory/user.rb"
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:user_file_contents) { File.read "./spec/example_factories/user.rb"}
|
10
|
-
let(:admin_file_contents){ File.read "./spec/example_factories/admin.rb" }
|
9
|
+
let(:user_file_contents) { File.read "./spec/example_factories/user.rb" }
|
10
|
+
let(:admin_file_contents) { File.read "./spec/example_factories/admin.rb" }
|
11
11
|
|
12
12
|
it "reads all the factories" do
|
13
13
|
finder = ToFactory::Finders::Factory.new
|
14
14
|
|
15
15
|
result = finder.call
|
16
16
|
|
17
|
-
expect(result[0].definition)
|
18
|
-
to match_sexp user_file_contents
|
17
|
+
expect(result[0].definition)
|
18
|
+
.to match_sexp user_file_contents
|
19
19
|
|
20
|
-
expect(result[1].definition)
|
21
|
-
to match_sexp admin_file_contents
|
20
|
+
expect(result[1].definition)
|
21
|
+
.to match_sexp admin_file_contents
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
24
|
end
|
26
|
-
|
@@ -7,8 +7,8 @@ describe ToFactory::Finders::Model do
|
|
7
7
|
let(:path) { "./spec/support/models" }
|
8
8
|
|
9
9
|
describe "#call" do
|
10
|
-
let!(:user) { ToFactory::User.create! :
|
11
|
-
let!(:project) { ToFactory::Project.create! :
|
10
|
+
let!(:user) { ToFactory::User.create! name: "a user" }
|
11
|
+
let!(:project) { ToFactory::Project.create! name: "a project" }
|
12
12
|
|
13
13
|
context "with a match" do
|
14
14
|
it do
|
@@ -32,8 +32,8 @@ describe ToFactory::Finders::Model do
|
|
32
32
|
it "displays a warning" do
|
33
33
|
expect(finder.call).to eq [project]
|
34
34
|
|
35
|
-
expect(finder).to have_received(:warn)
|
36
|
-
with(
|
35
|
+
expect(finder).to have_received(:warn)
|
36
|
+
.with("Failed to eval ./spec/support/broken_models/invalid_ruby_file.rb")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -47,12 +47,9 @@ describe ToFactory::Finders::Model do
|
|
47
47
|
expect(klass).to receive(:ancestors).and_raise("Some error")
|
48
48
|
finder.call(klasses: [klass])
|
49
49
|
|
50
|
-
expect(finder).to have_received(:warn)
|
51
|
-
with(
|
50
|
+
expect(finder).to have_received(:warn)
|
51
|
+
.with("Failed to get record from BrokenClass \"Some error\"")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
56
55
|
end
|
57
|
-
|
58
|
-
|
@@ -1,16 +1,16 @@
|
|
1
1
|
describe ToFactory::Generation::Attribute do
|
2
|
-
let(:attribute) { ToFactory::Generation::Attribute.new(:some_attributes,
|
2
|
+
let(:attribute) { ToFactory::Generation::Attribute.new(:some_attributes, a: 1) }
|
3
3
|
|
4
4
|
describe "#to_s" do
|
5
5
|
it do
|
6
|
-
expect(attribute.to_s).to include "some_attributes
|
6
|
+
expect(attribute.to_s).to include "some_attributes { {:a => 1} }"
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#format" do
|
11
11
|
it "formats Date, Time, DateTime" do
|
12
|
-
Time.zone= "UTC"
|
13
|
-
time_string ="2011-12-13T14:15 UTC"
|
12
|
+
Time.zone = "UTC"
|
13
|
+
time_string = "2011-12-13T14:15 UTC"
|
14
14
|
|
15
15
|
expect(attribute.format(Time .parse(time_string))).to eq "2011-12-13T14:15 UTC".inspect
|
16
16
|
expect(attribute.format(Date .parse(time_string))).to eq "2011-12-13".inspect
|
@@ -23,12 +23,12 @@ describe ToFactory::Generation::Attribute do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "formats BigDecimal"do
|
26
|
-
expect(attribute.format(BigDecimal
|
26
|
+
expect(attribute.format(BigDecimal "123456789012345678900.0")).to eq "BigDecimal.new(\"123456789012345678900.0\")"
|
27
27
|
end
|
28
28
|
|
29
29
|
it "handles unparseable strings" do
|
30
|
-
#NB this spec may only have been relevant for ruby 1.8 i.e. older RubyParser versions
|
31
|
-
#see https://github.com/markburns/to_factory/issues/4
|
30
|
+
# NB this spec may only have been relevant for ruby 1.8 i.e. older RubyParser versions
|
31
|
+
# see https://github.com/markburns/to_factory/issues/4
|
32
32
|
parser = double "RubyParser"
|
33
33
|
expect(parser).to receive(:parse).and_raise "some error"
|
34
34
|
attribute.parser = parser
|
@@ -37,18 +37,17 @@ describe ToFactory::Generation::Attribute do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
40
|
describe "#inspect_value" do
|
42
41
|
it do
|
43
|
-
expect(attribute.inspect_value(
|
42
|
+
expect(attribute.inspect_value(a: 1)).to eq " { {:a => 1} }"
|
44
43
|
end
|
45
44
|
it "formats hashes correctly" do
|
46
45
|
hash = ActiveSupport::OrderedHash.new
|
47
|
-
hash[{"with" => :hash}] = "keys"
|
46
|
+
hash[{ "with" => :hash }] = "keys"
|
48
47
|
hash[2] = "integers"
|
49
|
-
hash[:a] = {:
|
48
|
+
hash[:a] = { nested: "hash" }
|
50
49
|
|
51
|
-
expected = '
|
50
|
+
expected = ' { {{"with" => :hash} => "keys", 2 => "integers", :a => {:nested => "hash"}} }'
|
52
51
|
|
53
52
|
expect(attribute.inspect_value(hash)).to eq expected
|
54
53
|
end
|
@@ -11,7 +11,7 @@ describe ToFactory::Generation::Factory do
|
|
11
11
|
let!(:user) { create_user! }
|
12
12
|
|
13
13
|
let(:representation) { ToFactory::Representation.from(user) }
|
14
|
-
let(:generator) { ToFactory::Generation::Factory.new representation
|
14
|
+
let(:generator) { ToFactory::Generation::Factory.new representation }
|
15
15
|
|
16
16
|
describe "#name" do
|
17
17
|
context "with a simple name" do
|
@@ -39,11 +39,9 @@ describe ToFactory::Generation::Factory do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
42
|
describe "#header" do
|
45
43
|
it do
|
46
|
-
expect(generator.header{}).to match_sexp
|
44
|
+
expect(generator.header {}).to match_sexp <<-eof.strip_heredoc
|
47
45
|
factory(:"to_factory/user") do
|
48
46
|
end
|
49
47
|
eof
|
@@ -52,27 +50,27 @@ describe ToFactory::Generation::Factory do
|
|
52
50
|
|
53
51
|
describe "#attributes" do
|
54
52
|
let(:representation) do
|
55
|
-
double(:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
double(attributes: { "something" => "something",
|
54
|
+
:id => 123,
|
55
|
+
:created_at => anything,
|
56
|
+
:created_on => anything,
|
57
|
+
:updated_at => anything,
|
58
|
+
:updated_on => anything,
|
59
|
+
nil => nil })
|
62
60
|
end
|
63
61
|
it "ignores blank keys, :id, :created_at, :updated_at, :created_on, :updated_on" do
|
64
|
-
expect(generator.attributes).to eq(
|
62
|
+
expect(generator.attributes).to eq("something" => "something")
|
65
63
|
end
|
66
64
|
end
|
67
65
|
describe "#factory_attribute" do
|
68
66
|
it do
|
69
|
-
expect(generator.factory_attribute(:name, nil)) .to eq
|
70
|
-
expect(generator.factory_attribute(:name, "Jeff")).to eq ' name "Jeff"'
|
71
|
-
expect(generator.factory_attribute(:id, 8)) .to eq
|
67
|
+
expect(generator.factory_attribute(:name, nil)) .to eq " name { nil }"
|
68
|
+
expect(generator.factory_attribute(:name, "Jeff")).to eq ' name { "Jeff" }'
|
69
|
+
expect(generator.factory_attribute(:id, 8)) .to eq " id { 8 }"
|
72
70
|
end
|
73
71
|
it "generates usable datetime strings" do
|
74
72
|
output = generator.factory_attribute(:birthday, birthday)
|
75
|
-
expect(output).to eq ' birthday "2014-07-08T15:30 UTC"'
|
73
|
+
expect(output).to eq ' birthday { "2014-07-08T15:30 UTC" }'
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe ToFactory::Parsing::File do
|
2
2
|
let(:user_contents) { File.read "spec/example_factories/user.rb" }
|
3
|
-
let(:admin_contents) { File.read "spec/example_factories/admin.rb"}
|
3
|
+
let(:admin_contents) { File.read "spec/example_factories/admin.rb" }
|
4
4
|
|
5
5
|
let(:parser) { ToFactory::Parsing::File.from_file(filename) }
|
6
6
|
|
@@ -18,7 +18,7 @@ describe ToFactory::Parsing::File do
|
|
18
18
|
|
19
19
|
it do
|
20
20
|
expect(Kernel).to receive(:warn).with(/#{dynamic_content}/).at_least :once
|
21
|
-
expect
|
21
|
+
expect { instance.parse }.not_to raise_error
|
22
22
|
result = instance.parse
|
23
23
|
expect(result).to be_a Array
|
24
24
|
expect(result[0]).to be_a ToFactory::NullRepresentation
|
@@ -28,7 +28,7 @@ describe ToFactory::Parsing::File do
|
|
28
28
|
|
29
29
|
describe "#multiple_factories? and #header?" do
|
30
30
|
context "new syntax" do
|
31
|
-
tests =
|
31
|
+
tests = # file, multiple, header
|
32
32
|
[
|
33
33
|
["user", false, false],
|
34
34
|
["user_with_header", false, true],
|
@@ -39,7 +39,7 @@ describe ToFactory::Parsing::File do
|
|
39
39
|
tests.each do |file, multiple, header|
|
40
40
|
context "with #{header ? 'header' : 'no header'} and #{multiple ? 'multiple factories' : 'one factory'}" do
|
41
41
|
context "file: #{file}" do
|
42
|
-
let(:filename) { "spec/example_factories/#{file}.rb"}
|
42
|
+
let(:filename) { "spec/example_factories/#{file}.rb" }
|
43
43
|
|
44
44
|
it { expect(parser.multiple_factories?).to eq multiple }
|
45
45
|
it { expect(parser.header?).to eq header }
|
@@ -51,7 +51,7 @@ describe ToFactory::Parsing::File do
|
|
51
51
|
|
52
52
|
describe "#parse" do
|
53
53
|
context "with multiple levels of parent classes" do
|
54
|
-
let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb"}
|
54
|
+
let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb" }
|
55
55
|
|
56
56
|
it do
|
57
57
|
result = parser.parse
|
@@ -61,7 +61,7 @@ describe ToFactory::Parsing::File do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
context "file: user" do
|
64
|
-
let(:filename) { "spec/example_factories/#{'user'}.rb"}
|
64
|
+
let(:filename) { "spec/example_factories/#{'user'}.rb" }
|
65
65
|
|
66
66
|
it do
|
67
67
|
result = parser.parse
|
@@ -71,7 +71,7 @@ describe ToFactory::Parsing::File do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
context "file: user_with_header" do
|
74
|
-
let(:filename) { "spec/example_factories/#{'user_with_header'}.rb"}
|
74
|
+
let(:filename) { "spec/example_factories/#{'user_with_header'}.rb" }
|
75
75
|
|
76
76
|
it do
|
77
77
|
result = parser.parse
|
@@ -81,7 +81,7 @@ describe ToFactory::Parsing::File do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
context "file: user_admin" do
|
84
|
-
let(:filename) { "spec/example_factories/#{'user_admin'}.rb"}
|
84
|
+
let(:filename) { "spec/example_factories/#{'user_admin'}.rb" }
|
85
85
|
|
86
86
|
it do
|
87
87
|
result = parser.parse
|
@@ -94,7 +94,7 @@ describe ToFactory::Parsing::File do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
context "file: user_admin_with_header" do
|
97
|
-
let(:filename) { "spec/example_factories/#{'user_admin_with_header'}.rb"}
|
97
|
+
let(:filename) { "spec/example_factories/#{'user_admin_with_header'}.rb" }
|
98
98
|
|
99
99
|
it do
|
100
100
|
result = parser.parse
|
@@ -2,27 +2,25 @@ describe ToFactory::KlassInference do
|
|
2
2
|
let(:inference) { ToFactory::KlassInference.new representations }
|
3
3
|
|
4
4
|
mappings = [
|
5
|
-
[:super_admin,
|
5
|
+
[:super_admin, :admin, ToFactory::User, 3],
|
6
6
|
[:"to_factory/user", nil, ToFactory::User, 1],
|
7
7
|
[:admin, :"to_factory/user", ToFactory::User, 2],
|
8
8
|
[:some_project, :"to_factory/project", ToFactory::Project, 2],
|
9
|
-
[:sub_project, :
|
9
|
+
[:sub_project, :some_project, ToFactory::Project, 3]
|
10
10
|
]
|
11
11
|
|
12
|
-
|
13
|
-
let(:representations) { mappings.map{|name, parent, _| ToFactory::Representation.new(name,parent) }}
|
12
|
+
let(:representations) { mappings.map { |name, parent, _| ToFactory::Representation.new(name, parent) } }
|
14
13
|
|
15
14
|
mappings.each do |name, parent_name, expected_klass, expected_order|
|
16
15
|
it "having #{name} and #{parent_name.inspect} implies #{expected_klass} #{expected_order} "do
|
17
16
|
result_klass, order = inference.infer(name.to_s)
|
18
17
|
|
19
18
|
expect(result_klass).to eq expected_klass
|
20
|
-
expect(order
|
19
|
+
expect(order).to eq expected_order
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
it do
|
25
|
-
|
26
|
-
expect(lambda{inference.infer("unknown")}).to raise_error
|
24
|
+
expect { inference.infer("unknown") }.to raise_error ToFactory::CannotInferClass
|
27
25
|
end
|
28
26
|
end
|
data/to_factory.gemspec
CHANGED
@@ -1,32 +1,36 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "to_factory/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "to_factory"
|
8
8
|
spec.version = ToFactory::VERSION
|
9
9
|
spec.authors = ["Mark Burns"]
|
10
10
|
spec.email = ["markthedeveloper@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Turn ActiveRecord instances into factories"
|
12
|
+
spec.description = "Autogenerate and append/create factory_bot definitions from the console"
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}){ |f| File.basename(f) }.reject{|f| f== "spec" || f =="ci" }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }.reject { |f| f == "spec" || f == "ci" }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "factory_bot"
|
22
22
|
spec.add_dependency "ruby2ruby"
|
23
|
-
spec.add_dependency "activerecord", "> 4.0"
|
24
23
|
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "activerecord"
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
|
+
spec.add_development_dependency "database_cleaner"
|
27
27
|
|
28
28
|
spec.add_development_dependency "byebug"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
|
31
|
+
spec.add_development_dependency 'simplecov'
|
32
|
+
spec.add_development_dependency 'rspec-github'
|
29
33
|
|
30
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
-
spec.add_development_dependency "rake", "
|
35
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
32
36
|
end
|