jeremymcanally-context 0.5 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "context"
3
- s.version = "0.5"
3
+ s.version = "0.5.2"
4
4
  s.date = "2008-10-03"
5
5
  s.summary = "Contexts and DSL sugar for your tests"
6
6
  s.email = "jeremy@entp.com"
@@ -12,6 +12,8 @@ class Test::Unit::TestCase
12
12
  send("before_#{period}_callbacks") << block
13
13
  end
14
14
 
15
+ alias :setup :before
16
+
15
17
  # Add logic to run after the tests (i.e., a +teardown+ method)
16
18
  #
17
19
  # after do
@@ -21,6 +23,8 @@ class Test::Unit::TestCase
21
23
  def after(period = :each, &block)
22
24
  send("after_#{period}_callbacks") << block
23
25
  end
26
+
27
+ alias :teardown :after
24
28
 
25
29
  def gather_callbacks(callback_type, period) # :nodoc:
26
30
  callbacks = superclass.respond_to?(:gather_callbacks) ? superclass.gather_callbacks(callback_type, period) : []
@@ -41,13 +45,15 @@ class Test::Unit::TestCase
41
45
  child.after_all_callbacks = []
42
46
 
43
47
  child.class_eval do
44
- def setup
48
+ def setup(&block)
45
49
  super
50
+
46
51
  run_each_callbacks :before
47
52
  end
48
53
 
49
54
  def teardown
50
55
  super
56
+
51
57
  run_each_callbacks :after
52
58
  end
53
59
  end
@@ -2,7 +2,7 @@ module Context
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- TINY = 0
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -25,7 +25,7 @@ class TestLifecycle < Test::Unit::TestCase
25
25
  sample_test = context "lifecycle" do
26
26
  attr_reader :inherited_before_each_var, :inherited_before_each_var_2, :inherited_after_each_var,
27
27
  :after_each_var, :inherited_before_all_var, :inherited_after_all_var, :before_all_var, :after_all_var,
28
- :superclass_before_each_var, :superclass_after_each_var, :superclass_before_all_var, :superclass_after_all_var
28
+ :superclass_before_each_var, :superclass_after_each_var, :superclass_before_all_var, :superclass_after_all_var, :one, :two
29
29
 
30
30
  before do
31
31
  @inherited_before_each_var = 3
@@ -127,4 +127,38 @@ class TestLifecycle < Test::Unit::TestCase
127
127
  assert_equal 1, @test.after_all_var
128
128
  end
129
129
  end
130
+
131
+ # Test that we aren't stomping on defined seutp method
132
+ context "With setup/teardown methods" do
133
+ before do
134
+ @result = Test::Unit::TestResult.new
135
+ @test = sample_test.new("test_lifecycle_foo")
136
+
137
+ @test.class.setup do
138
+ @one = 1
139
+ end
140
+
141
+ @test.class.teardown do
142
+ @two = 10
143
+ end
144
+
145
+ @test.run(@result) { |inherited_after_each_var, v| }
146
+ end
147
+
148
+ it "runs setup method block a la Shoulda" do
149
+ assert_equal 1, @test.one
150
+ end
151
+
152
+ it "runs setup method block and regular callbacks" do
153
+ assert_equal 3, @test.inherited_before_each_var
154
+ end
155
+
156
+ it "runs teardown method block a la Shoulda" do
157
+ assert_equal 10, @test.two
158
+ end
159
+
160
+ it "runs teardown method block and regular callbacks" do
161
+ assert_equal 1, @test.after_each_var
162
+ end
163
+ end
130
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremymcanally-context
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.5"
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy McAnally