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
@@ -1,9 +1,9 @@
1
- FactoryGirl.define do
2
- factory(:admin, :parent => :"to_factory/user") do
3
- birthday "2014-07-08T15:30 UTC"
4
- email "admin@example.com"
5
- name "Admin"
6
- some_attributes({:a => 1})
7
- some_id 9
1
+ FactoryBot.define do
2
+ factory(:admin, parent: :"to_factory/user") do
3
+ birthday { "2014-07-08T15:30 UTC" }
4
+ email { "admin@example.com" }
5
+ name {"Admin" }
6
+ some_attributes { {a: 1 } }
7
+ some_id { 9 }
8
8
  end
9
9
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory(:"to_factory/inherited_project") do
3
+ name { "My Project" }
4
+ objective { "easy testing" }
5
+ some_id { 9 }
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory(:"to_factory/project") do
3
- name "My Project"
4
- objective "easy testing"
5
- some_id 9
3
+ name { "My Project" }
4
+ objective { "easy testing" }
5
+ some_id { 9 }
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  factory(:"to_factory/user") do
2
- birthday "2014-07-08T15:30 UTC"
3
- email "test@example.com"
4
- name "Jeff"
5
- some_attributes({:a => 1})
6
- some_id 8
2
+ birthday {"2014-07-08T15:30 UTC"}
3
+ email {"test@example.com"}
4
+ name {"Jeff"}
5
+ some_attributes {{a: 1}}
6
+ some_id { 8 }
7
7
  end
@@ -1,15 +1,15 @@
1
1
  factory(:"to_factory/user") do
2
- birthday "2014-07-08T15:30 UTC"
3
- email "test@example.com"
4
- name "Jeff"
5
- some_attributes({:a => 1})
6
- some_id 8
2
+ birthday { "2014-07-08T15:30 UTC" }
3
+ email { "test@example.com" }
4
+ name { "Jeff" }
5
+ some_attributes { {a: 1 } }
6
+ some_id { 8 }
7
7
  end
8
8
 
9
- factory(:admin, :parent => :"to_factory/user") do
10
- birthday "2014-07-08T15:30 UTC"
11
- email "admin@example.com"
12
- name "Admin"
13
- some_attributes({:a => 1})
14
- some_id 9
9
+ factory(:admin, parent: :"to_factory/user") do
10
+ birthday {"2014-07-08T15:30 UTC"}
11
+ email {"admin@example.com"}
12
+ name {"Admin"}
13
+ some_attributes { {a: 1 } }
14
+ some_id { 9 }
15
15
  end
@@ -1,22 +1,21 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory(:"to_factory/user") do
3
- name("User")
3
+ name {"User"}
4
4
  end
5
5
 
6
- factory(:admin, :parent => :"to_factory/user") do
7
- name("Admin")
6
+ factory(:admin, parent: :"to_factory/user") do
7
+ name {"Admin"}
8
8
  end
9
9
 
10
- factory(:root, :parent => :"to_factory/user") do
11
- birthday "2014-07-08T15:30 UTC"
12
- email "test@example.com"
13
- name "Jeff"
14
- some_attributes({:a => 1})
15
- some_id 8
10
+ factory(:root, parent: :"to_factory/user") do
11
+ birthday {"2014-07-08T15:30 UTC"}
12
+ email {"test@example.com"}
13
+ name {"Jeff"}
14
+ some_attributes {{a: 1}}
15
+ some_id { 8 }
16
16
  end
17
17
 
18
-
19
- factory(:super_admin, :parent => :admin) do
20
- name("Super Admin")
18
+ factory(:super_admin, parent: :admin) do
19
+ name {"Super Admin"}
21
20
  end
22
21
  end
@@ -1,13 +1,13 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory(:"to_factory/user") do
3
- name "User"
3
+ name {"User"}
4
4
  end
5
5
 
6
- factory(:admin, :parent => :"to_factory/user") do
7
- name "Admin"
6
+ factory(:admin, parent: :"to_factory/user") do
7
+ name {"Admin" }
8
8
  end
9
9
 
10
- factory(:super_admin, :parent => :admin) do
11
- name "Super Admin"
10
+ factory(:super_admin, parent: :admin) do
11
+ name {"Super Admin"}
12
12
  end
13
13
  end
@@ -1,17 +1,17 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory(:"to_factory/user") do
3
- birthday "2014-07-08T15:30 UTC"
4
- email "test@example.com"
5
- name "Jeff"
6
- some_attributes({:a => 1})
7
- some_id 8
3
+ birthday {"2014-07-08T15:30 UTC"}
4
+ email {"test@example.com"}
5
+ name {"Jeff"}
6
+ some_attributes {{a: 1}}
7
+ some_id { 8 }
8
8
  end
9
9
 
10
- factory(:admin, :parent => :"to_factory/user") do
11
- birthday "2014-07-08T15:30 UTC"
12
- email "admin@example.com"
13
- name "Admin"
14
- some_attributes({:a => 1})
15
- some_id 9
10
+ factory(:admin, parent: :"to_factory/user") do
11
+ birthday {"2014-07-08T15:30 UTC"}
12
+ email {"admin@example.com"}
13
+ name {"Admin"}
14
+ some_attributes {{a: 1}}
15
+ some_id { 9 }
16
16
  end
17
17
  end
@@ -1,9 +1,9 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory(:"to_factory/user") do
3
- birthday "2014-07-08T15:30 UTC"
4
- email "test@example.com"
5
- name "Jeff"
6
- some_attributes({:a => 1})
7
- some_id 8
3
+ birthday { "2014-07-08T15:30 UTC" }
4
+ email { "test@example.com" }
5
+ name { "Jeff" }
6
+ some_attributes { {:a => 1} }
7
+ some_id { 8 }
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  describe "Empty File spec" do
2
- let(:user) { create_user! }
2
+ let(:user) { create_user! }
3
3
 
4
4
  context "with an empty factory file" do
5
5
  before do
@@ -13,7 +13,7 @@ describe "Empty File spec" do
13
13
  end
14
14
 
15
15
  it "doesn't blow up" do
16
- ToFactory(:empty => OpenStruct.new({attributes: {}}), :user => user)
16
+ ToFactory(empty: OpenStruct.new({ attributes: {} }), user: user)
17
17
  end
18
18
  end
19
19
  end
@@ -1,7 +1,7 @@
1
1
  describe "FileSync" do
2
- let(:user) { create_user! }
3
- let(:admin) { create_admin! }
4
- let(:project) { create_project! }
2
+ let(:user) { create_user! }
3
+ let(:admin) { create_admin! }
4
+ let(:project) { create_project! }
5
5
  let(:expected_user_file) { File.read("./spec/example_factories/user.rb") }
6
6
  let(:expected_user_with_header_file) { File.read("./spec/example_factories/user_with_header.rb") }
7
7
  let(:expected_admin_file) { File.read("./spec/example_factories/admin.rb") }
@@ -9,11 +9,15 @@ describe "FileSync" do
9
9
  let(:user_admin_with_header) { File.read("./spec/example_factories/user_admin_with_header.rb") }
10
10
 
11
11
  def user_file
12
- File.read("./tmp/factories/to_factory/user.rb") rescue nil
12
+ File.read("./tmp/factories/to_factory/user.rb")
13
+ rescue
14
+ nil
13
15
  end
14
16
 
15
17
  def project_file
16
- File.read("./tmp/factories/to_factory/project.rb") rescue nil
18
+ File.read("./tmp/factories/to_factory/project.rb")
19
+ rescue
20
+ nil
17
21
  end
18
22
 
19
23
  context "with no arguments" do
@@ -26,7 +30,7 @@ describe "FileSync" do
26
30
  sync = ToFactory::FileSync.new
27
31
  sync.perform
28
32
 
29
- expect(user_file ).to match_sexp expected_user_with_header_file
33
+ expect(user_file).to match_sexp expected_user_with_header_file
30
34
  end
31
35
  end
32
36
 
@@ -35,13 +39,11 @@ describe "FileSync" do
35
39
  sync = ToFactory::FileSync.new(user)
36
40
  sync.perform
37
41
 
38
- expect(user_file ).to match_sexp user_with_header
42
+ expect(user_file).to match_sexp user_with_header
39
43
  expect(project_file).to eq nil
40
44
  end
41
45
  end
42
46
 
43
-
44
-
45
47
  context "with a pre-existing file" do
46
48
  let(:sync) { ToFactory::FileSync.new(user) }
47
49
  before do
@@ -50,26 +52,23 @@ describe "FileSync" do
50
52
  end
51
53
 
52
54
  it "raises an error" do
53
- expect(lambda{ sync.perform }).to raise_error ToFactory::AlreadyExists
55
+ expect { sync.perform }.to raise_error ToFactory::AlreadyExists
54
56
  end
55
57
 
56
58
  context "with a named factory" do
57
59
  it do
58
- sync = ToFactory::FileSync.new({:admin => admin})
60
+ sync = ToFactory::FileSync.new(admin: admin)
59
61
  sync.perform
60
62
 
61
63
  parser = ToFactory::Parsing::File.new(user_file)
62
64
  result = parser.parse
63
- admin= result.find{|r| r.name == "admin"}
64
- user= result.find{|r| r.name == "to_factory/user"}
65
-
65
+ admin = result.find { |r| r.name == "admin" }
66
+ user = result.find { |r| r.name == "to_factory/user" }
66
67
 
67
68
  expect(admin.definition).to match_sexp expected_admin_file
68
69
  expect(user.definition).to match_sexp expected_user_file
69
70
 
70
- expect(lambda{
71
- sync.perform
72
- }).to raise_error ToFactory::AlreadyExists
71
+ expect { sync.perform }.to raise_error ToFactory::AlreadyExists
73
72
  end
74
73
  end
75
74
  end
@@ -1,18 +1,22 @@
1
1
  describe ToFactory::FileWriter do
2
- let(:fw) { ToFactory::FileWriter.new }
3
- let(:expected) { File.read "./spec/example_factories/user_with_header.rb"}
4
- let(:user_file_contents) { File.read "./tmp/factories/to_factory/user.rb"}
2
+ let(:file_writer) { ToFactory::FileWriter.new }
3
+ let(:user_file_contents) { File.read "./tmp/factories/to_factory/user.rb" }
5
4
  let!(:user) { create_user! }
6
- let!(:admin) { create_admin! }
5
+ let!(:admin) { create_admin! }
6
+ let(:file_sync) { ToFactory::FileSync.new }
7
+ let(:representations) { file_sync.all_representations }
7
8
 
8
- it do
9
- fs = ToFactory::FileSync.new
10
- representations = fs.all_representations
11
- #sanity check generation isn't broken
9
+ let(:expected) { File.read "./spec/example_factories/user_with_header.rb" }
10
+
11
+ before do
12
+ # sanity check generation isn't broken
12
13
  expect(representations.keys).to eq ["to_factory/user"]
13
14
  expect(representations.values[0][0]).to be_a ToFactory::Representation
15
+ end
16
+
17
+ it 'writes correctly' do
18
+ file_writer.write representations
14
19
 
15
- fw.write representations
16
20
  expect(user_file_contents).to match_sexp expected
17
21
  end
18
22
  end
@@ -1,12 +1,13 @@
1
1
  context "full integration" do
2
2
  let(:user) do
3
- ToFactory::User.create :name => "Jeff", :email => "test@example.com", :some_id => 8, :birthday => Time.now
3
+ ToFactory::User.create name: "Jeff", email: "test@example.com", some_id: 8, birthday: Time.now
4
4
  end
5
5
 
6
6
  it "#to_factory linting the output" do
7
7
  ToFactory(user)
8
+ require 'factory_bot'
9
+
8
10
  load "./tmp/factories/to_factory/user.rb"
9
- FactoryGirl.lint
11
+ FactoryBot.lint
10
12
  end
11
13
  end
12
-
@@ -1,11 +1,13 @@
1
1
  describe ToFactory do
2
- let!(:user) { create_user! }
2
+ let!(:user) { create_user! }
3
3
 
4
4
  def user_file
5
- File.read("./tmp/factories/to_factory/user.rb") rescue nil
5
+ File.read("./tmp/factories/to_factory/user.rb")
6
+ rescue
7
+ nil
6
8
  end
7
9
 
8
- let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb"}
10
+ let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb" }
9
11
 
10
12
  context "single call" do
11
13
  before do
@@ -24,21 +26,21 @@ describe ToFactory do
24
26
 
25
27
  it "renders two factories correctly" do
26
28
  expect(user_file).to eq <<-FACTORY.strip_heredoc
27
- FactoryGirl.define do
29
+ FactoryBot.define do
28
30
  factory(:"to_factory/user") do
29
- birthday("2014-07-08T15:30 UTC")
30
- email("test@example.com")
31
- name("Jeff")
32
- some_attributes(:a => 1)
33
- some_id(8)
31
+ birthday { "2014-07-08T15:30 UTC" }
32
+ email { "test@example.com" }
33
+ name { "Jeff" }
34
+ some_attributes { { :a => 1 } }
35
+ some_id { 8 }
34
36
  end
35
37
 
36
38
  factory(:user_2, :parent => :"to_factory/user") do
37
- birthday "2014-07-08T15:30 UTC"
38
- email "test@example.com"
39
- name "Jeff"
40
- some_attributes({:a => 1})
41
- some_id 8
39
+ birthday { "2014-07-08T15:30 UTC" }
40
+ email { "test@example.com" }
41
+ name { "Jeff" }
42
+ some_attributes { {:a => 1} }
43
+ some_id { 8 }
42
44
  end
43
45
  end
44
46
  FACTORY
@@ -55,37 +57,37 @@ describe ToFactory do
55
57
 
56
58
  it "renders multiple factories correctly" do
57
59
  expect(user_file).to match_sexp <<-FACTORY
58
- FactoryGirl.define do
60
+ FactoryBot.define do
59
61
  factory(:"to_factory/user") do
60
- birthday("2014-07-08T15:30 UTC")
61
- email("test@example.com")
62
- name("Jeff")
63
- some_attributes(:a => 1)
64
- some_id(8)
62
+ birthday { "2014-07-08T15:30 UTC" }
63
+ email { "test@example.com" }
64
+ name { "Jeff" }
65
+ some_attributes { {:a => 1} }
66
+ some_id { 8 }
65
67
  end
66
68
 
67
69
  factory(:user_2, :parent => :"to_factory/user") do
68
- birthday("2014-07-08T15:30 UTC")
69
- email("test@example.com")
70
- name("Jeff")
71
- some_attributes(:a => 1)
72
- some_id(8)
70
+ birthday { "2014-07-08T15:30 UTC" }
71
+ email { "test@example.com" }
72
+ name { "Jeff" }
73
+ some_attributes { {:a => 1} }
74
+ some_id { 8 }
73
75
  end
74
76
 
75
77
  factory(:user_3, :parent => :"to_factory/user") do
76
- birthday("2014-07-08T15:30 UTC")
77
- email("test@example.com")
78
- name("Jeff")
79
- some_attributes(:a => 1)
80
- some_id(8)
78
+ birthday { "2014-07-08T15:30 UTC" }
79
+ email { "test@example.com" }
80
+ name { "Jeff" }
81
+ some_attributes { {:a => 1} }
82
+ some_id { 8 }
81
83
  end
82
84
 
83
85
  factory(:user_4, :parent => :"to_factory/user") do
84
- birthday "2014-07-08T15:30 UTC"
85
- email "test@example.com"
86
- name "Jeff"
87
- some_attributes({:a => 1})
88
- some_id 8
86
+ birthday { "2014-07-08T15:30 UTC" }
87
+ email { "test@example.com" }
88
+ name { "Jeff" }
89
+ some_attributes { {:a => 1} }
90
+ some_id { 8 }
89
91
  end
90
92
  end
91
93
  FACTORY
@@ -0,0 +1,40 @@
1
+ describe "non active record classes" do
2
+ let!(:project) { create_project! }
3
+
4
+ def project_file
5
+ File.read("./tmp/factories/to_factory/project.rb")
6
+ rescue
7
+ nil
8
+ end
9
+
10
+ def inherited_project_file
11
+ File.read("./tmp/factories/to_factory/inherited_project.rb")
12
+ rescue
13
+ nil
14
+ end
15
+
16
+ let(:expected_project_file) { File.read "./spec/example_factories/project_with_header.rb" }
17
+ let(:expected_inherited_project_file) { File.read "./spec/example_factories/inherited_project_with_header.rb" }
18
+
19
+ context "given a folder with non active record models in" do
20
+ before do
21
+ ToFactory.models = "./spec/support/non_active_record"
22
+ ToFactory()
23
+ end
24
+
25
+ it "creates an ordinary factory correctly" do
26
+ expect(project_file).to match_sexp expected_project_file
27
+ end
28
+
29
+ context "STI" do
30
+ it "creates a single factory correctly" do
31
+ expect(inherited_project_file).to match_sexp expected_inherited_project_file
32
+ end
33
+ end
34
+
35
+ it "doesn't create other factories" do
36
+ count = Dir.glob("./tmp/factories/*.rb").length
37
+ expect(count).to eq 0
38
+ end
39
+ end
40
+ end
@@ -1,28 +1,31 @@
1
1
  describe ToFactory do
2
2
  let!(:user) { create_user! }
3
- let!(:project) { create_project!}
3
+ let!(:project) { create_project! }
4
4
 
5
5
  def user_file
6
- File.read("./tmp/factories/to_factory/user.rb") rescue nil
6
+ File.read("./tmp/factories/to_factory/user.rb")
7
+ rescue
8
+ nil
7
9
  end
8
10
 
9
11
  def project_file
10
- File.read("./tmp/factories/to_factory/project.rb") rescue nil
12
+ File.read("./tmp/factories/to_factory/project.rb")
13
+ rescue
14
+ nil
11
15
  end
12
16
 
13
- let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb"}
14
- let(:expected_project_file) { File.read "./spec/example_factories/project_with_header.rb"}
17
+ let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb" }
18
+ let(:expected_project_file) { File.read "./spec/example_factories/project_with_header.rb" }
15
19
 
16
20
  describe "ToFactory.definitions" do
17
21
  it do
18
22
  ToFactory()
19
23
  expect(ToFactory.definitions).to match_array ["to_factory/user", "to_factory/project"]
20
24
  end
21
-
22
25
  end
23
26
 
24
27
  describe "ToFactory.definition_for" do
25
- let(:expected_user_file) { File.read "./spec/example_factories/user.rb"}
28
+ let(:expected_user_file) { File.read "./spec/example_factories/user.rb" }
26
29
  it do
27
30
  expect(ToFactory.definition_for user).to match_sexp expected_user_file
28
31
  end
@@ -33,35 +36,35 @@ describe ToFactory do
33
36
  end
34
37
 
35
38
  it "raises a not found error" do
36
- expect(lambda{ToFactory.definition_for :"to_factory/user"}).to raise_error ToFactory::NotFoundError
39
+ expect { ToFactory.definition_for :"to_factory/user" }.to raise_error ToFactory::NotFoundError
37
40
  end
38
41
  end
39
42
 
40
43
  describe "Object#ToFactory" do
41
44
  context "with multiple levels of parent classes" do
42
- let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb"}
45
+ let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb" }
43
46
 
44
47
  it "gets the output order correct" do
45
48
  output = "./tmp/factories/to_factory/user.rb"
46
49
  `mkdir -p ./tmp/factories/to_factory`
47
50
  `cp #{filename} #{output}`
48
51
 
49
- ToFactory(:root => user)
52
+ ToFactory(root: user)
50
53
 
51
54
  expected = File.read "spec/example_factories/#{'user_admin_root'}.rb"
52
55
 
53
- #user, admin, super_admin, root
56
+ # user, admin, super_admin, root
54
57
  expect(File.read(output)).to match_sexp expected
55
58
  end
56
59
  end
57
60
 
58
61
  it "generates all factories" do
59
62
  ToFactory()
60
- #simple check for equivalent ruby
63
+ # simple check for equivalent ruby
61
64
  expect(user_file) .to match_sexp expected_user_file
62
65
  expect(project_file).to match_sexp expected_project_file
63
66
 
64
- #once we are sure output is equivalent ruby, check output is identical
67
+ # once we are sure output is equivalent ruby, check output is identical
65
68
  expect(user_file.chomp) .to eq expected_user_file.chomp
66
69
  expect(project_file.chomp).to eq expected_project_file.chomp
67
70
  end
@@ -77,13 +80,13 @@ describe ToFactory do
77
80
  end
78
81
 
79
82
  it "ignores specified classes" do
80
- ToFactory(:exclude => ToFactory::User)
83
+ ToFactory(exclude: ToFactory::User)
81
84
  expect(user_file).to be_nil
82
85
  expect(project_file).to be_present
83
86
  end
84
87
 
85
88
  it "ignores specified classes - sanity check" do
86
- ToFactory(:exclude => ToFactory::Project)
89
+ ToFactory(exclude: ToFactory::Project)
87
90
  expect(user_file).to be_present
88
91
  expect(project_file).to be_nil
89
92
  end
@@ -115,14 +118,14 @@ describe ToFactory do
115
118
  context "with a name for the factory" do
116
119
  it "appends to the file" do
117
120
  user_file_includes('factory(:"to_factory/user"')
118
- ToFactory(:specific_user => user)
121
+ ToFactory(specific_user: user)
119
122
  user_file_includes('factory(:specific_user, :parent => :"to_factory/user"')
120
123
  end
121
124
  end
122
125
 
123
126
  it "without a name" do
124
- expect(lambda{ToFactory(user)}).
125
- to raise_error ToFactory::AlreadyExists
127
+ expect { ToFactory(user) }
128
+ .to raise_error ToFactory::AlreadyExists
126
129
  end
127
130
  end
128
131
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  begin
2
- require "codeclimate-test-reporter"
3
- CodeClimate::TestReporter.start
2
+ require 'simplecov'
3
+ SimpleCov.start
4
4
  rescue LoadError
5
- #ignore on ruby 1.8.x
5
+ # ignore on ruby 1.8.x
6
6
  end
7
7
 
8
- require 'active_record'
9
- require 'active_support/core_ext/string'
10
- require 'active_support/core_ext/hash'
8
+ require "active_record"
9
+ require "active_support/core_ext/string"
10
+ require "active_support/core_ext/hash"
11
11
  require "sqlite3"
12
12
  require "database_cleaner"
13
13
 
@@ -24,8 +24,8 @@ RSpec.configure do |config|
24
24
 
25
25
  config.before :suite do
26
26
  ActiveRecord::Base.tap do |base|
27
- config = {:adapter => "sqlite3", :database => "spec/db/test.sqlite3"}
28
- base.configurations = {:test => config}.with_indifferent_access
27
+ config = { adapter: "sqlite3", database: "spec/db/test.sqlite3" }
28
+ base.configurations = { test: config }.with_indifferent_access
29
29
  base.establish_connection :test
30
30
  end
31
31