Please, I have the same problem: Deploy error ruby on rails Don't know how to build task 'assets:precompile'?
If it's possible, helpme and help this guy too.
Thanks in advance for your attention
Update:
With #Anuj help, I find the solution:
Precisely because my project is API by default, I don't have the precompile assets (#Anuj said the same, I didn't know).
The solution to me is:
-> remove inside my Capfile: require 'capistrano/rails/assets'
-> remove inside my deploy.rb after :finishing, :compile_assets
assets:precompile is a task provided by Sprockets, which does not get included by default in an API only app (because APIs don't need assets).
In your Capfile, when you write
require 'capistrano/rails'
it basically includes both the below lines automatically
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
If you replace the capistrano/rails with just capistrano/rails/migrations in your Capfile, that should solve your problem.
Related
On our application we use RSpec, Capybara and Capybara-screenshot. All things work fine except cleaning tmp/screenshots folder. The project is configured with default settings, so images are saved in the screenshots folder. New screenshots with failed tests are added to the old ones and are difficult to find and identify problems in tests.
Capybara-screenshot has default method prune_strategy to do this, but it didn't work.
After implement a new function, we need to fix/create a test, and then manually empty the folder with screenshots and only then run tests so as not to confuse the old screenshots and the new ones. Is there a way to configure this folder to be automatically cleaned up after running the rspec command, but before running the tests?
# Gemfile
ruby '2.6.6'
gem 'rails', '5.2.0'
group :test do
gem 'capybara'
gem 'capybara-screenshot'
gem 'webdrivers'
end
# spec/rails_helper.rb
require File.expand_path('../config/environment', __dir__)
abort('The Rails environment is running in production mode!') if Rails.env.production? || Rails.env.staging?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
Capybara.asset_host = 'http://localhost:5000'
Capybara::Screenshot.prune_strategy = :keep_last_run
# Also tried with this config:
# Capybara::Screenshot.prune_strategy = { keep: 20 }
Thanks for answers!
From the capybara-screenshot gem
def wildcard_path
File.expand_path('*.{html,png}', Screenshot.capybara_root)
end
def prune_with_last_run_strategy
FileUtils.rm_rf(Dir.glob(wildcard_path))
end
So it will remove all html and png files from the Screenshot.capybara_root directory - Obviously that wouldn't work if you're not screenshotting in png or html and if you're changing the directory after pruning has occurred.
Note, that from the code it looks like pruning is only done when the screenshot is saved, so if you have no failures in your run it wouldn't actually prune the screenshots from the previous run. If that's not the behavior you want it looks like you should be able to add an RSpec before(:suite) block that calls Capybara::Screenshot.prune
I want to analyse the test coverage of our code , and therefore, installed the simplecov gem.
Our testing environement has 2 seperate project: REST API test (Java+Rest-Assured) and Web UI testing (Java-Selenium).
As you can see, we dont have unit testing inside the rails app, and we are testing using external projects.
I configured the simplecov gem as descriped in the tutorial and put this, in the rails script:
require 'simplecov'
SimpleCov.start 'rails'
puts "require simplecov"
When loading the app, I see the string I printed.
I ran both automation test projects, saw their printouts in the rails log, but I don't see any coverage of controllers/models, I see only small precentage of initializtion files of some gems and rails.
I searched the net, and tried putting the code phrase in boot.rb or even puma.rb and it returned the same results.
Any ideas?
EDIT
Nothing helped with all the comments, but I figured out something very interesting, in all cases, I only see the name of methods marked as tested, not the content (in controllers).
I tried to put the simplecov start phrase in both bin/rails, puma.rb, config.ru, environment.rb, all not given the desired results of code coverage.
I'm not sure simplecov can measure the whole rails app coverage... But I googled something that you can attach as a rack middleware:
https://github.com/danmayer/coverband
And it's output is compatible with simplecov. So it looks like it could be useful in your case.
As you mentioned in your question you're using puma. I suspect that, since it's multi-threaded, it spawns a few rails apps and their simplecov output overwrites each other's results. I'd try with the single threaded server like webrick - but this may make your tests slower (depending on how the tests are fired up really) or try the coverband gem.
Also - even if the server is single threaded - I'm not sure if each request would not overwrite simplecov's output.
Maybe you have to specify the paths
require 'simplecov'
SimpleCov.start do
# add_filter '/admin/'
add_group "Models", "app/models"
add_group "Controllers", "app/controllers"
add_group "Lib", "lib/"
add_group "Helpers", "app/helpers"
end
You need to to start SimpleCov before loading any of your files, so put these lines as early as possible in your ruby entrypoint:
require 'simplecov'
SimpleCov.start
You could see an example in one of my repos here:
https://github.com/tareksamni/DockUp/blob/master/spec/spec_helper.rb
I do autoload my ruby code after starting SimpleCov. You need to the same as well:
require 'simplecov'
SimpleCov.start
require './autoload'
I trying to deploy rails app through capistrano. All assets (css, js and images) build by webpacker. I removed app/assets folder and now deploy failed when capistrano trying to backup manifest. This task running always https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/assets.rake
If I enable sprockets require "sprockets/railtie" everything is fine.
As explained in the capistrano-rails README, if you don't use the asset pipeline, then exclude capistrano/rails/assets from your Capfile. In other words:
# Instead of this:
require "capistrano/rails"
# Require only these:
require "capistrano/bundler"
require "capistrano/rails/migrations"
However, if you are using Webpacker, then there is a good chance that you still need to run asset-pipeline tasks. Notably, you still probably need to run assets:precompile during deployment, in order to trigger the webpack build.
In this case, you would need a more precise exclusion of the backup_manifest task. Following the instructions in the official Capistrano docs, you can clear the default implementation as follows:
# In deploy.rb
Rake::Task["deploy:assets:backup_manifest"].clear_actions
I have a set of files that are in the lib directory of a Ruby on Rails application.
I have a model that needs to use these files. In my model I have the following:
require_relative '../../some_path_to_file_without_extention'
(Side note; I would love to know a way to require all the files, instead of require_relative for each file).
The file that I require_relative has the following require in it.
require "bindata"
When I try to access functions from the require_relative file I get the following error:
LoadError: cannot load such file -- bindata
This is happening for other gems that are being required in the set of files as well. I just chose bindata as an example.
I have bindata in my Gemfile. When I run bundle show bindata it shows me the path to bindata.
I even put require 'bindata' in my model, but it gave me the same load error.
How do I stop the LoadError?
Any help would greatly be appreciated.
Update 1
When I run bundle show . I get the following:
Gems included by the bundle:
...
* bcrypt (3.1.11)
* bindata (2.3.4)
...
Then in the console, requiring bcrypt works but bindata does not.
irb(main):002:0> require 'bcrypt'
=> true
But bindata does not.
irb(main):003:0> require 'bindata'
LoadError: cannot load such file -- bindata
Update 2
Ok so I know is has to be something with how I am loading my rails environment.
bundle exec irb
irb(main):001:0> require 'bindata'
=> true
Update 3
So I went back a few git commits and keep trying to add the gems and see if they would load in my rails console. I went back far enough were it did. Did not know what was different. However, I also noticed when my spring server was restarted then my gems would load in my rails console.
To require all the files in the lib folder, add config.autoload_paths << Rails.root.join('lib') to your application.rb, this answer can help you: https://stackoverflow.com/a/19650564/3739191
Now,
require 'bindata'
should work :)
My project was created using PostgresSQL but we really intend to use MongoDB, what should I change in order for that to happen?
A lot of scaffolding already took place, so we are trying to savage any of the work already done...
Remove database adapter gems from your Gemfile (mysql2, sqlite3, etc.)
Change your config/application.rb
Remove require 'rails/all' line and require frameworks you want to use, for example:
require "action_controller/railtie"
require "action_view/railtie"
require "action_mailer/railtie"
require "active_job/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
NOTE: You should be using the require snippet from the rails/all.rb file that is current with your version of Rails without the active_record railtie. Here is a link to rails/all.rb on the Rails master branch.
Delete your config/database.yml file, db/schema.rb and migrations (if any)
Delete migration check in test/test_helper.rb
Delete any ActiveRecord configuration from your config/environments files
Better late than never! This should come in handy to somebody, someday!!!!
The following python-based migration framework does the job.
https://github.com/datawrangl3r/pg2mongo
Coming to the performance, the migration of each JSON object is dynamic and there shouldn't be any memory lock issues when you use the above framework.
The same situation I also I have to face . I am adding some additional points to above answer .
1) Create a file in initializers and put this code
Mongoid.load!(Rails.root.join("config/mongoid.yml"))
2) You have to remove from every model which are inheriting from ApplicationRecord and delete the application_record file.
3) If you have installed devise so you have to change
**From **
require 'devise/orm/active_record'
to
require 'devise/orm/mongoid'
4) If you are using carrierwave so in gem file you have to replace
From
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
To
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'