# ScratchPad versus Channel in RubySpec

**URL:** <https://www.ruby-forum.com/t/scratchpad-versus-channel-in-rubyspec/157090>\
**Category:** IronRuby\
**Created:** [January 7, 2009, 9:56am UTC](https://www.ruby-forum.com/t/scratchpad-versus-channel-in-rubyspec/157090 "2009-01-07T09:56:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [January 7, 2009, 9:56am UTC](https://www.ruby-forum.com/t/scratchpad-versus-channel-in-rubyspec/157090/1 "2009-01-07T09:56:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [January 7, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/scratchpad-versus-channel-in-rubyspec/157090/2 "2009-01-07T21:33:35Z")

</div>

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 B.  
Sent: Wednesday, January 07, 2009 12:32 AM  
To: Jim D.  
Cc: removed\_email\_address@domain.invalid  
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
