Let's say I've got Ruby process A using a set of dependencies managed by bundler.
I want to spawn a subprocess and have that subprocess do work in a separate set of dependencies.
Specifically:
process A accepts incoming API requests to run an automated test suite
process A spawns process B
process B runs the test suite using a separate set of tools & dependencies
Currently when I spawn B, I'm getting errors like this:
/Users/foomanchu/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/bundler/rubygems_integration.rb:374:in `block in replace_bin_path': can't find executable cucumber for gem cucumber. cucumber is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
Thoughts ?? Thanks ~~
Related
During my attempt to automate some task with rake on ubuntu, I've encountered scenarios that required packed might not already exist on target machine. What is a good way to check if certain package was already installed on the system and respond accordingly?
For example, I'd like to run 'npm start' within certain task, but I'd want to know if npm has already been installed on the system, thus giving user the correct error message. I'm also fine doing it with thor if it's possible at all.
You can run system command from Ruby scripts using the Kernel.system method. Consider something like the following:
fail unless system('which npm')
I'm writing a node module to be open sourced and there's a dependency on some Ruby code (see Can I include a Ruby Gem in a Node.js project? for details). I made a Ruby project that requires some gems and all of that works well. In my node_module, I want to interface it via exec to the Ruby code.
But now there's Ruby dependencies as well. So can I somehow specify the Ruby version, and the gemset required to run my node package?
Ambiguous question perhaps. I can clarify if anything is unclear.
I don't think you can/should specify the Ruby version to use when executing your code. That should be up the library consumer so choose. Since you want to execute your code with exec, the library consumer will have the added responsbility of making ruby accessible to the node process. How that happens is not up to you as the library developer.
As for dependencies/gemsets, just use bundler.
Maybe you could do something like this - without more information it's hard to say.
On the ruby side, build your gem to do whatever it needs to do and then add a rake task to it. How you build this rake task is obviously up to the demands of the project and how it will be used, but it will provide a way for you to interface from the outside.
In the 'middle' build a bash script that includes RVM - this way you can require a specific gemset/do specifc things before running the rake task. Another benefit is that if you want to change the gemset or other implementation details, you just change the bash script.
On the node side, call the bash script. More info on that in this answer.
How do I specify a cucumber profile when using the parallel tests gem?
If I were to launch cucumber from the command line (using Jruby) I would do
Jruby -S cucumber -p profile_name
and using rake tasks I would set the tasks profile t.profle=myprofile and then execute using rake mytask
so when using parallel_tests I launch the tests using the built in rake tasks associated with the gem : rake parallel:features is there any way to pass in t.profile argument into the rake task on execution?
What i would like to do is something along the lines of
rake parallel:features[4] t.profile=myprofile
This may or may not be useful, but in the cucumber.yml, you can just add a parallel: profile and it will get picked up automatically. You can specify one on command line but I didn't bother trying to figure it out because I don't really have the need to switch profiles.
I've got a Ruby project started with NetBeans, so the Rake file has been generated. Is there a way that I can run the project over the command line?
It runs fine when I use F6 through NetBeans, as does my automated test suite with Alt+F6. I'm essentially looking for something like...
$ rake run
Does this exist?
The goal of ruby programming is (generally) to either write a web application, or write a program that can be run from the command line.
For a web application a rake run option might be worthwhile, but really the most common web applicaition framework is Rails, and for rails, you can just run a dedicated webserver running your web app with script/server.
For a commandline program, just run whichever ruby file you have intended as the main file (the one with the code that runs at startup). Ruby doesn't have any of the difficulties that Java does (e.g. having a jar file with the right Main-class attribute, and getting the classpath right, etc...). So you don't really need a rake run target, because there's no complexity that needs to be hidden in the rakefile.
Although Ken's right, you can certainly make a rake task to run your program. In lib/tasks/project.rake:
namespace :project do
task :run do
call_your_code()
end
end
and then rake project:run will do what you want.
I tried to make a script that would execute several external binaries to perform some tasks. Each binary was executed from a different thread, but the thing is, it didn't work ( because of the implementation of Ruby's threads in 1.8.6 ).
Is there a different way I could do this, or do I have to go with Ruby 1.9 ?
Have you try Ruby Daemons? I have about 15 external application running simultaneously with RoR by implement it. (http://daemons.rubyforge.org/)
Basically, you extract your thread code to another ruby file. say my_external_call.rb. then, create a daemon control
require 'daemons'
Daemons.run('my_external_call.rb')
execute it by 'ruby control.rb start | stop | status'