Building and Testing Command Line Gem on TeamCity - ruby

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.

Related

What is a good way to see output from my ruby gem?

I want to know a good way to run code in my ruby gem (and not just through tests).
That means I want to run ruby lib/{gemname}.rb on the terminal and be able to see some output
So I have this line in my base file:
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
and then I load a file called debugger.rb by requiring it at the bottom of the base file. This file then gives me the output I need.
This works but this kind of clutters my code and I don't want to accidentally commit it and watch it break in production.
So what's a good way of doing this?
My approach for developing and debugging gems has two parts:
1) Always use require_relative to include needed "internal" gem related files. This allows the gem to be loaded up normally when installed as a gem and also in my development environment (ignoring any versions of the gem that may already be installed.)
2) Then use the following snippet of code (usually) at the bottom of the main file, to activate debugging features when the base my_gem.rb file is run explicitly on the command line.
if __FILE__ == $0
#debugging code goes here!
end
With this strategy there's no need to worry about yanking debug code before releasing the gem.

Ruby - watch for file with extension being updated

I am trying to auto compile my less files on centos.
Is it possible in ruby to watch a directory for changes to files ending in a specific extension and then execute a command when that happens?
I have tried inotify in a simple shell script but there are always problems when an ide creates temporary files etc.
You want inotify. A Ruby wrapper, rb-notify, is available.
The ZenTest gem includes the autotest command-line tool, which watches a test directory and runs tests when one of the files changes.
Go look at how that tool works. Using inotify is helpful but not necessary.
The basic idea for this is to write a loop with a sleep inside it. Use Ruby's Find class to locate the files that are candidates for processing. The Find documentation has example code to get that part started.

How execute a self contained rake build?

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

Need help with starting RoR: Command "rails server" does not result in "Booting WEBrick"?

I need help to get started with RoR.
I currently follow this guideline:
http://allaboutruby.wordpress.com/2009/07/20/installing-rails-on-windows-3-years-later/#comment-11099
I followed step 1 through 3 w/o problems.
In step 5: I can get the webserver through WEBrick working.
When i put
"rails server"
instead of getting "Booting Webrick", i get "rails new_path option"
thus when i try 127.0.0.1:3000 in the browser... it does work.
Can anyone guide me on this on how to get it up and runnning? (Im a total newb for now...so i need specific explanations! thanks!)
In your tutorial i can't see the command 'bundle install' - it's checking and installing all necessary gems in your system. So why you don't use another great rails tutorial - http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
I'm guessing you are running windows, on which rails can be a little awkward. You'll probably need to run the rails server command by pointing ruby at the server script. On windows, your rails "commmand" is actually just a .bat file that lives in the /bin file of your ruby installation, and that .bat file just passes the arguments to ruby. If you look at the rails gem that is installed on your machine, you'll see the files that correspond to the normal first argument of a rails command (console, generate, server, etc). You might find it helpful to copy these to the /script directory of your application, and when you want to run a rails command you can just run "ruby script\server" from your application's main directory, though there may be more accepted ways of getting the same result.

how can my gem know the path to its repository directory?

My gem semantictext has a bunch of test data that it reads for regression testing.
Here's the project: http://github.com/dafydd/semantictext
Here's an example test that I want to be able to run directly from the gem: http://github.com/dafydd/semantictext/blob/master/test/test_document.rb (look for text "SANDBOX")
I normally develop it in a directory called "semantictext" and have the environment variable SANDBOX set to the path of the directory above "semantictext" - so that I can reference any file in the project using ENV['SANDBOX'].
When the gem is installed as a package, is there a way that the test/unit test running from rake can:
1) know that it's running from a gem? and
2) know the path to it's semantictext directory within the local rubygems repository?
I want to make it effortless to be able to run all the tests from any gem installation. This would make my continuous integration a bit easier and allow me to write better gems.
Thanks,
Dafydd
You can find out the directory of the current file using:
File.dirname(__FILE__)
This will allow you to build up a relative path to whatever file you need to access.

Resources