DISQUS

Chris Pratt: Rails, RSpec, Autotest, Redgreen, and Snarl: Reasons I don’t like Windows

  • Chris · 2 years ago
    I am also at the ready to abandon Windows for rails development for the same reason. I've spent 3 days trying to get this setup working and I'm not even this far. I can't even get autotest to run. When I try I get an error that makes it seem like autotest can't find my test files even though they are there and running "rake test" works perfectly.

    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.
  • Chris Pratt · 2 years ago
    Since, I wrote this post, I revisited setting up my Windows environment one last time (I purchased e-Text Editor, a TextMate clone for windows, and would love to be able to actually use it). This time, however, I approached it from a different standpoint, using Cygwin.

    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.
  • weyus · 2 years ago
    Hmmm. I see the same thing. What I notice is that autotest --rails and rake spec are clearly not doing the same thing. While I am on the verge of buying a Mac anyway because my system is so fscking slow, I'd like to try and power through this because it feels like it should be debuggable. I'll post any findings.
  • weyus · 2 years ago
    I discovered that my autotest was not actually running the specs because of a problem with the way that they were being called. That is, if I ran autotest, it would construct appropriate spec commands but they they wouldn't actually be run. Running the exact same spec command in a command window would work fine.

    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.
  • Wes Gamble · 2 years ago
    The bug is in autotest, in a method that it uses to construct the path to the ruby executable.
  • Jamal · 2 years ago
    Same goes here,

    I get too many errors when I tried to get autotest to run on Windows.
  • Vitor · 2 years ago
    One more to hate windows and autotest (not) working together.
  • darelf · 2 years ago
    i succeeded in having colored autotest output and snarl popups in Windows (not cygwin) with next raugh steps:

    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
  • Chris Foley · 1 year ago
    Looks like in rspec 1.1.1, darelf's hack to base_text_formatter.rb has been moved to .\vendor\plugins\rspec\lib\spec\runner\options.rb around line 104
  • Thomas G. · 1 year ago
    Hi,

    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...
  • vknightbd · 1 year ago
    I also managed to hack it so that I got colored autotest and snarl to work outside of cygwin for rspec-1.1.4, zentest-3.9.2, win32console-1.0.8

    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
  • Anlek · 1 year ago
    vknightbd had the right idea, but my snarl worked fine as is, the only thing I had to do based on what he wrote was:
    -----
    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.
  • Bryan · 1 year ago
    Following the example above, to get autotest to output with color, without hacking released files:
    —–
    I put the following in my .autotest:
    require 'Win32/Console/ANSI'
    —–
    I never had any issues getting autotest or snarl to work.
  • zaj · 11 months ago
    I've followed tips here and on other sites and I still always end up with the following when I run the autotest cmd:

    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?