#507 √ resolved
Luis Lavena

[PATCH] Fixes MSpec on Windows

Reported by Luis Lavena | April 20th, 2008 @ 04:52 PM | in 1.0 preview

MSpec fail on some specs and some matchers in Windows. The attached patches fixes that.

Comments and changes to this ticket

  • Luis Lavena
  • Brian Ford

    Brian Ford April 21st, 2008 @ 09:01 AM

    While this patch is only for MSpec, it does not uniformly address the issue of temp directories for the ruby specs. We don't want to have stdlib dependencies in the core lib specs, so this solution doesn't translate.

    I don't consider the name of the temp directory to be a platform issue (i.e. there is not really anything in a platform that dictates where you put temp files, there is only a convention). Rather, this is an environment issue.

    Given this, mkdir /tmp is the simplest solution. MSpec specs pass 100% for me on Windows XP with that.

    Another possibility is a helper method something like

    def tmp(name)
      ["/tmp", "/temp"].each do |dir|
        if File.directory? dir
          return File.join dir, name
        end
      end
    end
    

    In the specs you would write

      MSpec.stub!(:tags_file).and_return(tmp("tags.txt"))
    

    The list of directories to test can be expanded. But in general, this solution (and Dir.tmpdir) offer nothing better than mkdir /tmp and are certainly more complex. Granted, making sure you have a /tmp directory requires some setup on Windows, but that can be covered in the README.

    I'd like to hear a good reason not to require that /tmp exist for running MSpec specs and the ruby specs.

  • Luis Lavena

    Luis Lavena April 21st, 2008 @ 02:27 PM

    I agree with you about depending on stdlib stuff. but in first place Dir.tmpdir shouldn't be part of it, but core instead.

    I also agree with you that this patch don't address the issues with Rubyspecs, but I couldn't trust on the results of a testing tool that was failing it's own specs, as I commented on #rubinius when send the patches.

    In any case, put things in /tmp or /temp will generate garbage that will not be traceable or be collected by tools that clean TEMP folders.

    Does Linux/OSX support ENV['TEMP'] or similar? if so, we can put into the MSpec helper tmp(name) and lookup for /tmp, /temp and ENV['TEMP'], something like Dir: is doing.

    Please let me know and I'll provide the required patches for you to review.

  • Luis Lavena

    Luis Lavena April 21st, 2008 @ 03:02 PM

    Also, forgot to add in the previous comment, how we should tackle file operations that are related to binary/ascii operations?

    On example is getc and ungetc. They work ok under *nix but unless you state 'b' (binary mode) when opening the file, it will not work on Windows.

    What we should do in this case in the specs? conditionally guard the before blocks, or provide specs that make File/IO operation ignores 'b' mode on any platforms that doesn't support it? (Like currently MRI does).

    Thanks for your time.

  • Brian Ford

    Brian Ford April 22nd, 2008 @ 12:55 AM

    I understand your points. It makes sense to add a helper for this to make it easier for an implementation to override if necessary. Since we have the guards in mspec, I'm going to add a directory for helpers there as well. So far, we have bignum_value helper and this one. I like the tmp("file.txt") syntax; what do you think?

    Regarding the binary mode for Windows, I would put separate before blocks wrapped in platform_is guards. If a whole set of behaviors is involved, you could even do a different describe block; something like:

    platform_is :mswin do
      describe "IO#foo on Windows" do
        # ...
      end
    end
    

    BTW, it would be simple to extend the platform_is guard to accept something like :windows to stand for a whole family of implementations on Windows, Linux/UNIX, etc.

    I'll commit the tmp() helper and related stuff sometime today if there are no objections.

  • Luis Lavena

    Luis Lavena April 22nd, 2008 @ 11:24 AM

    +1 for tmp(name) helper. No objections and that will make our life (anyone providing fixes for Rubyspecs) more easy.

    platform_is sounds good too, since we are pushing a new One-Click Installer based completely in MinGW (GCC) and that simple change will break lot of specs.

    Regarding the IO behaviors, when this get's updated, I'll look into the specs and see to add a few ones that describe the binary mode behavior.

    Linux/*nix doesn't care of 'b' mode was supplied for read/write operations, so the same must go for rubinius.

    Thank you for your time and positve look at this stuff.

  • Ryan Davis

    Ryan Davis April 29th, 2008 @ 04:45 PM

    • → Assigned user changed from “” to “Brian Ford”
  • Brian Ford

    Brian Ford April 29th, 2008 @ 05:59 PM

    • → State changed from “new” to “resolved”

    The #tmp helper was added to MSpec in 7243309. It's been modified since then but seems to be working well. Closing this ticket. Please reopen if necessary.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket