Calling Rake Tasks before specs
Closed this issue · 3 comments
I need to call rake tasks before running specs so I don't have to duplicate it in using a scenario or somewhere else. Is this possible? I tried adding in the initializer but I get an error when calling certain task like db:seed
.
example error
20:40:10 server.1 | /Users/abyrd1/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/activerecord-5.2.8.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `mount_uploader' for #<Class:0x00007fcff553b5c0> (NoMethodError)
20:40:10 server.1 | from /Users/abyrd1/Code/cubie/app/models/user.rb:38:in `<class:User>'
20:40:10 server.1 | from /Users/abyrd1/Code/cubie/app/models/user.rb:37:in `<top (required)>'
user.rb
class User < ApplicationRecord
mount_uploader :avatar, AvatarUploader
mount_uploader :signature, SignatureUploader
config/initializers/cypress_on_rails.rby
return unless ENV['CYPRESS'].present?
Rails.application.load_tasks unless defined?(Rake::Task)
# CypressOnRails.hooks.before_server_start do
Rake::Task["db:seed"].invoke
# end
I'm looking for something similar to what is described here(different gem).
Maybe instead try running it from cypress_helper.rb
and you could use system
to execute it so you don't have to load the tasks into the running application.
system "RAILS_ENV=test bin/rails db:seed"
@grantspeelman Looks like it was an issue with Carrierwave. I needed to require the module by adding require 'carrierwave/orm/activerecord'
to the file. I was able to get this working in a scenario. Haven't tried the cypress_helper or initializer.