File: rspec_spec.rb

package info (click to toggle)
ruby-em-spec 0.2.6-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 156 kB
  • ctags: 96
  • sloc: ruby: 500; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 1,725 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require File.dirname(__FILE__) + '/../lib/em-spec/rspec'

describe 'Rspec' do
  it 'should work as normal outside EM.describe' do
    1.should == 1
  end
end

describe EventMachine, "when testing with EM::SpecHelper" do
  include EM::SpecHelper
  
  it "should not require a call to done when #em is not used" do
    1.should == 1
  end
  
  it "should have timers" do
    em do
      start = Time.now

      EM.add_timer(0.5) {
        (Time.now - start).should be_within(0.1).of(0.5)
        done
      }
    end
  end
end

describe EventMachine, "when testing with EM::Spec" do
  include EM::Spec
  
  it 'should work' do
    done
  end

  it 'should have timers' do
    start = Time.now
    
    EM.add_timer(0.5) {
      (Time.now - start).should be_within(0.5).of(0.5)
      done
    }
  end

  it 'should have periodic timers' do
    num = 0
    start = Time.now
    
    timer = EM.add_periodic_timer(0.5) {
      if (num += 1) == 2
        (Time.now - start).should be_within(1).of(0.5)
        EM.__send__ :cancel_timer, timer
        done
      end
    }
  end

  it 'should have deferrables' do
    defr = EM::DefaultDeferrable.new
    defr.timeout(1)
    defr.errback{
      done
    }
  end
    
end

describe EventMachine, "when testing with EM::Spec with a maximum execution time per test" do

  include EM::Spec

  default_timeout 4

  it 'should timeout before reaching done' do
    EM.add_timer(3) {
      done
    }
  end

  it 'should timeout before reaching done' do
    timeout(4)
    EM.add_timer(3) {
      done
    }
  end

end

describe "Rspec", "when running an example group after another group that uses EMSpec " do
  it "should work normally" do
    :does_not_hang.should_not be_false
  end
end