Forum: Ruby How to get the minitest capture_io method found in my specs?

Posted by Milli Sami (millisami)
on 2012-08-20 09:10
This is my `spec/helper.rb` file:

    require 'minitest/autorun'
    require 'minitest/spec'
    require_relative '../lib/launcher'

    class MiniTest::Spec
      include MiniTest::Assertions
    end

And this is the spec file:

    require 'helper'

    describe Launcher do
      it "should get the stdout" do
        out, err = capture_io do
          warn "You did a bad thing"
        end
        err.should =~ /bad/
      end
    end

But when I run the spec:

    ± rake spec
    /Users/millisami/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec
./spec/launcher_spec.rb -Ispec:lib
    F

    Failures:

      1) Launcher should be a launcher for cloud
         Failure/Error: out, err = capture_io do
         NoMethodError:
           undefined method `capture_io' for
#<RSpec::Core::ExampleGroup::Nested_1:0x000001012a4840>
         # ./spec/launcher_spec.rb:5:in `block (2 levels) in <top
(required)>'

    Finished in 0.00044 seconds
    1 example, 1 failure

    Failed examples:

    rspec ./spec/launcher_spec.rb:4 # launcher should be a launcher for
cloud
    rake aborted!
    /Users/millisami/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec
./spec/launcher_spec.rb -Ispec:lib failed

    Tasks: TOP => spec

But when I do this with the default MiniTest::Unit way, it works?
And why not the spec way?
Posted by Ryan Davis (Guest)
on 2012-08-20 10:05
(Received via mailing list)
On Aug 20, 2012, at 00:10 , Milli Sami <lists@ruby-forum.com> wrote:

> This is my `spec/helper.rb` file:
>
>    require 'minitest/autorun'
>    require 'minitest/spec'
>    require_relative '../lib/launcher'
>
>    class MiniTest::Spec
>      include MiniTest::Assertions
>    end

This isn't necessary. In fact, you only need the autorun and launcher 
lines.

>      end
>    end

I'd start by cleaning up the above. it works for me:

10011 % ruby -Ilib -rminitest/autorun -e 'describe true do it "works" do 
x = capture_io do puts "hi" end; p x end end'
Run options: --seed 27063

# Running tests:

["hi\n", ""]
.

Finished tests in 0.000760s, 1315.7895 tests/s, 0.0000 assertions/s.

1 tests, 0 assertions, 0 failures, 0 errors, 0 skips


If you still can't get it to work, please file a bug. This is no the 
right forum for minitest support.
Posted by Milli Sami (millisami)
on 2012-08-20 12:32
Ryan Davis wrote in post #1072862:
> On Aug 20, 2012, at 00:10 , Milli Sami <lists@ruby-forum.com> wrote:
>
>> This is my `spec/helper.rb` file:
>>
>>    require 'minitest/autorun'
>>    require 'minitest/spec'
>>    require_relative '../lib/launcher'
>>
>>    class MiniTest::Spec
>>      include MiniTest::Assertions
>>    end
>
> This isn't necessary. In fact, you only need the autorun and launcher
> lines.
>
>>      end
>>    end
>
> I'd start by cleaning up the above. it works for me:
>
> 10011 % ruby -Ilib -rminitest/autorun -e 'describe true do it "works" do
> x = capture_io do puts "hi" end; p x end end'
> Run options: --seed 27063
>
> # Running tests:
>
> ["hi\n", ""]
> .
>
> Finished tests in 0.000760s, 1315.7895 tests/s, 0.0000 assertions/s.
>
> 1 tests, 0 assertions, 0 failures, 0 errors, 0 skips
>
>
> If you still can't get it to work, please file a bug. This is no the
> right forum for minitest support.

Well, it works when I run the spec via `ruby spec/...`.
But fails with
`rake`.

Actually I'm running into this with the project I'm trying with
`Hoe`.
Since you said this is not the place for such issue, I've posted
this issue at https://github.com/seattlerb/hoe/issues/30

Can you take a look into that?
Posted by Ryan Davis (Guest)
on 2012-08-21 03:15
(Received via mailing list)
On Aug 20, 2012, at 03:32 , Milli Sami <lists@ruby-forum.com> wrote:

> Actually I'm running into this with the project I'm trying with
> `Hoe`.
> Since you said this is not the place for such issue, I've posted
> this issue at https://github.com/seattlerb/hoe/issues/30
>
> Can you take a look into that?

Fixed and released! Thanks!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.