How execute a self contained rake build? - ruby

We have an application which is compiled using Rake (on windows). We have a new requirement that one of our clients needs to compile the source code in their own environment using a bat file.
So I need to find a way to execute a rake build without installing anything on the host environment (i.e. everything required to do the build needs to be in the source directory, ruby, gems, etc...) from a batch file.
Anyone have any clues how I could get started with this?

Download and install ruby to a folder inside your project (do not add it to your PATH). After go to this folder and delete any "uninstall" file. Go to the folder again with the console (cmd and then use cd path\to\ruby\folder) and run gem install ... to install everything you need. After add a .bat file to run your app. Something like:
#echo off
rubyfolder\bin\ruby.exe myscript.rb
This is a fully portable ruby installation, you can put it in any computer and it will work as well. (I use it as a portable ruby in my pendrive to let me play everywhere with ruby!)
PS.: rake is a script from bin, you can open it with:
rubyfolder\bin\ruby.exe rubyfolder\bin\rake

Related

CLI tool built using commander gem doesn't execute correctly when used after being installed

So, I have a CLI tool I'm building using the commander gem.
The executable successfully executes correctly when used directly from the bin folder (bin/dynamised), but when I install the gem locally and then run it from the command line (dynamised) it doesn't seem to do anything.
If I add puts 'WORKING' to the top of the file, I see that but nothing else.
EDIT:
output of puts [$0, __FILE__].inspect:
from bin:
["bin/dynamised", "bin/dynamised"]
from installed gem:
["/Users/---------/.rbenv/versions/2.3.0/bin/dynamised", "/Users/---------/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/Dynamised-0.1.4/bin/dynamised"]
Link to gist containing executable.
Not quite sure what's wrong.
Change the very last line of your script to:
Dynamised::CLI.new.run if File.basename($0) == File.basename(__FILE__)
or simply remove this redundant check:
Dynamised::CLI.new.run

How can I make a gem perform an action on install?

Update:
Mainly, I need a .bat file to be placed in RUBY_HOME/bin, similar to how rails.bat gets placed in bin when the Rails gem is installed
I'm building a gem that can be used for generating automation test frameworks for testing web application written in any language, with any framework.
I need one file within my gem to be run every time the gem is installed. This file generates either a .bat or .sh file.
I have already built this script and it works great, I just need it be run each time the gem is installed using bundler. Is this possible?

Executable gem - Windows

I am trying to create an executable gem on windows machine. But i am not sure how do make the file executable in windows? Is there any way i can create the same on windows? Here is what i did so far: created a file and then right click and update the permission to read and execute. But its not working. I am keeping this file under bin folder as mentioned " here " in the link
A gem is not executable itself, it is a bundled collection of Ruby scripts and other files which can be executable. You can compare it with a Zip file.
The purpose is to easily distribute your projects tot other computers.
When you gem install the gem and require the gem in a script then you can use what the gem has to offer.
It is possible to execute the scripts and executable files when you use the full path in your console or when the path is included in the Windows path environtment variable. Sometimes a .bat or .cmd (in Windows) is provided that can be called but it just executes some other Ruby scripts.

Building and Testing Command Line Gem on TeamCity

I'm having some trouble testing a command line gem in a TeamCity build environment.
I'm working on a gem for building various types of manifest files, elf_manifesto. It runs from the command line and I've successfully tested it with Cucumber, and the really useful Aruba gem. Locally I'm working on a Lion MBP, using RVM, ruby 1.9.2. Everything's hunky dory.
The problem's arisen when moving the build process to the TeamCity environment at work. The TeamCity agent is running on a windows box and the problem seems to be that when triggering the command line executable from Aruba the script isn't found in the path environment on the windows box. Here's a snippet of Cucumber output from the build log.
[13:46:37]: [Scenario: Start manifesto with no parameters] When I run `manifesto`
[13:46:37]: [When I run `manifesto`] ChildProcess::LaunchError: The system cannot find the file specified. (2)
The Aruba gem is meant to take care of adding the executable (which is in the bin dir) to the path when running the tests. This works fine on my local set up, but fails on Windows. I've tried adding a RUBYPATH environment variable to the build parameters in TeamCity, but so far no luck.
Does anyone have any pointers?
Thanks in advance.
In my experience, Aruba does not add your gem from bin/ into the path. Even on UNIX-based projects, I've had to do it myself:
In env.rb:
PROJECT_ROOT = File.join(File.dirname(__FILE__),'..','..')
ENV['PATH'] = "#{File.join(PROJECT_ROOT,'bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
That being said, I have never gotten Aruba to work on Windows the same way as it did on UNIX.
To help diagnose, make use of the #announce tag on your features (which causes stderr and stdout to be printed), and possibly even drop in your own log statements in your custom steps.
In Windows, only if file with some extension like .COM,.EXE (and others) is executable.
You can change manifesto to ruby manifesto like with correct path to manifesto, it should work on windows.
If you want to work in Unix platform also, you need to change in support\env.rb for Aruba like below
require 'aruba/cucumber'
module ArubaOverrides
def detect_ruby(cmd)
processor, platform, *rest = RUBY_PLATFORM.split("-")
#puts platform
if platform =~ /w32$/ && cmd =~ /^manifesto /
"ruby -I../../lib -S ../../bin/#{cmd}"
else
"#{cmd}"
end
end
end
World(ArubaOverrides)
Hope it helps
You should be aware that Aruba runs the application it tests and creates all local output in its own working directory (awd). The awd defaults to tmp/aruba and is purged and created by Aruba at the beginning of every Scenario. However, the contents created by the last Scenario are left in the awd for your inspection.
Solution #1
Aruba will automatically add the bin directory of your project to the PATH environment variable for the duration of each Cucumber scenario.
You can create a bin dir under your project root, and copy you binaries there
Solution #2
You can use aruba-jbb, which provide a #no-aruba-tmpdir tag to handle this case.

Deploying a Ruby project

I have a finished Ruby project that has the standard structure for a multiple file Ruby program:
project/
lib/ # Files the driver program uses go here.
bin/ # Driver program goes here.
tests/ # Unit tests go here.
What I want to be able to do is type in project into the command line from any directory and have my program run (which means it needs to be in my $PATH). My question is how do I do add a multiple file Ruby project to my PATH so that I can call by name in the terminal? (Or perhaps my approach is wrong, and I should do something else like make it into a Gem? I just don't know what is normally done).
package it as a gem and install that gem. If not and you're on linux then you can set your shebang line to be the right ruby, and chmod to make your script executable, and add your bin dir to your path (or what not).
You could go the quick and dirty route, and write a bash script that calls your main function to run the project, and then stick the bash script over in /usr/bin.

Resources