Journeymandev's Notebook

General ramblings, things I don't want to forget, and an occasional rant.
Rails, Growl and Windows?

Lately I have been developing Rails apps in Windows. Don’t judge. During that time I tried multiple installation techniques from RVM in Cygwin, Ruby Installer to JRuby. The clear winner, at least for me, was JRuby. Since I like the way JRuby has been treating me, I thought I would do a high level post documenting my setup. I make the assumption that you are familiar with Ruby and Rails, and that you have enough experience to install Java and supporting applications.

Environment

As of this writing I use Windows 7 (64 bit) Professional, Java 1.7.0 (64 bit), JRuby 1.6.5, and Rails 3.1.1 but I believe these steps will be applicable for varying configurations. To get started developing in Ruby or Rails on Windows, we will need to download and install the following programs.

Java

The “J” in “JRuby” means Java. We need to download and install the flavor of JDK (32 bit or 64 bit) that is appropriate for our system.

JRuby

"JRuby is a 100% Java implementation of the Ruby programming language. It is Ruby for the JVM." That pretty much sums it up. Visit the JRuby site for the benefits of using JRuby over other implementations. My reason for using JRuby is that in my Windows experience JRuby executes faster than MRI. Installation is painless with the provided installer. Be sure to check the box to “add paths to your environment”.

Growl

Does watching the Railscasts, or Peep Code screen casts make you jealous of their Growl notifications? No more! Growl is available for windows now. When used in combination with autotest and autotest-growl it is an indispensable tool for easily tracking the status of our unit tests. Go ahead download and install Growl now.

Developing

Once we have completed installation of Java, JRuby and Growl, we can begin setting up our application.

Open up a command prompt and install the Rails gem. I already had Rails installed so do not be surprised to see gem automatically install other dependecies. Notice that in JRuby commands are preceded with a ‘j’ so instead of ruby, gem, irb we will use jruby, jgem, jirb.


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\nate>jgem install rails
Successfully installed rails-3.1.1
1 gem installed

C:\Users\nate>

Now all we have to do is create our Rails app. Please note the -S argument to the jruby command. This is the recommended way to run jruby commands as documented here.

C:\Users\nate>jruby -S rails new testapp

At this point Rails will produce lines describing the creation of directories and files. Rails will also call Bundler and install those gems required by Gemfile.

Now we have a working Rails app. Just cd into the directory and run it!


C:\Users\nate>cd testapp

C:\Users\nate\testapp>jruby -S rails s
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-10 18:16:03] INFO  WEBrick 1.3.1
[2011-11-10 18:16:03] INFO  ruby 1.9.2 (2011-10-25) [java]
[2011-11-10 18:16:03] INFO  WEBrick::HTTPServer#start: pid=5348 port=3000

Point the browser to http://0.0.0.0:3000 to view the default rails app in action. To stop the server issue Ctrl-C twice. Proceed to setting up autotest!

Growl & Autotest

Here comes the fun part. The default install of Growl is all we need. So the only Growl configuration we have to do is to choose a notification theme, which I will leave for you. We just need to make sure Growl is running after we have installed it. Check for a claw in the system tray.

To get Growl notifications for autotest we need to install some supporting gems. Add the following lines to the Gemfile and run bundle install. I use rspec so I include rspec and rspec-rails to the Gemfile.


gem 'rspec'
gem 'rspec-rails'
gem 'autotest'
gem 'autotest-notification'
gem 'autotest-growl'
gem 'autotest-rails'

Tell autotest that we wish to use autotest-growl. In the .autotest file in the root directory of our application, add the following line.

reqiure 'autotest/growl'

Install rspec using the generator.


C:\Users\nate\testapp>jruby -S rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb


Now we will create an ‘article’ model using scaffolding.


C:\Users\nate\testapp>jruby -S rails g model article
      invoke  active_record
      create    db/migrate/20111111005801_create_articles.rb
      create    app/models/article.rb
      invoke    rspec
      create      spec/models/article_spec.rb


Thats it! Run autotest! Below is the console output with the deprecation and console color warnings removed.


C:\Users\nate\testapp>jruby -S autotest
loading autotest/rails_rspec2

--------------------------------------------------------------------------------

Pending:
  Article add some examples to (or delete) C:/Users/nate/testapp/spec/models/article_spec.rb
    # Not Yet Implemented
    # ./spec/models/article_spec.rb:4

Finished in 14.88 seconds
1 example, 0 failures, 1 pending


If everything went well, we should see an application registration notification and a test result notification from Growl. Happy testing!

Rails, Growl and Windows?

Lately I have been developing Rails apps in Windows. Don’t judge. During that time I tried multiple installation techniques from RVM in Cygwin, Ruby Installer to JRuby. The clear winner, at least for me, was JRuby. Since I like the way JRuby has been treating me, I thought I would do a high level post documenting my setup. I make the assumption that you are familiar with Ruby and Rails, and that you have enough experience to install Java and supporting applications.

Environment

As of this writing I use Windows 7 (64 bit) Professional, Java 1.7.0 (64 bit), JRuby 1.6.5, and Rails 3.1.1 but I believe these steps will be applicable for varying configurations. To get started developing in Ruby or Rails on Windows, we will need to download and install the following programs.

Java

The “J” in “JRuby” means Java. We need to download and install the flavor of JDK (32 bit or 64 bit) that is appropriate for our system.

JRuby

"JRuby is a 100% Java implementation of the Ruby programming language. It is Ruby for the JVM." That pretty much sums it up. Visit the JRuby site for the benefits of using JRuby over other implementations. My reason for using JRuby is that in my Windows experience JRuby executes faster than MRI. Installation is painless with the provided installer. Be sure to check the box to “add paths to your environment”.

Growl

Does watching the Railscasts, or Peep Code screen casts make you jealous of their Growl notifications? No more! Growl is available for windows now. When used in combination with autotest and autotest-growl it is an indispensable tool for easily tracking the status of our unit tests. Go ahead download and install Growl now.

Developing

Once we have completed installation of Java, JRuby and Growl, we can begin setting up our application.

Open up a command prompt and install the Rails gem. I already had Rails installed so do not be surprised to see gem automatically install other dependecies. Notice that in JRuby commands are preceded with a ‘j’ so instead of ruby, gem, irb we will use jruby, jgem, jirb.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\nate>jgem install rails
Successfully installed rails-3.1.1
1 gem installed

C:\Users\nate>

Now all we have to do is create our Rails app. Please note the -S argument to the jruby command. This is the recommended way to run jruby commands as documented here.

C:\Users\nate>jruby -S rails new testapp

At this point Rails will produce lines describing the creation of directories and files. Rails will also call Bundler and install those gems required by Gemfile.

Now we have a working Rails app. Just cd into the directory and run it!

C:\Users\nate>cd testapp

C:\Users\nate\testapp>jruby -S rails s
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-10 18:16:03] INFO  WEBrick 1.3.1
[2011-11-10 18:16:03] INFO  ruby 1.9.2 (2011-10-25) [java]
[2011-11-10 18:16:03] INFO  WEBrick::HTTPServer#start: pid=5348 port=3000

Point the browser to http://0.0.0.0:3000 to view the default rails app in action. To stop the server issue Ctrl-C twice. Proceed to setting up autotest!

Growl & Autotest

Here comes the fun part. The default install of Growl is all we need. So the only Growl configuration we have to do is to choose a notification theme, which I will leave for you. We just need to make sure Growl is running after we have installed it. Check for a claw in the system tray.

To get Growl notifications for autotest we need to install some supporting gems. Add the following lines to the Gemfile and run bundle install. I use rspec so I include rspec and rspec-rails to the Gemfile.

gem 'rspec'
gem 'rspec-rails'
gem 'autotest'
gem 'autotest-notification'
gem 'autotest-growl'
gem 'autotest-rails'

Tell autotest that we wish to use autotest-growl. In the .autotest file in the root directory of our application, add the following line.

reqiure 'autotest/growl'

Install rspec using the generator.

C:\Users\nate\testapp>jruby -S rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb

Now we will create an ‘article’ model using scaffolding.

C:\Users\nate\testapp>jruby -S rails g model article
      invoke  active_record
      create    db/migrate/20111111005801_create_articles.rb
      create    app/models/article.rb
      invoke    rspec
      create      spec/models/article_spec.rb

Thats it! Run autotest! Below is the console output with the deprecation and console color warnings removed.

C:\Users\nate\testapp>jruby -S autotest
loading autotest/rails_rspec2

--------------------------------------------------------------------------------

Pending:
  Article add some examples to (or delete) C:/Users/nate/testapp/spec/models/article_spec.rb
    # Not Yet Implemented
    # ./spec/models/article_spec.rb:4

Finished in 14.88 seconds
1 example, 0 failures, 1 pending

If everything went well, we should see an application registration notification and a test result notification from Growl. Happy testing!