to_factory 2.0.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 (68) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +35 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop-disabled.yml +95 -0
  5. data/.rubocop-enabled.yml +1194 -0
  6. data/.rubocop.yml +938 -0
  7. data/CHANGELOG.md +11 -0
  8. data/Gemfile +6 -1
  9. data/README.md +11 -10
  10. data/Rakefile +17 -9
  11. data/lib/to_factory/collation.rb +9 -9
  12. data/lib/to_factory/file_sync.rb +11 -11
  13. data/lib/to_factory/file_writer.rb +18 -2
  14. data/lib/to_factory/finders/factory.rb +8 -2
  15. data/lib/to_factory/finders/model.rb +11 -13
  16. data/lib/to_factory/generation/attribute.rb +10 -12
  17. data/lib/to_factory/generation/factory.rb +3 -3
  18. data/lib/to_factory/klass_inference.rb +4 -6
  19. data/lib/to_factory/options_parser.rb +4 -4
  20. data/lib/to_factory/parsing/file.rb +87 -14
  21. data/lib/to_factory/representation.rb +9 -6
  22. data/lib/to_factory/version.rb +1 -1
  23. data/lib/to_factory.rb +7 -17
  24. data/spec/db/migrate/1_create_users.rb +4 -4
  25. data/spec/db/migrate/2_create_projects.rb +4 -4
  26. data/spec/db/migrate/3_create_not_namespaced.rb +4 -4
  27. data/spec/db/migrate/4_add_birthday_to_users.rb +3 -3
  28. data/spec/db/migrate/5_add_serialized_attributes_to_users.rb +3 -3
  29. data/spec/example_factories/admin.rb +6 -6
  30. data/spec/example_factories/admin_with_header.rb +7 -7
  31. data/spec/example_factories/inherited_project_with_header.rb +7 -0
  32. data/spec/example_factories/project_with_header.rb +4 -4
  33. data/spec/example_factories/user.rb +5 -5
  34. data/spec/example_factories/user_admin.rb +11 -11
  35. data/spec/example_factories/user_admin_root.rb +12 -12
  36. data/spec/example_factories/user_admin_super_admin.rb +6 -6
  37. data/spec/example_factories/user_admin_with_header.rb +12 -12
  38. data/spec/example_factories/user_with_header.rb +6 -6
  39. data/spec/integration/empty_factory_file_spec.rb +19 -0
  40. data/spec/integration/file_sync_spec.rb +16 -24
  41. data/spec/integration/file_writer_spec.rb +13 -9
  42. data/spec/integration/lint_spec.rb +4 -3
  43. data/spec/integration/multiple_to_factory_calls_spec.rb +96 -0
  44. data/spec/integration/non_active_record_classes_spec.rb +40 -0
  45. data/spec/integration/to_factory_method_spec.rb +21 -20
  46. data/spec/spec_helper.rb +9 -18
  47. data/spec/support/broken_models/invalid_ruby_file.rb +1 -0
  48. data/spec/support/broken_models/project.rb +3 -0
  49. data/spec/support/data_creation.rb +11 -13
  50. data/spec/support/match_sexp.rb +0 -1
  51. data/spec/support/non_active_record/inherited_project.rb +3 -0
  52. data/spec/support/non_active_record/project.rb +3 -0
  53. data/spec/support/non_active_record/some_other_service_inheriting_from_something_else.rb +4 -0
  54. data/spec/support/non_active_record/some_service.rb +2 -0
  55. data/spec/support/non_active_record/something_else.rb +2 -0
  56. data/spec/support/ruby_parser_exception_causing_string.rb +29 -29
  57. data/spec/unit/collation_spec.rb +9 -10
  58. data/spec/unit/file_writer_spec.rb +4 -8
  59. data/spec/unit/finders/factory_spec.rb +7 -9
  60. data/spec/unit/finders/model_spec.rb +35 -8
  61. data/spec/unit/generation/attribute_spec.rb +22 -22
  62. data/spec/unit/generation/factory_spec.rb +38 -14
  63. data/spec/unit/parsing/file_spec.rb +9 -9
  64. data/spec/unit/parsing/klass_inference_spec.rb +5 -7
  65. data/to_factory.gemspec +17 -15
  66. metadata +109 -44
  67. data/.travis.yml +0 -14
  68. data/lib/to_factory/parsing/syntax.rb +0 -83
@@ -1,30 +1,31 @@
1
1
  describe ToFactory do
2
2
  let!(:user) { create_user! }
3
- let!(:project) { create_project!}
4
-
5
- before { FileUtils.rm_rf "./tmp/factories" }
3
+ let!(:project) { create_project! }
6
4
 
7
5
  def user_file
8
- File.read("./tmp/factories/to_factory/user.rb") rescue nil
6
+ File.read("./tmp/factories/to_factory/user.rb")
7
+ rescue
8
+ nil
9
9
  end
10
10
 
11
11
  def project_file
12
- File.read("./tmp/factories/to_factory/project.rb") rescue nil
12
+ File.read("./tmp/factories/to_factory/project.rb")
13
+ rescue
14
+ nil
13
15
  end
14
16
 
15
- let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb"}
16
- 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" }
17
19
 
18
20
  describe "ToFactory.definitions" do
19
21
  it do
20
22
  ToFactory()
21
23
  expect(ToFactory.definitions).to match_array ["to_factory/user", "to_factory/project"]
22
24
  end
23
-
24
25
  end
25
26
 
26
27
  describe "ToFactory.definition_for" do
27
- let(:expected_user_file) { File.read "./spec/example_factories/user.rb"}
28
+ let(:expected_user_file) { File.read "./spec/example_factories/user.rb" }
28
29
  it do
29
30
  expect(ToFactory.definition_for user).to match_sexp expected_user_file
30
31
  end
@@ -35,35 +36,35 @@ describe ToFactory do
35
36
  end
36
37
 
37
38
  it "raises a not found error" do
38
- 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
39
40
  end
40
41
  end
41
42
 
42
43
  describe "Object#ToFactory" do
43
44
  context "with multiple levels of parent classes" do
44
- let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb"}
45
+ let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb" }
45
46
 
46
47
  it "gets the output order correct" do
47
48
  output = "./tmp/factories/to_factory/user.rb"
48
49
  `mkdir -p ./tmp/factories/to_factory`
49
50
  `cp #{filename} #{output}`
50
51
 
51
- ToFactory(:root => user)
52
+ ToFactory(root: user)
52
53
 
53
54
  expected = File.read "spec/example_factories/#{'user_admin_root'}.rb"
54
55
 
55
- #user, admin, super_admin, root
56
+ # user, admin, super_admin, root
56
57
  expect(File.read(output)).to match_sexp expected
57
58
  end
58
59
  end
59
60
 
60
61
  it "generates all factories" do
61
62
  ToFactory()
62
- #simple check for equivalent ruby
63
+ # simple check for equivalent ruby
63
64
  expect(user_file) .to match_sexp expected_user_file
64
65
  expect(project_file).to match_sexp expected_project_file
65
66
 
66
- #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
67
68
  expect(user_file.chomp) .to eq expected_user_file.chomp
68
69
  expect(project_file.chomp).to eq expected_project_file.chomp
69
70
  end
@@ -79,13 +80,13 @@ describe ToFactory do
79
80
  end
80
81
 
81
82
  it "ignores specified classes" do
82
- ToFactory(:exclude => ToFactory::User)
83
+ ToFactory(exclude: ToFactory::User)
83
84
  expect(user_file).to be_nil
84
85
  expect(project_file).to be_present
85
86
  end
86
87
 
87
88
  it "ignores specified classes - sanity check" do
88
- ToFactory(:exclude => ToFactory::Project)
89
+ ToFactory(exclude: ToFactory::Project)
89
90
  expect(user_file).to be_present
90
91
  expect(project_file).to be_nil
91
92
  end
@@ -117,14 +118,14 @@ describe ToFactory do
117
118
  context "with a name for the factory" do
118
119
  it "appends to the file" do
119
120
  user_file_includes('factory(:"to_factory/user"')
120
- ToFactory(:specific_user => user)
121
+ ToFactory(specific_user: user)
121
122
  user_file_includes('factory(:specific_user, :parent => :"to_factory/user"')
122
123
  end
123
124
  end
124
125
 
125
126
  it "without a name" do
126
- expect(lambda{ToFactory(user)}).
127
- to raise_error ToFactory::AlreadyExists
127
+ expect { ToFactory(user) }
128
+ .to raise_error ToFactory::AlreadyExists
128
129
  end
129
130
  end
130
131
  end
data/spec/spec_helper.rb CHANGED
@@ -1,26 +1,17 @@
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
 
14
- begin
15
- require "pry-byebug"
16
- rescue LoadError
17
- begin
18
- require "ruby-debug"
19
- rescue LoadError
20
- $stderr.puts "No debugger available for #{RUBY_VERSION}"
21
- end
22
- end
23
-
14
+ require "byebug"
24
15
  require "to_factory"
25
16
 
26
17
  require "./spec/support/models/user"
@@ -33,8 +24,8 @@ RSpec.configure do |config|
33
24
 
34
25
  config.before :suite do
35
26
  ActiveRecord::Base.tap do |base|
36
- config = {:adapter => "sqlite3", :database => "spec/db/test.sqlite3"}
37
- base.configurations = {:test => config}.with_indifferent_access
27
+ config = { adapter: "sqlite3", database: "spec/db/test.sqlite3" }
28
+ base.configurations = { test: config }.with_indifferent_access
38
29
  base.establish_connection :test
39
30
  end
40
31
 
@@ -0,0 +1 @@
1
+ class Egg < ActiveRecord::Base
@@ -0,0 +1,3 @@
1
+ class ToFactory::Project < ActiveRecord::Base
2
+ self.table_name = "projects"
3
+ end
@@ -5,7 +5,7 @@ module ToFactory::DataCreation
5
5
  end
6
6
 
7
7
  def create_project!
8
- ToFactory::Project.create({:name => "My Project", :objective => "easy testing", :some_id => 9 })
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
- :name => "Jeff",
18
- :email => "test@example.com",
19
- :some_attributes => {:a => 1},
20
- :some_id => 8,
21
- :birthday => birthday
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
- :name => "Admin",
28
- :email => "admin@example.com",
29
- :some_attributes => {:a => 1},
30
- :some_id => 9,
31
- :birthday => birthday
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
-
@@ -8,7 +8,6 @@ RSpec::Matchers.define :match_sexp do |expected|
8
8
  @raised = e
9
9
  false
10
10
  end
11
-
12
11
  end
13
12
 
14
13
  failure_message do |actual|
@@ -0,0 +1,3 @@
1
+ class ToFactory::InheritedProject < ToFactory::Project
2
+ self.table_name = "projects"
3
+ end
@@ -0,0 +1,3 @@
1
+ class ToFactory::Project < ActiveRecord::Base
2
+ self.table_name = "projects"
3
+ end
@@ -0,0 +1,4 @@
1
+ require_relative "something_else"
2
+
3
+ class SomeOtherService < SomethingElse
4
+ end
@@ -0,0 +1,2 @@
1
+ class SomeService
2
+ end
@@ -0,0 +1,2 @@
1
+ class SomethingElse
2
+ end
@@ -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
  \ "
@@ -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(:name => "a")]}
5
- let(:b) { [double(:name => "a")]}
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(lambda{perform}).to raise_error ToFactory::AlreadyExists
12
+ expect { perform }.to raise_error ToFactory::AlreadyExists
13
13
  end
14
14
 
15
15
  context "non matching keys" do
16
- let(:a) { [double(:name => "a")]}
17
- let(:b) { [double(:name => "b")]}
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 = [ root ]
33
- pre_existing = [ admin, user, super_admin ]
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 :name => "project", :definition =>"factory b"
16
- fw.write({"to_factory/user" =>[user_representation],
17
- "to_factory/project" => [project_representation]
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 /FactoryGirl.define do/
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
- "./tmp/factories/to_factory/user.rb"
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
-
@@ -4,10 +4,17 @@ describe ToFactory::Finders::Model do
4
4
  end
5
5
 
6
6
  let(:finder) { ToFactory::Finders::Model.new }
7
+ let(:path) { "./spec/support/models" }
7
8
 
8
9
  describe "#call" do
9
- let!(:user) { ToFactory::User.create! :name => "a user"}
10
- let!(:project) { ToFactory::Project.create! :name => "a project"}
10
+ let!(:user) { ToFactory::User.create! name: "a user" }
11
+ let!(:project) { ToFactory::Project.create! name: "a project" }
12
+
13
+ context "with a match" do
14
+ it do
15
+ expect(finder.call).to match_array [user, project]
16
+ end
17
+ end
11
18
 
12
19
  context "no match"do
13
20
  let(:path) { "./tmp/doesnt_exist" }
@@ -15,14 +22,34 @@ describe ToFactory::Finders::Model do
15
22
  expect(finder.call).to eq []
16
23
  end
17
24
  end
18
- context "with a match" do
19
- let(:path) { "./spec/support/models" }
20
- it do
21
- expect(finder.call).to match_array [user, project]
25
+
26
+ context "with an invalid model file" do
27
+ let(:path) { "./spec/support/broken_models" }
28
+ before do
29
+ allow(finder).to receive(:warn)
30
+ end
31
+
32
+ it "displays a warning" do
33
+ expect(finder.call).to eq [project]
34
+
35
+ expect(finder).to have_received(:warn)
36
+ .with("Failed to eval ./spec/support/broken_models/invalid_ruby_file.rb")
22
37
  end
23
38
  end
24
- end
25
39
 
26
- end
40
+ context "with an invalid class" do
41
+ before do
42
+ allow(finder).to receive(:warn)
43
+ end
27
44
 
45
+ it "displays a warning" do
46
+ klass = double("BrokenClass", inspect: "BrokenClass")
47
+ expect(klass).to receive(:ancestors).and_raise("Some error")
48
+ finder.call(klasses: [klass])
28
49
 
50
+ expect(finder).to have_received(:warn)
51
+ .with("Failed to get record from BrokenClass \"Some error\"")
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,16 +1,16 @@
1
1
  describe ToFactory::Generation::Attribute do
2
- let(:attribute) { ToFactory::Generation::Attribute.new(:some_attributes, {:a => 1}) }
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({:a => 1})"
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
@@ -21,20 +21,33 @@ describe ToFactory::Generation::Attribute do
21
21
  expect(attribute.format(123)) .to eq "123"
22
22
  expect(attribute.format(123.0)).to eq "123.0"
23
23
  end
24
- end
25
24
 
25
+ it "formats BigDecimal"do
26
+ expect(attribute.format(BigDecimal "123456789012345678900.0")).to eq "BigDecimal.new(\"123456789012345678900.0\")"
27
+ end
28
+
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
32
+ parser = double "RubyParser"
33
+ expect(parser).to receive(:parse).and_raise "some error"
34
+ attribute.parser = parser
35
+
36
+ expect(attribute.format("anything")).to eq "ToFactory: RubyParser exception parsing this attribute".inspect
37
+ end
38
+ end
26
39
 
27
40
  describe "#inspect_value" do
28
41
  it do
29
- expect(attribute.inspect_value({:a => 1})).to eq "({:a => 1})"
42
+ expect(attribute.inspect_value(a: 1)).to eq " { {:a => 1} }"
30
43
  end
31
44
  it "formats hashes correctly" do
32
45
  hash = ActiveSupport::OrderedHash.new
33
- hash[{"with" => :hash}] = "keys"
46
+ hash[{ "with" => :hash }] = "keys"
34
47
  hash[2] = "integers"
35
- hash[:a] = {:nested => "hash"}
48
+ hash[:a] = { nested: "hash" }
36
49
 
37
- expected = '({{"with" => :hash} => "keys", 2 => "integers", :a => {:nested => "hash"}})'
50
+ expected = ' { {{"with" => :hash} => "keys", 2 => "integers", :a => {:nested => "hash"}} }'
38
51
 
39
52
  expect(attribute.inspect_value(hash)).to eq expected
40
53
  end
@@ -46,17 +59,4 @@ describe ToFactory::Generation::Attribute do
46
59
  expect(attribute.format(input, false)).to eq expected
47
60
  end
48
61
  end
49
-
50
- if RUBY_VERSION =~ /\A1\.8/
51
- it "alters attributes that are unparseable by RubyParser" do
52
- #when reparsing the generated files, we don't want the parser itself
53
- #to raise an exception, rather than fix RubyParser now, a hotfix is to
54
- #warn about these attributes and replace them with something parseable
55
- value = File.read("./spec/support/ruby_parser_exception_causing_string.rb")
56
- expect(lambda{RubyParser.new.parse(value)}).to raise_error StringScanner::Error
57
- result = attribute.inspect_value(value)
58
- expect(lambda{RubyParser.new.parse(result)}).not_to raise_error
59
- expect(result).to match /ToFactory: RubyParser exception/
60
- end
61
- end
62
62
  end
@@ -11,13 +11,37 @@ 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
+ describe "#name" do
17
+ context "with a simple name" do
18
+ let(:representation) { double "Representation", name: "some_name" }
16
19
 
20
+ it "adds just displays the name" do
21
+ expect(generator.name).to eq "some_name"
22
+ end
23
+ end
24
+
25
+ context "with a namespace" do
26
+ let(:representation) { double "Representation", name: "some_namespace/some_name" }
27
+
28
+ it "adds quotes to the name" do
29
+ expect(generator.name).to eq "some_namespace/some_name".inspect
30
+ end
31
+ end
32
+
33
+ context "with a an already quoted name in a namespace" do
34
+ let(:representation) { double "Representation", name: "some_namespace/some_name".inspect }
35
+
36
+ it "doesn't add extra adds quotes to the name" do
37
+ expect(generator.name).to eq "some_namespace/some_name".inspect
38
+ end
39
+ end
40
+ end
17
41
 
18
42
  describe "#header" do
19
43
  it do
20
- expect(generator.header{}).to match_sexp <<-eof.strip_heredoc
44
+ expect(generator.header {}).to match_sexp <<-eof.strip_heredoc
21
45
  factory(:"to_factory/user") do
22
46
  end
23
47
  eof
@@ -26,27 +50,27 @@ describe ToFactory::Generation::Factory do
26
50
 
27
51
  describe "#attributes" do
28
52
  let(:representation) do
29
- double(:attributes => {"something" => "something",
30
- :id => 123,
31
- :created_at => anything,
32
- :created_on => anything,
33
- :updated_at => anything,
34
- :updated_on => anything,
35
- nil => nil})
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 })
36
60
  end
37
61
  it "ignores blank keys, :id, :created_at, :updated_at, :created_on, :updated_on" do
38
- expect(generator.attributes).to eq({"something" => "something"})
62
+ expect(generator.attributes).to eq("something" => "something")
39
63
  end
40
64
  end
41
65
  describe "#factory_attribute" do
42
66
  it do
43
- expect(generator.factory_attribute(:name, nil)) .to eq ' name nil'
44
- expect(generator.factory_attribute(:name, "Jeff")).to eq ' name "Jeff"'
45
- expect(generator.factory_attribute(:id, 8)) .to eq ' id 8'
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 }"
46
70
  end
47
71
  it "generates usable datetime strings" do
48
72
  output = generator.factory_attribute(:birthday, birthday)
49
- expect(output).to eq ' birthday "2014-07-08T15:30 UTC"'
73
+ expect(output).to eq ' birthday { "2014-07-08T15:30 UTC" }'
50
74
  end
51
75
  end
52
76