factory_bot | A library for setting up Ruby objects as test data | Application Framework library
kandi X-RAY | factory_bot Summary
kandi X-RAY | factory_bot Summary
factory_bot is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc. We love open source software! See our other projects or hire us to design, develop, and grow your product.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of factory_bot
factory_bot Key Features
factory_bot Examples and Code Snippets
Community Discussions
Trending Discussions on factory_bot
QUESTION
I am getting the following error zeitwerk/loader/helpers.rb:95:in const_get': uninitialized constant Controllers::BasePublicDecorator (NameError)
This is an error in a local production console using rails c -e production
but not an issue in development which works perfectly.
In an engine, CcsCms::PublicTheme
, I have a decorator I am using to extend the controller of another CcsCms::Core
engine and it is this decorator that is causing the error.
...public_theme/app/decorators/decorators/controllers/base_public_decorator.rb
ANSWER
Answered 2022-Apr-02 at 19:30Problem here is that when lazy loading, nobody is referencing a constant called ...::BasePublicDecorator
. However, Zeitwerk expects that constant to be defined in that file, and the mismatch is found when eager loading.
The solution is to configure the autoloader to ignore the decorators, because you are handling their loading, and because they do not define constants after their names. This documentation has an example. It needs to be adapted to your engine, but you'll see the idea.
For completeness, let me also explain that in Zeitwerk, eager loading is a recursive const_get
, not a recursive require
. This is to guarantee that if you access the constant, loading succeeds or fails consistently in both modes (and it is also a tad more efficient). Recursive const_get
still issues require
calls via Module#autoload
, and if you ran one for some file idempotence also applies, but Zeitwerk detects the expected constant is not defined anyway, which is an error condition.
QUESTION
So I have a file not found problem. I have an engine that works in development mode in the engines test/dummy app, the engine allows the editing of sass variables and stores them in a theme table, the variables are used by a sass partial such as _banner.scss containing variables used in the main stylesheet such as $banner_color which is then imported into the main stylesheet which in turn is precompiled using an initializer in the engine.rb file and inclusion in the app/config/engine_name_manifest.js.
The files are all available in development with the local dummy app but not in the eventual host app due to the assets being compiled.
I have a rake task that takes the data, updates the relevant partial e.g. _banner.scss with the data from the theme table but of course the partials are not not available in a host app as the engine has already compiled them. I'm looking for a solution that will allow me to edit the raw, uncompiled stylesheets then recompile them. Obviously my Capistrano deploy script will need to reapply the stylesheet changes every deployment but that is just a rake task call. What approach should I take? Should I find a way to copy the css files to the host app in an engine initializer? Should I use a different approach entirely, I have started looking at propshaft but that is a massive step to replace sass rails and I'm not sure how that would help
The engine
...ANSWER
Answered 2022-Apr-02 at 03:44Thanks for clarifying. If I understood correctly here my take on it.
partials are not not available in a host app as the engine has already compiled them
Partials are still there, precompilation just outputs *.{css/js}
files into public/assets/
that are declared in app/assets/config/manifest.js
.
To get to engines files, instead of Rails.root
use:
QUESTION
I am trying to use a helper method in my FactoryBot
file, but when I call require rails_helper
I get a require: cannot load such file -- support/geocoder_helper (LoadError)
.
spec/factories/members.rb
ANSWER
Answered 2021-Nov-09 at 09:43spec
folder is not in your load_path
. You can either:
use absolute path
require Rails.root.join('support/geocoder_helper')
use relative require
require_relative '../support/geocoder_helper'
add
spec
folder to your load (in spec_helper.rb):$LOAD_PATH << Rails.root.join('spec')
require all your support files in spec_helper, which is pretty standard procedure
Other issues: do not define methods on main
object. It is quite a terrible practice that I keep fixing in most of the specs, causing a lot of really odd behaviours and subtle bugs. Once the geocoder_helper file is loaded, add_geocoder_stub
method is defined on Object
class making it available in every single object globally (that is including nil
, true
, all symbols etc). This is just, well, yucky - not to mention it might cause unexpected behaviour changes as suddenly respond_to?
will return true and you just don't know what other libraries might be using this.
Instead, wrap your method in modules:
QUESTION
I'm seeing the following error it only is appearing in cron jobs using the whenever gem. The application is working correctly otherwise. The scheduled job doesn't run. But I can run it manually and it does work.
...ANSWER
Answered 2021-Sep-23 at 15:08The issue was related to environment variables and not being able to find the correct path for the gems. I found a solution and updated the schedule.rb file.
QUESTION
I'm quite new with Rspec and factory_bot. I have the following factories:
...ANSWER
Answered 2021-Jul-24 at 19:16There must be a validation in your user model that prevents you from creating users with an email and/or username that's already in the database. And as you have a factory (favorite
), that attempts to create a user and a game, without checking first if the user email and/or username already exist, it fails because it uses the values you set for them, which are always the same ("test@gmail.com", "test", correspondingly).
You can use a FactoryBot sequence for that:
QUESTION
Im running ruby version 2.6.1 with docker. Rake gem is version 13.0.1.
Whenever I tried docker-compose up, it always fails and throws this error everytime:
This error did not exist before.
ANSWER
Answered 2021-May-23 at 12:27I'm not really sure what happened and why but I tried doing this on my rails container and I was no longer receiving the said error.
docker-compose run --rm bash
cd to project directory
bundle install
QUESTION
When using FactoryBot in conjunction of default_value_for
gem, and when relying on an association that must be present like belongs_to
to define the default value, I run in an error telling me that the relationship is not defined.
Here is a simplified example:
...ANSWER
Answered 2021-Mar-18 at 22:32Make sure to use initialize_with
in your factory, so when assigning the attributes, your association is already defined.
QUESTION
I have a model called Event. It looks like this:
...ANSWER
Answered 2021-Feb-28 at 01:48Turns out this was being caused by the automatic generation of enum traits, which is why there were those incompatible traits that were causing the linter to fail. The feature is described here, you can disable it with FactoryBot.automatically_define_enum_traits = false
(I created a factory_bot.rb
file in my initializers directory and disabled it there).
QUESTION
I have a handler which is responsible for creating a new record in db.It takes params from the POST requests and adds a new record to database.That helper is defined below:
...ANSWER
Answered 2020-Dec-09 at 20:32A handler is a class, so just need to do something like this...
QUESTION
I use Rails 5 with ruby 2.4.1
I begin make rspec tests on application...
This is my first test and i don't have success
After I will use Faker gem to put random information, but first i need this run with sucess, please help me!
spec_helper.rb
...ANSWER
Answered 2020-Nov-09 at 00:50You should require 'rails_helper'
in your rspec tests, not spec_helper.
rails_helper will set up the rails environment for rspec
and load spec_helper, but spec_helper does not load rails_helper. Without rails_helper, rspec does not know how to load the Rails code.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install factory_bot
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page