I have around 50 feature files and I want the tester team to run them. I don't want them to run all the files at once and also don't want them to get in the prerequisites for running cucumber ie..bundle install ...rake db:migrate...service postgresql start...... etc
I want to make a shellscript file so that they can execute it, select the option which file to run (all or other individual file) and then the script would execute the prerequisites and execute the file and output the log to specified folder. I want to make a sh file.
Of course I don't know your development environment or exactly what commands you need to execute to get your tests running, but here's a sample shell script:
#!/bin/sh
bundle install
rake db:migrate
rake db:test:prepare
rake cucumber "$#"
Execute the script like this:
./script_name.sh
With arguments:
./script_name.sh features/registration.feature
The "$#" part will pass any arguments like features/registration.feature to rake cucumber.
Related
Can I invoke "rake jobs:work" automatically after running "rails s" in console?
Currently, after running rails s in cmd I will also run rake jobs:work in the other console, what i want to happen is After running "rails s" the jobs:work will automatically start.
The right way to go about this would be to use a process manager, like Invoker or Foreman. There is ample documentation on the links, but it boils down to the following steps:
Install the software
Create a configuration file where you declare what processes do you intend to run. Both support Procfile style declaration.
Use the command line client to start the process manager.
Based on my personal experience, I highly recommend Invoker, it goes beyond just a process manager, and packs in a few more handy features, like support for .dev local domain.
One you can do is simply:
rails server & rake jobs:work
It'll run rails server as background job, which you can get back to foreground with fg. It can be annoying that you'll get output from both processes mixed.
I'm not sure what are your needs and what you expect but maybe it would be good for you to use screen (or tmux) to run them in parallel and be able to switch between.
You can do your own .screenrc script which will run the server and any other commands when automatically for you.
There is a little problem that if you run the server from it and you close it (ctrl+c) than you'll loose it's screen window. Fortunately there is a solution for that as well (worked-out on the SO as well - you can read more about it here)
So, I use some helper script for that .run_screen (don't forget to chmod +x it):
#!/bin/bash
/bin/bash -i <<<"$*; exec </dev/tty"
Than I have .screenrc_rails file:
#shell -${SHELL}
caption always "%n(%t) %= %{b}#%H[%l] : %{r}%c:%s"
termcapinfo xterm ti#:te#
termcap xterm 'AF=\E[3%dm:AB=\E[4%dm'
terminfo xterm 'AF=\E[3%p1%dm:AB=\E[4%p1%dm'
startup_message off
screen -t server 2 ${HOME}/.run_screen rails s
screen -t spork 3 ${HOME}/.run_screen bundle exec spork
screen -t dev_log 4 ${HOME}/.run_screen tail -f ./log/development.log
screen -t test_log 5 ${HOME}/.run_screen tail -f ./log/test.log
screen -t bash 0
screen -t bash 1
And an alias ( screenr(ails) ) defined at .bash_profile:
alias screenr='screen -c ~/.screenrc_rails'
If you don't know screen than start from ctrl+a, ". ctrl+a, ? will give you some help.
I hope you'll enjoy it.
I should change to specific folder so that the output of the script can be exported into a file in that folder (123.txt in the example code below).
but this command, which I run from inside my ruby code
./iw2_broadcast.py
takes 5 minutes or more to complete. I try to append & to make it run in the background, but it seems it does not work.
Any ideas? Thanks
Dir.chdir(#iw2_dir)
` ./iw2_broadcast.py -f 123.txt & `
puts "123"
Create a shell script with the execution command
# py.sh
./iw2_broadcast.py
Execute the above shell script from ruby using system command
# ruby_script.rb
system("./py.sh")
Now your ruby code will be executed without waiting for the output
Adding & works with system(). You can easily test it with:
system("sleep 1 &")
So for this precise example:
system("./iw2_broadcast.py -f 123.txt &")
I'm trying to write a task for Capistrano 3 that involves executing 'composer install' within the directory of the current release. It looks something like this:
namespace :composer do
desc 'Install dependencies with Composer'
task :install do
on roles(:web) do
within release_path do
execute "#{fetch(:composer_command)} install"
end
end
end
end
composer_command is set in the staging and production files - in my particular case to php /home/user/composer.phar
For some reason this command does not actually run in the current release directory, but instead runs in the parent directory (containing current, shared, releases, etc)
I delved into this a bit further and found that when I ran a single word command, like:
within release_path do
execute "pwd"
end
It works just fine, and runs the command in the current release directory. But... when I run a command with spaces, like:
within release_path do
execute "pwd && ls"
end
It runs in the parent directory, and not the directory set by the within block.
Can someone shed some light on this? Thanks!
Smells like a Cap 3 bug.
I suggest just guaranteeing you are where you want to be from the shell perspective:
execute "cd '#{release_path}'; #{fetch(:composer_command)} install"
You can retain all the niceties of within(), with(), default_env, etc, while still keeping the natural string syntax:
within release_path do
execute *%w[ pip install -r requirements.txt ]
end
A couple of tips:
1) Capistrano uses SSHKit for a lot of things, among which command execution. In order to simplify using Composer you could configure the command map (in deploy.rb or production.rb, etc), here are 2 examples:
SSHKit.config.command_map[:composer] = "#{shared_path.join('composer.phar')}"
SSHKit.config.command_map[:composer] = '/usr/bin/env composer.phar'
Next you can execute it like so:
execute :composer, :install
2) From a security perspective it's wise to disable the php setting allow_url_fopen, but unfortunately Composer needs it enabled to function. You can use this trick to leave it disabled globally:
SSHKit.config.command_map[:composer] = "/usr/bin/env php -d allow_url_fopen=On #{shared_path.join('composer.phar')}"
Check out iniscan for more security advise on php settings.
3) Composer has an option -d, --working-dir, which you can point to the directory containing the composer.json file in order to run Composer from any other directory. This should solve your problem:
execute :composer, '-d', release_path, :install
4) You may want to take a look at the capistrano-composer project :)
Actually, your use of the within function is almost correct. You have supplied it an entire string as a command, but the doc points out that this results in unreliable behaviour (which I have experienced myself).
Let the first argument to execute be a symbol instead of a string (which contains whitespace):
within release_path do
execute fetch(:composer_command).to_sym, "install"
execute :pwd
execute :ls
end
just for reference here is the Capistrano Doc explaining why within {} does not work with arguments with whitespace. I hope this helps.
I want to run the rspec tests for Gitlab within vim (calling: !rspec). The problem is, i'm using the vagrant box provided here: https://github.com/gitlabhq/gitlab-vagrant-vm
This means that the whole app is running inside of the vagrant box, and when i call rspec from within vim, it tries to run locally.
Is there any way i can forward the rspec call to the vagrant box, and get the output back locally?
I've found this one: https://github.com/clintoncwolfe/vagrant-rspec-ci But its not what im looking for, since i have to run a custom command.
Maybe its related to: Spork, Vagrant, and Rspec
You can execute any command over ssh, and return the output:
$ ssh user#host echo "hi"
hi
You could use this to run rspec:
$ ssh user#vagrant-ip "cd /path/to/project && rspec"
The thing to bear in mind with this approach is that your shell's environment must be set up correctly to allow access to the rspec command. Your mileage will vary depending on how you manage your rubies.
But you can set up a command in vim to execute this SSH command, and the output will be returned, e.g.:
:command VRspec exec "system('ssh user#vagrant-ip...')"
How can I make an alias either run a script in another directory or both cd and run the script?
I have commands in my .bashrc file to cd /home/myname/my_dir
and also
rake sunspot:solr:start
when I am in our app directory (that contains the /script subdirectory).
I have not been able to put either put the directory in the rake command or have the alias do a cd and then the rake command that it currently does.
For instance I attempted rake /home/my_dir/out_code_directory/sunspot:solr:start RAILS_ENV=test but that didn't work.
alias rakesolr='cd dir; rake sunspot:solr:start; cd -'
works for me (in bash). Does that do what you need?
[ Ahh, semicolon ! Michael.]
Maybe can you edit your rake task ?
Or you can make a new task that do a Dir.chdir and then execute the task wanted.
Edit : resource about execute a task within another here
Why not write a small bash script that cds then executes the script and have that run via an aliased command?