Displaying 2 results from an estimated 2 matches for "sampletask".
Did you mean:
samplemask
2007 Jan 21
1
A Thread / Mock question
...ith so far:
class TaskRunner
def initialize
@is_running = false
end
def running?
return @is_running
end
def execute(task)
@is_running = true
Thread.new do
task.run
@is_running = false
end
end
end
class SampleTask
def run
end
end
context "The TaskRunner" do
setup do
Thread.stub!(:new).and_return do |block|
block.call
end
@runner = TaskRunner.new
end
specify "should be running when a task is executed" do
task = SampleTask.ne...
2007 Jan 25
0
mocking methods that receive blocks - back to mocking Thread again
...running
end
def execute(task)
@is_running = true
Thread.new(task) do |myTask|
myTask.run
@is_running = false
end
end
end
context "The TaskRunner" do
setup do
@runner = TaskRunner.new
@task = mock(''SampleTask'')
@task.stub!(:run)
Thread.stub!(:new)
end
specify "should not run a task in the main thread" do
@task.should_not_receive(:run)
@runner.execute(@task)
end
specify "should run a task in a new thread" do
Thread.sho...