Sha256: 802c7791a65b094d0b47188f338b3d4212c720fee564d887934c2b92b13494e8

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe Spork::Forker do
  describe ".new" do
    it "runs a block in a fork" do
      $var = "hello world"
      Spork::Forker.new { $var = "booyah" }.result
      $var.should == "hello world"
    end
  end
  
  describe "#result" do
    it "returns the result" do
      Spork::Forker.new { "results" }.result.should == "results"
    end
  end
  
  describe "#running?" do
    it "reports when the fork is running" do
      forker = Spork::Forker.new { sleep 0.1 }
      forker.running?.should == true
      forker.result
      sleep 0.1
      forker.running?.should == false
    end
  end
  
  describe "#abort" do
    it "aborts a fork and returns nil for the result" do
      started_at = Time.now
      ended_at = nil
      forker = Spork::Forker.new { sleep 5 }
      Thread.new do
        forker.result.should == nil
        ended_at = Time.now
      end
      sleep 0.5
      forker.abort
      sleep 0.1
      (ended_at - started_at).should be_close(0.5, 0.1)
      forker.running?.should == false
    end
  end
end unless windows?

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
spork-0.9.0.rc8-x86-mswin32 spec/spork/forker_spec.rb
spork-0.9.0.rc8-x86-mingw32 spec/spork/forker_spec.rb
spork-0.9.0.rc8 spec/spork/forker_spec.rb
spork-0.9.0.rc7 spec/spork/forker_spec.rb
spork-0.9.0.rc6 spec/spork/forker_spec.rb
spork-0.9.0.rc5 spec/spork/forker_spec.rb
spork-0.9.0.rc4 spec/spork/forker_spec.rb
spork-0.9.0.rc3 spec/spork/forker_spec.rb
nimboids-spork-0.8.99 spec/spork/forker_spec.rb
nimboids-spork-0.9.0.rc2 spec/spork/forker_spec.rb
invo-sporknife-0.1.0.1 spec/spork/forker_spec.rb
invo-sporknife-0.1.0 spec/spork/forker_spec.rb
invo-sporknife-0.1.0.pre spec/spork/forker_spec.rb