-
Website
http://www.chrisdpratt.com -
Original page
http://www.chrisdpratt.com/2007/09/04/rails-rspec-autotest-redgreen-and-snarl-reasons-i-dont-like-windows/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
Shane Sponagle
1 comment · 3 points
-
Chris Pratt
21 comments · 1 points
-
ibrahimahmed
1 comment · 1 points
-
robbykeller
1 comment · 1 points
-
besman
1 comment · 1 points
-
-
Popular Threads
I uninstalled everything and started with ruby 1.8.6 and installed the same versions of everything else you are using here. I execute "rails test_site" then "ruby script/generate scaffold person" to get some test files and when I run autotest I get the following.
loading autotest/rails
c:\ruby\bin\ruby -I.;lib;test -rtest/unit -e "%w[test/unit/person_test.rb].each { |f| require f }" | unit_diff -u
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- test/unit/person_test.rb (LoadError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from -e:1
from -e:1:in `each'
from -e:1
I'm pleading with my boss to get me a mac, I even told him I would come in and set it up on the weekend, but if that proves fruitless, I would at least like to get autotest working even if I can't have nice gui notifications or colored text.
With Cygwin, I am able to have autotest happily running my specs with colored output. The only thing missing is Snarl integration, but 1) I'm not sure if it's even possible to integrate Snarl with Cygwin and 2) I'm not sure where to begin if it is.
Nevertheless, this has allowed me to productively use Windows for Rails development, for the most part. Everything still runs slower than in Linux and OSX, but having TextMate like functionality makes up for that.
Anyways, since others seem to be having the same issues setting up Cygwin properly can be a bit tricky, I think I'll be posting about it real quick here. I'll try to get something out tonight or tomorrow.
Turns out the command to run the spec commands looks like:
c:\ruby\bin\ruby -S script/spec --options spec/spec.opts spec/helpers/admin_hel
per_spec.rb spec/models/evaluation_request_spec.rb spec/models/right_spec.rb spe
c/controllers/admin_controller_spec.rb spec/models/person_spec.rb
In autotest.rb line 209 (ZenTest 3.6.1), we see:
open("| #{cmd}", "r") do |f| ...
This is how autotest actually executes the spec command. Turns out that the single \ characters will causes this command to fail. Testing with irb, I found that changing the \ to / or escaping the \ with another \ would allow this to work.
I don't know yet whether this is a bug in autotest or whether autotest is relying on something lower level to generate the path to the ruby executable. But either way the command needs to be constructed in such a way that it can be executed.
I will post anything more if I find it here.
I get too many errors when I tried to get autotest to run on Windows.
content for .\.autotest
require ‘autotest/snarl’
content for .\ansipipe.rb
require 'rubygems'
require 'win32console'
@io = Win32::Console::ANSI::IO.new()
until $stdin.eof? do
line = $stdin.gets
@io.puts line
end
@io.flush
in .\vendor\plugins\rspec\lib\spec\runner\formatter\base_text_formatter.rb hack method colour=
def colour=(colour)
@colour = colour
# winhack
# begin
# require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/
# rescue LoadError ;
# raise "You must gem install win32console to use colour on Windows"
# end
end
`snarl` must be installed.
Gems: `win32console`, `diff-lcs`, `ruby-snarl` must be installed.
`Redgreen` gem is not needed.
`ruby` and `rake` must be included in $PATH
run autotest from the root of project in command line as:
autotest | ruby ansipipe.rb
not delicate but it works for me
Using rSpec and Zentest as of today's version, I am having the same problems: no color in the shell, and snarl telling me that all tests pass when they do not... And moreover the tests are quite slow compared to OSX or Linux boxes...
change the require in line 130 from 'rubygems' to 'RubyGems' in rspec-1.1.4\lib\spec\runner\options.rb (not sure if this is significant)
add the following to the top of ZenTest-3.9.2\lib\autotest.rb (for color)
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
Snarl is broken since ZenTest is not parsing Rspec's output correctly.
replace the following regex in the initialize method in autotest.rb to match the Rspec output.
self.completed_re = /\d+ examples(, \d+ failures)?(, \d+ pending)?/
self.failed_results_re = /^\s*\d+\)\s*[^\n]*(?:Failed|Error)[^\n]*\n([^\n]*)\n([^\n]*):\d+:/i #ugly
replace the consolidate_failures method in autotest.rb (or in my case, merb_rspec.rb) to use the new array generated by the above failed_results_re.
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each{|error_message, spec_file| filters[spec_file] << error_message}
return filters
end
I also made some extra changes to ZenTest-3.9.2\lib\autotest\snarl.rb and modified the red hook and added an all_good hook.
Autotest.add_hook :red do |at|
failed_tests = at.files_to_test.inject(0){ |s,a| k,v = a; s + v.size}
failed_files = at.files_to_test.size
snarl "Tests Failed", "#{failed_tests} tests failed of #{failed_files} specs tested.", :red
end
Autotest.add_hook :all_good do |at|
snarl "All Tests Passed", "Tests have fully passed", :green
end
-----
add the following to the top of ZenTest-3.9.2\lib\autotest.rb (for color)
require ‘Win32/Console/ANSI’ if RUBY_PLATFORM =~ /win32/
-----
Doing the first step with the rubygem actually created 3 errors when running auto test (saying that rubygem was already included or something like that)
and I didn't do the bottom two steps because like I said, snarl was working fine for me.
—–
I put the following in my .autotest:
require 'Win32/Console/ANSI'
—–
I never had any issues getting autotest or snarl to work.
loading autotest/rails
and then it hangs up.
I've also tried "autotest | ruby ansipipe.rb" as suggested above. I dont get the loading msg, but it still just seems to hang.
I'm on Vista and running rails 1.2.6... does anybody have any odeas?