running_man 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/running_man.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
2
2
 
3
3
  module RunningMan
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
 
6
6
  # Public: Sets up any helper class methods in TestClassMethods on the
7
7
  # specified test case class.
@@ -42,4 +42,4 @@ module RunningMan
42
42
  autoload :ActiveRecordBlock, 'running_man/active_record_block'
43
43
  end
44
44
 
45
- require 'running_man/block'
45
+ require 'running_man/block'
@@ -6,30 +6,20 @@ module RunningMan
6
6
  # See README for instructions on use.
7
7
  class ActiveRecordBlock < Block
8
8
  module TestClassMethods
9
+ # Runs this block once, which should insert records through ActiveRecord.
10
+ # Test Cases should only have one #fixtures call, and it should be at the
11
+ # first run callback.
9
12
  def fixtures(&block)
10
- test_block = RunningMan::ActiveRecordBlock.new(block)
11
- active_record_fixtures_setup(test_block)
12
- active_record_fixtures_teardown
13
- end
14
-
15
- def active_record_fixtures_setup(test_block)
16
- setup do
17
- test_block.run(self)
18
- # Open a new transaction before running any test.
19
- ActiveRecord::Base.connection.increment_open_transactions
20
- ActiveRecord::Base.connection.begin_db_transaction
21
- end
13
+ RunningMan::ActiveRecordBlock.new(block).setup(self)
22
14
  end
15
+ end
23
16
 
24
- def active_record_fixtures_teardown
25
- teardown do
26
- # Rollback our transaction, returning our fixtures to a pristine
27
- # state.
28
- ActiveRecord::Base.connection.rollback_db_transaction
29
- ActiveRecord::Base.connection.decrement_open_transactions
30
- ActiveRecord::Base.clear_active_connections!
31
- end
32
- end
17
+ # Ensure the block is setup to run first, and that the test run is wrapped
18
+ # in a database transaction.
19
+ def setup(test_class)
20
+ block = self
21
+ test_class.setup { block.run(self) }
22
+ test_class.teardown { block.teardown_transaction }
33
23
  end
34
24
 
35
25
  # Clear the database before running the block.
@@ -38,6 +28,25 @@ module RunningMan
38
28
  super
39
29
  end
40
30
 
31
+ # Sets up an ActiveRecord transition before every test.
32
+ def run(binding)
33
+ super
34
+ setup_transaction
35
+ end
36
+
37
+ # Open a new transaction before running any test.
38
+ def setup_transaction
39
+ ActiveRecord::Base.connection.increment_open_transactions
40
+ ActiveRecord::Base.connection.begin_db_transaction
41
+ end
42
+
43
+ # Rollback our transaction, returning our fixtures to a pristine state.
44
+ def teardown_transaction
45
+ ActiveRecord::Base.connection.rollback_db_transaction
46
+ ActiveRecord::Base.connection.decrement_open_transactions
47
+ ActiveRecord::Base.clear_active_connections!
48
+ end
49
+
41
50
  # reload any AR instances
42
51
  def set_ivar(binding, ivar, value)
43
52
  if value.class.respond_to?(:find)
@@ -53,4 +62,4 @@ module RunningMan
53
62
  end
54
63
  end
55
64
  end
56
- end
65
+ end
@@ -1,10 +1,9 @@
1
1
  module RunningMan
2
2
  class Block
3
3
  module TestClassMethods
4
- # Runs the given block
4
+ # Runs the given block
5
5
  def setup_once(&block)
6
- test_block = RunningMan::Block.new(block)
7
- setup { test_block.run(self) }
6
+ RunningMan::Block.new(block).setup(self)
8
7
  end
9
8
 
10
9
  def teardown_once(&block)
@@ -26,7 +25,19 @@ module RunningMan
26
25
  end
27
26
  end
28
27
 
29
- # Public: This is what is run in the test/unit callback. #run_once is
28
+ # Public: Makes sure the test case class runs this block first. By default,
29
+ # This is added as a single #setup callback. Override this method if the
30
+ # underlying TestCase #setup implementation varies.
31
+ #
32
+ # test_class - A class inheriting from Test::Unit::TestCase
33
+ #
34
+ # Returns nothing.
35
+ def setup(test_class)
36
+ block = self
37
+ test_class.setup { block.run(self) }
38
+ end
39
+
40
+ # Public: This is what is run in the test/unit callback. #run_once is
30
41
  # called only the first time, and #run_always is always called.
31
42
  #
32
43
  # binding - Object that is running the test (usually a Test::Unit::TestCase).
@@ -112,4 +123,4 @@ if defined?(Test::Unit::TestSuite) && defined?(Test::Unit::TestCase)
112
123
  end
113
124
  end
114
125
  end
115
- end
126
+ end
data/running_man.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'running_man'
16
- s.version = '0.2.1'
17
- s.date = '2010-05-03'
16
+ s.version = '0.3.0'
17
+ s.date = '2011-07-13'
18
18
  s.rubyforge_project = 'running_man'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: running_man
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
4
+ version: 0.3.0
10
5
  platform: ruby
11
6
  authors:
12
7
  - rick
@@ -14,7 +9,7 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-05-03 00:00:00 -07:00
12
+ date: 2011-07-13 00:00:00 -07:00
18
13
  default_executable:
19
14
  dependencies: []
20
15
 
@@ -51,20 +46,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
46
  requirements:
52
47
  - - ">="
53
48
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
49
  version: "0"
50
+ version:
57
51
  required_rubygems_version: !ruby/object:Gem::Requirement
58
52
  requirements:
59
53
  - - ">="
60
54
  - !ruby/object:Gem::Version
61
- segments:
62
- - 0
63
55
  version: "0"
56
+ version:
64
57
  requirements: []
65
58
 
66
59
  rubyforge_project: running_man
67
- rubygems_version: 1.3.6
60
+ rubygems_version: 1.3.5
68
61
  signing_key:
69
62
  specification_version: 2
70
63
  summary: Simple class for test/unit setup blocks that run just once.