Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,27 @@ name: Ruby
on:
push:
pull_request:
branches: [ "master" ]
branches: ["master"]

permissions:
contents: read

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["3.0", "3.1", "3.2"]
ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"]

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1 # v1.146.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
6 changes: 3 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Layout/SpaceInsideParens:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Max: 120

Metrics/ModuleLength:
Expand Down Expand Up @@ -32,7 +32,7 @@ Style/HashEachMethods:

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true

Expand All @@ -52,4 +52,4 @@ Metrics/PerceivedComplexity:
Max: 10

AllCops:
NewCops: enable
NewCops: enable
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in faker_maker.gemspec
gemspec

gem 'bundler-audit', '~> 0.9.2'
gem 'irb', '~> 1.15'
gem 'rdoc', '~> 6.13'
2 changes: 1 addition & 1 deletion lib/faker_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def shut!( name )
return unless factory

factories[name] = nil
Object.send( :remove_const, factory.class_name )
FakerMaker::Factory.send( :remove_const, factory.class_name )
end

def shut_all!
Expand Down
4 changes: 2 additions & 2 deletions lib/faker_maker/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize( name, options = {} )

def parent_class
if @parent
Object.const_get( FakerMaker[@parent].class_name )
FakerMaker::Factory.const_get( FakerMaker[@parent].class_name )
else
Object
end
Expand Down Expand Up @@ -67,7 +67,7 @@ def build( attributes: {}, chaos: false, **kwargs )
def assemble
if @klass.nil?
@klass = Class.new parent_class
Object.const_set @class_name, @klass
FakerMaker::Factory.const_set @class_name, @klass
attach_attributes_to_class
attach_json_overrides_to_class
end
Expand Down
2 changes: 1 addition & 1 deletion lib/faker_maker/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module FakerMaker
VERSION = '2.1.2'
VERSION = '3.0.0'
end
2 changes: 1 addition & 1 deletion spec/faker_maker/factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
child_attributes.each { |a| child.attach_attribute( a ) }
FakerMaker.register_factory( child )

fake = Child.new
fake = FakerMaker::Factory::Child.new

expect( fake ).to respond_to( :date )
expect( fake ).to respond_to( :title )
Expand Down
8 changes: 4 additions & 4 deletions spec/faker_maker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

it 'builds objects from a factory' do
FakerMaker.register_factory(factory)
expect( FakerMaker.build( :placeholder ) ).to be_a Placeholder
expect( FakerMaker.build( :placeholder ) ).to be_a FakerMaker::Factory::Placeholder
end

it 'raises an error if the factory doesn\'t exist' do
Expand All @@ -29,10 +29,10 @@
describe '#shut!' do
it 'removes the factory and its class' do
factory = FakerMaker.register_factory( FakerMaker::Factory.new( :shut_me ) )
expect( Object.const_get( factory.class_name) ).not_to be_nil
expect( FakerMaker::Factory.const_get( factory.class_name) ).not_to be_nil
FakerMaker.shut!( factory.name )
expect { FakerMaker[factory.name] }.to raise_error( FakerMaker::NoSuchFactoryError )
expect { Object.const_get( factory.class_name) }.to raise_error( NameError )
expect { FakerMaker::Factory.const_get( factory.class_name) }.to raise_error( NameError )
end
end

Expand All @@ -43,7 +43,7 @@
FakerMaker.shut_all!
factories.each do |name, factory|
expect { FakerMaker[name] }.to raise_error( FakerMaker::NoSuchFactoryError )
expect { Object.const_get( factory.class_name) }.to raise_error( NameError )
expect { FakerMaker::Factory.const_get( factory.class_name) }.to raise_error( NameError )
end
end
end
Expand Down
22 changes: 12 additions & 10 deletions usefakermaker.com/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
source "https://rubygems.org"
# frozen_string_literal: true

source 'https://rubygems.org'
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
Expand All @@ -7,31 +9,31 @@ source "https://rubygems.org"
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
gem "jekyll", "~> 4.3.4"
gem 'jekyll', '~> 4.3.4'
# This is the default theme for new Jekyll sites. You may change this to anything you like.
gem "minima", "~> 2.5"
gem 'minima', '~> 2.5'
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.12"
gem "jekyll-data"
gem 'jekyll-data'
gem 'jekyll-feed', '~> 0.12'
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
platforms :mingw, :x64_mingw, :mswin, :jruby do
gem "tzinfo", ">= 1", "< 3"
gem "tzinfo-data"
gem 'tzinfo', '>= 1', '< 3'
gem 'tzinfo-data'
end

# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1", :platforms => [:mingw, :x64_mingw, :mswin]
gem 'wdm', '~> 0.1', platforms: %i[mingw x64_mingw mswin]

# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
# do not have a Java counterpart.
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]
gem "minimal-mistakes-jekyll"
gem 'base64'
gem 'csv'
gem 'http_parser.rb', '~> 0.6.0', platforms: [:jruby]
gem 'minimal-mistakes-jekyll'
2 changes: 1 addition & 1 deletion usefakermaker.com/docs/usage/building-instances/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To build an object:
result = FakerMaker[:basket].build
```

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.
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.

It's possible to override attributes at build-time, either by passing values as a hash:

Expand Down
7 changes: 4 additions & 3 deletions usefakermaker.com/docs/usage/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ FakerMaker.factory :user do
end
```

This will generate a `User` class with the attributes `name`, `email` and `admin` which will always return the same value.
This will generate a `FakerMaker::Factory::User` class with the attributes `name`, `email` and `admin` which will always return the same value.
Since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace.

It is possible to explicitly set the name of class which is particularly useful if there is a risk of redefining an existing one.
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)

```ruby
FakerMaker.factory :user, class: 'EmailUser' do
Expand All @@ -25,7 +26,7 @@ FakerMaker.factory :user, class: 'EmailUser' do
end
```

The class name will always be turned into a Ruby-style class name so `email_user` would become `EmailUser`.
The class name will always be turned into a Ruby-style class name so `email_user` would become `FakerMaker::Factory::EmailUser`.

Because of the block syntax in Ruby, defining attributes as `Hash`es requires two sets of curly brackets:

Expand Down
6 changes: 4 additions & 2 deletions usefakermaker.com/docs/usage/inheritance/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ end

This is the equivalent of:

Since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace.

```ruby
class Vehicle < Object
class FakerMaker::Factory::Vehicle < Object
# ...
end

class Motorbike < Vehicle
class FakerMaker::Factory::Motorbike < FakerMaker::Factory::Vehicle
# ...
end
```
Expand Down
Loading