Kilon
Kilon

Reputation: 2002

How to import code from Workspace to a method from inside Workspace

I want to send code from my workspace to a method. This means create the class and then the method without ever leaving the workspace or using the Browser. Is this possible and if yes how ?

Can I do the same for creating tests ?

Upvotes: 1

Views: 135

Answers (1)

MartinW
MartinW

Reputation: 5041

Try this in a workspace:

|myClass myTest|

myClass := Object subclass: #MyClass
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'GeneratedInAWorkspace'.

myClass compile: 'foo ^ 10'.

myTest := TestCase subclass: #MyClassTest
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'GeneratedInAWorkspace'.

myTest compile: 'testFoo self assert: (Smalltalk at: #MyClass) new foo = 10'.
myTest run: #testFoo "prints: 1 run, 1 passes, 0 skipped, 0 expected failures, 0 failures, 0 errors, 0 unexpected passes"

Upvotes: 3

Related Questions