File: minitest_hooks_direct_spec.rb

package info (click to toggle)
ruby-minitest-hooks 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 156 kB
  • sloc: ruby: 600; makefile: 4
file content (113 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require './spec/helper'
require 'minitest/hooks'

NDB = Sequel.connect(DATABASE_URL)

Minitest::Spec.register_spec_type(/no_default/, Minitest::Spec)

describe 'Minitest::Hooks with transactions/savepoints no_default' do
  include Minitest::Hooks

  before(:all) do
    @ds_ba = @ds_aa
    @ds_ba.count.must_equal 1 + @i
  end
  before do
    @ds_be = @ds_ae
    @ds_be.count.must_equal 2 + @i * 2
  end
  after do
    @ds_be.count.must_equal 2 + @i * 2
  end
  after(:all) do
    @ds_ba.count.must_equal 1 + @i
  end
  around do |&block|
    @ds_aa.count.must_equal 1 + @i
    NDB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
      @ds_ae = @ds_aa
      @ds_ae.insert(1)
      super(&block)
    end
    @ds_aa.count.must_equal 1 + @i
  end
  around(:all) do |&block|
    @i ||= 0
    NDB.transaction(:rollback=>:always) do
      NDB.create_table(:a){Integer :a}
      @ds_aa = NDB[:a]
      @ds_aa.count.must_equal 0
      @ds_aa.insert(1)
      super(&block)
    end
    NDB.table_exists?(:a).must_equal false
  end

  3.times do |i|
    it "should work try #{i}" do
      @ds_aa.count.must_equal 2
      @ds_ae.count.must_equal 2
      @ds_ba.count.must_equal 2
      @ds_be.count.must_equal 2
    end
  end

  describe "in nested describe" do
    before(:all) do
      @ds_ba3 = @ds_ba
      @ds_ba2 = @ds_aa2
      @ds_ba2.count.must_equal 2
    end
    before do
      @ds_be3 = @ds_be
      @ds_be2 = @ds_ae2
      @ds_be2.count.must_equal 4
    end
    after do
      @ds_be2.count.must_equal 4
    end
    after(:all) do
      @ds_ba2.count.must_equal 2
    end
    around do |&block|
      @ds_aa.count.must_equal 2
      super() do
        @ds_aa.count.must_equal 3
        @ds_ae3 = @ds_ae
        @ds_ae2 = @ds_aa2
        @ds_ae2.insert(1)
        block.call
        @ds_aa.count.must_equal 4
      end
      @ds_aa.count.must_equal 2
    end
    around(:all) do |&block|
      @i ||= 1
      super() do
        @ds_aa.count.must_equal 1
        @ds_aa2 = @ds_aa
        @ds_aa2.insert(1)
        block.call
        @ds_aa.count.must_equal 2
      end
      NDB.table_exists?(:a).must_equal false
    end

    3.times do |i|
      it "should work try #{i}" do
        @ds_aa.count.must_equal 4
        @ds_ae.count.must_equal 4
        @ds_ba.count.must_equal 4
        @ds_be.count.must_equal 4
        @ds_aa2.count.must_equal 4
        @ds_ae2.count.must_equal 4
        @ds_ba2.count.must_equal 4
        @ds_be2.count.must_equal 4
        @ds_ae3.count.must_equal 4
        @ds_ba3.count.must_equal 4
        @ds_be3.count.must_equal 4
      end
    end
  end
end