faker_maker 2.1.2 → 4.0.0.beta1

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +13 -14
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +4 -3
  5. data/Gemfile +6 -0
  6. data/README.md +7 -1
  7. data/lib/faker_maker/attribute.rb +10 -1
  8. data/lib/faker_maker/factory.rb +122 -36
  9. data/lib/faker_maker/version.rb +1 -1
  10. data/lib/faker_maker.rb +1 -1
  11. data/usefakermaker.com/.gitignore +5 -0
  12. data/usefakermaker.com/404.html +25 -0
  13. data/usefakermaker.com/Gemfile +39 -0
  14. data/usefakermaker.com/README.md +5 -0
  15. data/usefakermaker.com/_config.yml +299 -0
  16. data/usefakermaker.com/_config.yml.orig +55 -0
  17. data/usefakermaker.com/_data/navigation.yml +51 -0
  18. data/usefakermaker.com/_data/ui-text.yml +2132 -0
  19. data/usefakermaker.com/_site/assets/css/main.css.map +1 -1
  20. data/usefakermaker.com/_site/assets/js/lunr/lunr-store.js +1 -10
  21. data/usefakermaker.com/_site/feed.xml +1 -17
  22. data/usefakermaker.com/_site/sitemap.xml +0 -10
  23. data/usefakermaker.com/about.markdown +18 -0
  24. data/usefakermaker.com/docs/contributing/index.md +7 -0
  25. data/{docs/installation.md → usefakermaker.com/docs/installing/index.md} +3 -5
  26. data/{docs/usage/arrays.md → usefakermaker.com/docs/usage/arrays/index.md} +2 -6
  27. data/{docs/usage/building_instances.md → usefakermaker.com/docs/usage/building-instances/index.md} +10 -12
  28. data/{docs/usage/chaos.md → usefakermaker.com/docs/usage/chaos/index.md} +6 -10
  29. data/{docs/usage/destroying_factories.md → usefakermaker.com/docs/usage/destroying-factories/index.md} +7 -9
  30. data/{docs/usage/embedding_factories.md → usefakermaker.com/docs/usage/embedding-factories/index.md} +42 -9
  31. data/{docs/usage → usefakermaker.com/docs/usage/getting-started}/index.md +12 -15
  32. data/{docs/usage/audit_logs.md → usefakermaker.com/docs/usage/history-logging/index.md} +4 -4
  33. data/{docs/usage/inheritance.md → usefakermaker.com/docs/usage/inheritance/index.md} +7 -9
  34. data/{docs/usage/json_field_names.md → usefakermaker.com/docs/usage/json-field-names/index.md} +2 -6
  35. data/{docs/usage/lifecycle_hooks.md → usefakermaker.com/docs/usage/lifecycle-hooks/index.md} +3 -7
  36. data/{docs/usage/dependencies.md → usefakermaker.com/docs/usage/managing-dependencies/index.md} +2 -6
  37. data/{docs/usage/omitting_fields copy.md → usefakermaker.com/docs/usage/omitting-fields/index.md} +4 -8
  38. data/usefakermaker.com/pages/about/index.md +20 -0
  39. data/usefakermaker.com/pages/index.markdown +27 -0
  40. metadata +30 -32
  41. data/docs/.bundle/config +0 -2
  42. data/docs/.keep +0 -1
  43. data/docs/_config.yml +0 -8
  44. data/docs/contributing.md +0 -9
  45. data/docs/credits.md +0 -9
  46. data/docs/index.md +0 -21
  47. data/docs/logo.png +0 -0
  48. data/usefakermaker.com/_site/404.html +0 -213
  49. data/usefakermaker.com/_site/about/index.html +0 -10
  50. data/usefakermaker.com/_site/index.html +0 -258
  51. data/usefakermaker.com/_site/jekyll/update/welcome-to-jekyll/index.html +0 -18
  52. /data/usefakermaker.com/{_site/assets → assets}/images/pug.png +0 -0
  53. /data/usefakermaker.com/{_site/assets → assets}/images/unipug.svg +0 -0
@@ -1,10 +1 @@
1
- var store = [{
2
- "title": "Welcome to Jekyll!",
3
- "excerpt":"You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated. Jekyll requires blog post files to be named according to the following format: YEAR-MONTH-DAY-title.MARKUP Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers, and MARKUP is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works. Jekyll also offers powerful support for code snippets: def print_hi(name) puts \"Hi, #{name}\" end print_hi('Tom') #=> prints 'Hi, Tom' to STDOUT. Check out the Jekyll docs for more info on how to get the most out of Jekyll. File all bugs/feature requests at Jekyll’s GitHub repo. If you have questions, you can ask them on Jekyll Talk. ","categories": ["jekyll","update"],
4
- "tags": [],
5
- "url": "/jekyll/update/welcome-to-jekyll/",
6
- "teaser": null
7
- },{
8
- "title": "About",
9
- "excerpt":"This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at jekyllrb.com You can find the source code for Minima at GitHub: jekyll / minima You can find the source code for Jekyll at GitHub: jekyll / jekyll ","url": "http://localhost:4000/about/"
10
- }]
1
+ var store = [,]
@@ -1,17 +1 @@
1
- <?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2024-10-14T16:53:17+01:00</updated><id>http://localhost:4000/feed.xml</id><title type="html">Faker Maker</title><subtitle>Factories over fixtures: cook your test data from fresh</subtitle><author><name>Nigel Brookes-Thomas (Billy Ruffian)</name></author><entry><title type="html">Welcome to Jekyll!</title><link href="http://localhost:4000/jekyll/update/welcome-to-jekyll/" rel="alternate" type="text/html" title="Welcome to Jekyll!" /><published>2024-10-14T13:56:50+01:00</published><updated>2024-10-14T13:56:50+01:00</updated><id>http://localhost:4000/jekyll/update/welcome-to-jekyll</id><content type="html" xml:base="http://localhost:4000/jekyll/update/welcome-to-jekyll/"><![CDATA[<p>You’ll find this post in your <code class="language-plaintext highlighter-rouge">_posts</code> directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run <code class="language-plaintext highlighter-rouge">jekyll serve</code>, which launches a web server and auto-regenerates your site when a file is updated.</p>
2
-
3
- <p>Jekyll requires blog post files to be named according to the following format:</p>
4
-
5
- <p><code class="language-plaintext highlighter-rouge">YEAR-MONTH-DAY-title.MARKUP</code></p>
6
-
7
- <p>Where <code class="language-plaintext highlighter-rouge">YEAR</code> is a four-digit number, <code class="language-plaintext highlighter-rouge">MONTH</code> and <code class="language-plaintext highlighter-rouge">DAY</code> are both two-digit numbers, and <code class="language-plaintext highlighter-rouge">MARKUP</code> is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.</p>
8
-
9
- <p>Jekyll also offers powerful support for code snippets:</p>
10
-
11
- <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">def</span> <span class="nf">print_hi</span><span class="p">(</span><span class="nb">name</span><span class="p">)</span>
12
- <span class="nb">puts</span> <span class="s2">"Hi, </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span>
13
- <span class="k">end</span>
14
- <span class="n">print_hi</span><span class="p">(</span><span class="s1">'Tom'</span><span class="p">)</span>
15
- <span class="c1">#=&gt; prints 'Hi, Tom' to STDOUT.</span></code></pre></figure>
16
-
17
- <p>Check out the <a href="https://jekyllrb.com/docs/home">Jekyll docs</a> for more info on how to get the most out of Jekyll. File all bugs/feature requests at <a href="https://github.com/jekyll/jekyll">Jekyll’s GitHub repo</a>. If you have questions, you can ask them on <a href="https://talk.jekyllrb.com/">Jekyll Talk</a>.</p>]]></content><author><name>Nigel Brookes-Thomas (Billy Ruffian)</name></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.]]></summary></entry></feed>
1
+ <?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2025-01-16T09:57:40+00:00</updated><id>http://localhost:4000/feed.xml</id><title type="html">Faker Maker</title><subtitle>Factories over fixtures: cook your test data from fresh</subtitle><author><name>Nigel Brookes-Thomas (Billy Ruffian)</name></author></feed>
@@ -1,13 +1,3 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
- <url>
4
- <loc>http://localhost:4000/jekyll/update/welcome-to-jekyll/</loc>
5
- <lastmod>2024-10-14T13:56:50+01:00</lastmod>
6
- </url>
7
- <url>
8
- <loc>http://localhost:4000/about/</loc>
9
- </url>
10
- <url>
11
- <loc>http://localhost:4000/</loc>
12
- </url>
13
3
  </urlset>
@@ -0,0 +1,18 @@
1
+ ---
2
+ layout: page
3
+ title: About
4
+ permalink: /about/
5
+ ---
6
+
7
+ This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at [jekyllrb.com](https://jekyllrb.com/)
8
+
9
+ You can find the source code for Minima at GitHub:
10
+ [jekyll][jekyll-organization] /
11
+ [minima](https://github.com/jekyll/minima)
12
+
13
+ You can find the source code for Jekyll at GitHub:
14
+ [jekyll][jekyll-organization] /
15
+ [jekyll](https://github.com/jekyll/jekyll)
16
+
17
+
18
+ [jekyll-organization]: https://github.com/jekyll
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: single
3
+ title: Contributing
4
+ nav_order: 2
5
+ ---
6
+
7
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/BillyRuffian/faker_maker>
@@ -1,11 +1,9 @@
1
1
  ---
2
- layout: default
3
- title: Installation
2
+ layout: single
3
+ title: Installing Faker Maker
4
4
  nav_order: 2
5
5
  ---
6
6
 
7
- # Installation
8
-
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
@@ -18,4 +16,4 @@ And then execute:
18
16
 
19
17
  Or install it yourself as:
20
18
 
21
- $ gem install faker_maker
19
+ $ gem install faker_maker
@@ -1,12 +1,8 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Arrays
4
- parent: Usage
5
- nav_order: 2
6
4
  ---
7
5
 
8
- # Arrays
9
-
10
6
  It is possible to declare an attribute as having multiple values.
11
7
 
12
8
  ```ruby
@@ -41,4 +37,4 @@ FakerMaker.factory :basket do
41
37
  Faker::Commerce.product_name
42
38
  end
43
39
  end
44
- ```
40
+ ```
@@ -1,13 +1,9 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Building Instances
4
- parent: Usage
5
- nav_order: 6
6
4
  ---
7
5
 
8
- # Building Instances
9
-
10
- Instances are Plain Ol' Ruby Objects and the attributes are attached with getters and setters with their values assigned to the value return from their block at build time.
6
+ Instances are Plain Ol' Ruby Objects and the attributes are attached with getters and setters with their values assigned to the value return from their block at build time.
11
7
 
12
8
  To build an object:
13
9
 
@@ -15,12 +11,12 @@ To build an object:
15
11
  result = FakerMaker[:basket].build
16
12
  ```
17
13
 
18
- will generate a new instance using the Basket factory. Because an actual class is defined, you can instantiate an object directly through `Basket.new` but that will not populate any of the attributes.
14
+ will generate a new instance using the Basket factory. Because an actual class is defined (since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace), you can instantiate an object directly through `Basket.new` but that will not populate any of the attributes.
19
15
 
20
- It's possible to override attributes at build-time, either by passing values as a hash:
16
+ It's possible to override attributes at build-time, either by passing values as a hash (preferred):
21
17
 
22
18
  ```ruby
23
- result = FakerMaker[:item].build( name: 'Electric Blanket' )
19
+ result = FakerMaker[:item].build( attributes: { name: 'Electric Blanket' } )
24
20
  ```
25
21
 
26
22
  or by passing in a block:
@@ -32,7 +28,7 @@ result = FakerMaker[:item].build{ |i| i.name = 'Electric Sheep' }
32
28
  this is particularly useful for overriding nested values, since all the getters and setters of the embedded objects are already constructed:
33
29
 
34
30
  ```ruby
35
- result = FakerMaker[:basket].build do |b|
31
+ result = FakerMaker[:basket].build do |b|
36
32
  b.items.first.name = 'Neon Badger'
37
33
  end
38
34
  ```
@@ -40,7 +36,7 @@ end
40
36
  if you're crazy enough to want to do both styles during creation, the values in the block will be preserved, e.g.
41
37
 
42
38
  ```ruby
43
- result = FakerMaker[:item].build( name: 'Electric Blanket' ) do |i|
39
+ result = FakerMaker[:item].build( attributes: { name: 'Electric Blanket' } ) do |i|
44
40
  i.name = 'Electric Sheep'
45
41
  end
46
42
  ```
@@ -61,4 +57,6 @@ As another convenience, `FakerMaker` is also assigned to the variable `FM` to it
61
57
 
62
58
  ```ruby
63
59
  result = FM[:basket].build
64
- ```
60
+ ```
61
+
62
+ **For more complex instance building with embedded factories, see [Embedding Factories](docs/usage/embedding-factories/).**
@@ -1,17 +1,13 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Chaos
4
- parent: Usage
5
- nav_order: 11
6
4
  ---
7
5
 
8
- # Chaos
6
+ Chaos mode introduces extra spice to your generated factories.
9
7
 
10
- Chaos mode introduces extra spice to your generated factories.
8
+ Attributes can be marked as either `required` or `optional`, which Chaos will use to determine what attributes are included when instantiating your factory.
11
9
 
12
- Attributes can be marked as either `required` or `optional`, which Chaos will use to determine what attributes are included when instantiating your factory.
13
-
14
- Required attributes will always be present, however, optional attributes are not guaranteed to be present when Chaos is enabled.
10
+ Required attributes will always be present, however, optional attributes are not guaranteed to be present when Chaos is enabled.
15
11
 
16
12
  *All attributes are optional by default.*
17
13
 
@@ -26,11 +22,11 @@ FM.factory :item, naming: :json do
26
22
  end
27
23
  ```
28
24
 
29
- You can state an attribute is optional using the `optional` option set to either be a `Boolean`, `Integer` or a `Float`.
25
+ You can state an attribute is optional using the `optional` option set to either be a `Boolean`, `Integer` or a `Float`.
30
26
 
31
27
  When optional is set to either an `Integer` or a `Float`, this overrides the weighting which Chaos uses to determine the likelihood that attribute will be removed.
32
28
 
33
- Higher the value, the more likely that attribute will be present. By default there's a 50/50 chance an optional attribute will be present.
29
+ Higher the value, the more likely that attribute will be present. By default there's a 50/50 chance an optional attribute will be present.
34
30
 
35
31
  To unleash Chaos over a factory, you need to enable it when instantiating your object:
36
32
 
@@ -1,13 +1,11 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Destroying Factories
4
- parent: Usage
5
- nav_order: 9
6
4
  ---
7
5
 
8
6
  ## A Cautionary Tale
9
7
 
10
- If you think you want to do this, you are probably wrong. This will not only de-register the factory from Faker Maker, but also delete the class definition from the interpreter. While it's cool that Ruby allows this, it's almost certainly going to hurt.
8
+ If you think you want to do this, you are probably wrong. This will not only de-register the factory from Faker Maker, but also delete the class definition from the interpreter. While it's cool that Ruby allows this, it's almost certainly going to hurt.
11
9
 
12
10
  This functionality exists for experimenting with factories in REPLs.
13
11
 
@@ -20,11 +18,11 @@ Faker Maker deliberately does not allow you to redefine a factory by redeclaring
20
18
  For example, this might give you unexpected behavior:
21
19
 
22
20
  ```ruby
23
- FakerMaker.factory :user do
21
+ FakerMaker.factory :user do
24
22
  name {'Patsy Stone'}
25
23
  end
26
24
 
27
- FakerMaker.factory :user do
25
+ FakerMaker.factory :user do
28
26
  name {'Patsy Stone'}
29
27
  email {'patsy@fabulous.co.uk'}
30
28
  end
@@ -36,13 +34,13 @@ FM[:user].as_json
36
34
  On the other hand, sometimes you really, really want to destroy a factory and start again (especially if you are experimenting in a REPL for example). FakerMaker allows you to shut a factory which will de-register it from the list of available factories and attempt to unload the class it has built from the Ruby interpreter.
37
35
 
38
36
  ```ruby
39
- FakerMaker.factory :user do
37
+ FakerMaker.factory :user do
40
38
  name {'Patsy Stone'}
41
39
  end
42
40
 
43
41
  FakerMaker.shut!(:user)
44
42
 
45
- FakerMaker.factory :user do
43
+ FakerMaker.factory :user do
46
44
  name {'Patsy Stone'}
47
45
  email {'patsy@fabulous.co.uk'}
48
46
  end
@@ -50,5 +48,5 @@ end
50
48
  FM[:user].as_json
51
49
  => {:name=>"Patsy Stone", :email=>"patsy@fabulous.co.uk"}
52
50
  ```
53
-
51
+
54
52
  It also provides the `shut_all!` method to remove all factories.
@@ -1,12 +1,8 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Embedding Factories
4
- parent: Usage
5
- nav_order: 8
6
4
  ---
7
5
 
8
- # Embedding Factories
9
-
10
6
  To use factories with factories, the following pattern is recommended:
11
7
 
12
8
  ```ruby
@@ -35,11 +31,11 @@ FakerMaker.factory :item do
35
31
  end
36
32
 
37
33
  FakerMaker.factory :basket do
38
- items( has: 10, factory: [:item, :discount] )
34
+ items( has: 10, factory: [:item, :coupon] ) # either `item` or `coupon` will be randomly selected for each member
39
35
  end
40
36
  ```
41
37
 
42
- In this example, through 10 iterations, one of `item` and `discount` factories will be called to build their objects.
38
+ In this example, through 10 iterations, a random choice of `item` and `discount` factories will be called to build their objects.
43
39
 
44
40
  Blocks can still be provided and the referenced factory built object will be passed to the block:
45
41
 
@@ -53,11 +49,48 @@ FakerMaker.factory :basket do
53
49
  items( has: 10, factory: :item ) { |item| item.price = 10.99 ; item}
54
50
  end
55
51
  ```
52
+
53
+ ## Overriding values for nested factories in the enclosing factory
54
+
56
55
  **Important:** the value for the attribute will be the value returned from the block. If you want to modify the contents of the referenced factory's object, don't forget to return it at the end of the block (as above).
57
56
 
57
+ ## Overriding values for nested factories during build
58
+
59
+ If we look carefully at this factory
60
+
61
+ ```ruby
62
+ FakerMaker.factory :inventory do
63
+ item( factory: :item )
64
+ quantity { 10 }
65
+ end
66
+ ```
67
+
68
+ This will build a object of the form (in its `as_json` guise):
69
+
70
+ ```ruby
71
+ {item: {name: "toothpaste", price: 0.99}, quantity: 10}
72
+ ```
73
+
74
+ When it comes to overriding values at build time, a hash can be passed to set the nested values:
75
+
76
+ ```ruby
77
+ FM[:inventory].build( attributes: { item: { name: 'floor cleaner' } } )
78
+ ```
79
+
80
+ When you allow Faker Maker to make a choice of factory by giving it an array:
81
+
82
+ ```ruby
83
+ FakerMaker.factory :inventory do
84
+ item( factory: [:item, :coupon] )
85
+ quantity { 10 }
86
+ end
87
+ ```
88
+
89
+ ...either the `item` or `coupon` fields could be added to each build of the `inventory` factory. Faker Maker will ignore any fields for the non-chosen factory if they are paseed in the overrides hash. This means that a `NoSuchAttribute` error will not be raised.
90
+
58
91
  ## Alternative method
59
92
 
60
- There is an alternative style which might be of use:
93
+ There is an alternative style which might be of use, **but** you have less control using build-time overrides for values (you can't set nested values). *This is no longer a recommended pattern*.
61
94
 
62
95
  ```ruby
63
96
  FakerMaker.factory :item do
@@ -70,4 +103,4 @@ FakerMaker.factory :basket do
70
103
  end
71
104
  ```
72
105
 
73
- With this pattern, you might have to [manage your dependencies]({% link usage/dependencies.md %}) and `require` your referenced factory.
106
+ With this pattern, you might have to [manage your dependencies](../managing-dependencies/) and `require` your referenced factory.
@@ -1,40 +1,37 @@
1
1
  ---
2
- layout: default
3
- title: Usage
4
- nav_order: 3
5
- has_children: true
2
+ layout: single
3
+ title: Getting started
6
4
  ---
7
5
 
8
- # Usage
9
-
10
6
  FakerMaker generates factories that build disposable objects for testing. Each factory has a name and a set of attributes.
11
7
 
12
8
  ```ruby
13
- FakerMaker.factory :user do
9
+ FakerMaker.factory :user do
14
10
  name {'Patsy Stone'}
15
11
  email {'patsy@fabulous.co.uk'}
16
12
  admin {false}
17
13
  end
18
14
  ```
19
15
 
20
- This will generate a `User` class with the attributes `name`, `email` and `admin` which will always return the same value.
16
+ This will generate a `FakerMaker::Factory::User` class with the attributes `name`, `email` and `admin` which will always return the same value.
17
+ Since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace.
21
18
 
22
- It is possible to explicitly set the name of class which is particularly useful if there is a risk of redefining an existing one.
19
+ It is possible to explicitly set the name of class which is particularly useful if there is a risk of redefining an existing one. Classes will **always** be created within the `FakerMaker::Factory` namespace (since v3.0.0)
23
20
 
24
21
  ```ruby
25
- FakerMaker.factory :user, class: 'EmailUser' do
22
+ FakerMaker.factory :user, class: 'EmailUser' do
26
23
  name {'Patsy Stone'}
27
24
  email {'patsy@fabulous.co.uk'}
28
25
  admin {false}
29
26
  end
30
27
  ```
31
28
 
32
- The class name will always be turned into a Ruby-style class name so `email_user` would become `EmailUser`.
29
+ The class name will always be turned into a Ruby-style class name so `email_user` would become `FakerMaker::Factory::EmailUser`.
33
30
 
34
31
  Because of the block syntax in Ruby, defining attributes as `Hash`es requires two sets of curly brackets:
35
32
 
36
33
  ```ruby
37
- FakerMaker.factory :response do
34
+ FakerMaker.factory :response do
38
35
  body { { title: 'First Post', content: 'This is part of a hash' } }
39
36
  end
40
37
  ```
@@ -42,7 +39,7 @@ end
42
39
  Blocks are executed in the context of their instance. This means you can refer to variables already defined:
43
40
 
44
41
  ```ruby
45
- FakerMaker.factory :user, class: 'EmailUser' do
42
+ FakerMaker.factory :user, class: 'EmailUser' do
46
43
  title {'Ms'}
47
44
  name {'Patsy Stone'}
48
45
  formal_name {"#{title} #{name}"}
@@ -54,10 +51,10 @@ end
54
51
  Fields with no block (or reference to another factory) will be nil.
55
52
 
56
53
  ```ruby
57
- FakerMaker.factory :request do
54
+ FakerMaker.factory :request do
58
55
  body
59
56
  end
60
57
 
61
58
  FakerMaker[:request].build.body
62
59
  # => nil
63
- ```
60
+ ```
@@ -1,6 +1,6 @@
1
1
  ---
2
- layout: default
3
- title: Audit (History) Logs
2
+ layout: single
3
+ title: History logging
4
4
  parent: Usage
5
5
  nav_order: 10
6
6
  ---
@@ -33,7 +33,7 @@ Immediately after each object is built and after the post-build hooks have compl
33
33
  For example, given the factory:
34
34
 
35
35
  ```ruby
36
- FakerMaker.factory :user do
36
+ FakerMaker.factory :user do
37
37
  name {'Patsy Stone'}
38
38
  email {'patsy@fabulous.co.uk'}
39
39
  admin {false}
@@ -44,4 +44,4 @@ The audit log, on build, would look like:
44
44
 
45
45
  ```
46
46
  {"timestamp":"2023-05-15T15:46:30+01:00","factory":"user","class":"User","body":{"name":"Patsy Stone","email":"patsy@fabulous.co.uk","admin":false}}
47
- ```
47
+ ```
@@ -1,12 +1,8 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Inheritance
4
- parent: Usage
5
- nav_order: 1
6
4
  ---
7
5
 
8
- # Inheritance
9
-
10
6
  FakerMaker can exploit the Ruby class hierarchy to provide additional specialisation or to override some behaviours:
11
7
 
12
8
  ```ruby
@@ -22,16 +18,18 @@ FakerMaker.factory :motorbike, parent: :vehicle do
22
18
  end
23
19
  ```
24
20
 
25
- This is the equivalent of:
21
+ This is the equivalent of:
22
+
23
+ Since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace.
26
24
 
27
25
  ```ruby
28
- class Vehicle < Object
26
+ class FakerMaker::Factory::Vehicle < Object
29
27
  # ...
30
28
  end
31
29
 
32
- class Motorbike < Vehicle
30
+ class FakerMaker::Factory::Motorbike < FakerMaker::Factory::Vehicle
33
31
  # ...
34
32
  end
35
33
  ```
36
34
 
37
- so a motorbike will still have a colour and engine capacity between 600 and 2500.
35
+ so a motorbike will still have a colour and engine capacity between 600 and 2500.
@@ -1,12 +1,8 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: JSON Field Names
4
- parent: Usage
5
- nav_order: 4
6
4
  ---
7
5
 
8
- # JSON Field Names
9
-
10
6
  JavaScript likes to use camelCase, Ruby's idiom is to use snake_case. This can make make manipulating factory-built objects in ruby ugly. To avoid this, you can call your fields one thing and ask the JSON outputter to rename the field when generating JSON.
11
7
 
12
8
  Faker Maker provides two mechanisms for dealing with this.
@@ -54,4 +50,4 @@ v.to_json
54
50
 
55
51
  ## Combining the two approaches
56
52
 
57
- If the factory has a `:naming` strategy defined and an attribute has its own `:json` name defined, the attribute's `:json` name will take precedence.
53
+ If the factory has a `:naming` strategy defined and an attribute has its own `:json` name defined, the attribute's `:json` name will take precedence.
@@ -1,12 +1,8 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Lifecycle Hooks
4
- parent: Usage
5
- nav_order: 8
6
4
  ---
7
5
 
8
- # Lifecycle Hooks
9
-
10
6
  Faker Maker has a few hooks which can be added to the factory which are triggered when the factory builds an instance.
11
7
 
12
8
  * `before_build` the instance has been created but none of the values have been set yet
@@ -15,7 +11,7 @@ Faker Maker has a few hooks which can be added to the factory which are triggere
15
11
  For instance:
16
12
 
17
13
  ```ruby
18
- FakerMaker.factory :user do
14
+ FakerMaker.factory :user do
19
15
  before_build do |instance, factory|
20
16
  puts 'Building an instance of User'
21
17
  end
@@ -23,7 +19,7 @@ FakerMaker.factory :user do
23
19
  name {'Patsy Stone'}
24
20
  email {'patsy@fabulous.co.uk'}
25
21
  admin {false}
26
-
22
+
27
23
  after_build do |instance, factory|
28
24
  puts "Built an instance of User (#{instance.name})"
29
25
  end
@@ -1,10 +1,6 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Managing Dependencies
4
- parent: Usage
5
- nav_order: 3
6
4
  ---
7
5
 
8
- # Managing Dependencies
9
-
10
- Factory definition files are Plain Ol' Ruby. If you depend on another factory because you either extend from it or use it just add a `require` or (depending on your load path) `require_relative` to the top of your file.
6
+ Factory definition files are Plain Ol' Ruby. If you depend on another factory because you either extend from it or use it just add a `require` or (depending on your load path) `require_relative` to the top of your file.
@@ -1,16 +1,12 @@
1
1
  ---
2
- layout: default
2
+ layout: single
3
3
  title: Omitting Fields
4
- parent: Usage
5
- nav_order: 5
6
4
  ---
7
5
 
8
- # Omitting Fields
9
-
10
6
  Sometimes you want a field present, other times you don't. This is often the case when you want to skip fields which have null or empty values.
11
7
 
12
8
  ```ruby
13
- FakerMaker.factory :user do
9
+ FakerMaker.factory :user do
14
10
  name {'Patsy Stone'}
15
11
  email(omit: :nil) {'patsy@fabulous.co.uk'}
16
12
  admin {false}
@@ -34,9 +30,9 @@ There are three special modifiers:
34
30
  These can be mixed with real values, e.g.
35
31
 
36
32
  ```ruby
37
- FakerMaker.factory :user do
33
+ FakerMaker.factory :user do
38
34
  name {'Patsy Stone'}
39
35
  email(omit: [:nil, :empty, 'test@foobar.com']) {'patsy@fabulous.co.uk'}
40
36
  admin {false}
41
37
  end
42
- ```
38
+ ```
@@ -0,0 +1,20 @@
1
+ ---
2
+ title: "About"
3
+ layout: single
4
+ permalink: /pages/about/
5
+ author_profile: true
6
+ ---
7
+
8
+ Faker Maker was designed to be a trivial way to create data factories that could throw JSON payloads at an API endpoint. It has grown well beyond that original purpose but still remains a thing for building things that give you data.
9
+
10
+ It is much beloved by me. Although it's a personal project, it's used extensively by my employer and influenced by the needs of my colleagues. I hope it will be useful to you as well. I am very open to ideas, feedback and contributions.
11
+
12
+ Faker Maker is licenced under the [MIT licence](https://raw.githubusercontent.com/BillyRuffian/faker_maker/refs/heads/master/LICENSE.txt). Do with it what you will and have fun.
13
+
14
+ ### What's the Billy Ruffian thing?
15
+
16
+ HMS Bellerophon was a 74-gun third-rate ship of the line of the Royal Navy. Launched in 1786, she served during the French Revolutionary and Napoleonic Wars, mostly on blockades or convoy escort duties. She fought in three fleet actions: the Glorious First of June, the Battle of the Nile and the Battle of Trafalgar. She became famous as the ship upon which Napoleon surrendered and which transported him into exile in 1815.
17
+
18
+ Her sailors, not being educated in the Classics, struggled to pronounce her name and so she became known as the Billy Ruffian and her crew as the "Billy Ruffians". The name stuck and was used as a nickname for the ship for the rest of her career.
19
+
20
+ Since no one in coffee shops can spell my name, I adopted 'Billy' which turned into 'Billy Ruffian'. It's also a bloody good story.
@@ -0,0 +1,27 @@
1
+ ---
2
+ # Feel free to add content and custom Front Matter to this file.
3
+ # To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults
4
+
5
+ # layout: single
6
+ layout: splash
7
+ permalink: /
8
+ author_profile: false
9
+
10
+ feature_row:
11
+ - image_path: /assets/images/unipug.svg
12
+ alt: An illustration of cute pug dog pretending to be a unicorn by wearing a costume
13
+ title: Factories over fixtures
14
+ excerpt: FakerMaker is a simple factory builder so you can throw away your fixtures and generate test data instead.
15
+ url: "/docs/installing/"
16
+ btn_label: "Get Started"
17
+ btn_class: "btn btn--success"
18
+ ---
19
+
20
+ {% include feature_row type="center" %}
21
+
22
+ Sometimes you need generate data; something testers need to do a lot. Often, a bunch of fixtures will be built by hand, carefully maintained and curated, until the API or schema or something changes and all the fixtures need to be pruned before the tests pass again. This drives testers into building fixtures which individually cover lots of acceptance critera just so that they can drive down the number of them they have to maintain until the fixtures don’t resemble anything like realistic criteria.
23
+
24
+ If you’re testing a Rails application, you can use the awesome FactoryBot to generate faked model instances but what if you’re not using Rails or you don’t have model classes or you’re testing an API? This is what Faker Maker aims to help with.
25
+
26
+ It is designed to resemble the Factory Bot gem but without needing an existing class definition to back its object and so it goes without saying that it offers no persistence mechanism. Its purpose is to provide a simple framework for generating data to test JSON APIs and is intended to be used with the Faker gem (but has no dependency upon it).
27
+