Forum: IronRuby ScratchPad versus Channel in RubySpec

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-01-07 09:56
(Received via mailing list)
Many tests use Channel to collect data that needs to be tested. For
example, the following in inspect_spec.rb.

  compliant_on(:ruby) do
    it "reports aborting on a killed thread" do
      c = Channel.new
      t = Thread.new { c << Thread.current.inspect; Thread.stop }
      c.receive.should include('run')
      t.inspect.should include('sleep')
      Thread.critical = true
      t.kill
      t.inspect.should include('aborting')
      Thread.critical = false
    end
  end

However, there is also ScratchPad which serves the same purpose. Why are
there two ways of doing this, and which is the preferred one?

Also, (as we were discussing before), why does every test have to call
ScratchPad.clear before using it. Shouldn't MSpec be doing this
automatically?

Thanks,
Shri
Ade8632553a9243ae05fc920f68644c1?d=identicon&s=25 Jim Deville (Guest)
on 2009-01-07 21:33
(Received via mailing list)
K, ScratchPad clear: MSpec doesn't provide any contracts. It is up to
the user to clear his own state. This also allows for a test to use
ScratchPad across multiple examples. ScratchPad is only meant to be a
formalized global variable.

Channel is actually a part of Rubinius's standard library (IIRC).
Ideally, the tests don't rely on anything more than basic language
features, so we should try to keep usage of Standard Library to a
minimum. I only use stdlib's that are required for MSpec's runner, such
as FileUtils.

JD
From: Shri Borde
Sent: Wednesday, January 07, 2009 12:32 AM
To: Jim Deville
Cc: ironruby-core@rubyforge.org
Subject: ScratchPad versus Channel in RubySpec

Many tests use Channel to collect data that needs to be tested. For
example, the following in inspect_spec.rb.

  compliant_on(:ruby) do
    it "reports aborting on a killed thread" do
      c = Channel.new
      t = Thread.new { c << Thread.current.inspect; Thread.stop }
      c.receive.should include('run')
      t.inspect.should include('sleep')
      Thread.critical = true
      t.kill
      t.inspect.should include('aborting')
      Thread.critical = false
    end
  end

However, there is also ScratchPad which serves the same purpose. Why are
there two ways of doing this, and which is the preferred one?

Also, (as we were discussing before), why does every test have to call
ScratchPad.clear before using it. Shouldn't MSpec be doing this
automatically?

Thanks,
Shri
This topic is locked and can not be replied to.