我正在测试在轨道上添加一些生成器的宝石。
为了测试,我有一个瑞克任务,该任务准备一个新的Rails应用程序,安装我的gem,然后运行生成器。
问题是,在耙任务(spec:prepare
)中,我无法使它正常工作:bundle exec rails new test_app...
如果我放弃bundle exec
,一切都很好。
最接近成功的方法是这样的:
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
namespace :spec do
task :prepare do
Dir.chdir('spec') do
sh('rm -rf test_app')
Bundler.with_clean_env do
sh('rails -v')
# works: sh('rails new test_app -T') # works !
sh('bundle exec rails new test_app -T') # fails ...
end
# ... more stuff but doesn't get this far unless I don't use bundler above
end
end
end
end
task :default => :spec
基于以上内容,我在Gemfile
目录中具有以下spec
:
gem 'rails', '~> 6.0'
这成功创建了一个Rails应用程序结构,然后运行捆绑安装,但随后出现此错误:
Bundle complete! 14 Gemfile dependencies, 66 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
run bundle binstubs bundler
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
run bundle exec spring binstub --all
* bin/rake: Spring inserted
* bin/rails: Spring inserted
rails webpacker:install
Traceback (most recent call last):
3: from bin/rails:8:in `<main>'
2: from bin/rails:8:in `require_relative'
1: from .../ruby/rails-hyperstack/spec/test_app/config/boot.rb:4:in `<top (required)>'
.../ruby/rails-hyperstack/spec/test_app/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
rake aborted!
Command failed with status (1): [bundle exec rails new test_app -T...]
您可以使用-B [--skip-bundler]
跳过捆绑程序。您可以使用--skip-spring
跳过弹簧。
[您也可以使用-p [--pretend]
选项进行空运行,它不会生成文件,而只是写出有关stdout输出的期望,它将比实际生成应用程序快得多。