fas_test 0.0.7 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -8,8 +8,11 @@ structure your project, instead, simple naming conventions are used:
8
8
  Other things you need to know:
9
9
 
10
10
  - All test classes should inherit FasTest::TestClass
11
- - Your test class can define "setup" and/or "teardown" methods. They do what
12
- it sounds like they do.
11
+ - There are two setup and two teardown methods:
12
+ - class_setup: Called once before any of the tests
13
+ - class_teardown: Called once after any of the tests
14
+ - test_setup: Called before each test
15
+ - test_teardown: Called after each test
13
16
 
14
17
  Take a look in the test folder to see an example of how the library is used.
15
18
  (fas_test is used to test itself).
data/bin/fastest CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'lib/fas_test'
3
+ require 'fas_test'
4
4
 
5
5
  test_runner = FasTest::TestRunner.new
6
6
  test_runner.run_tests_in_folder(".")
data/fas_test.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "fas_test"
3
- s.version = "0.0.7"
3
+ s.version = "0.1.4"
4
4
  s.authors = ["Graeme Hill"]
5
5
  s.email = "graemekh@gmail.com"
6
6
  s.homepage = "https://github.com/graeme-hill/fas_test"
data/lib/fas_test.rb CHANGED
@@ -14,8 +14,23 @@ module FasTest
14
14
 
15
15
  def run_tests_in_class(test_class)
16
16
  test_instance = init_test_instance(test_class)
17
- get_all_test_method_names(test_class).each do |test_method_name|
18
- run_test(test_instance, test_method_name)
17
+ begin
18
+ setup_failed = false
19
+ begin
20
+ test_instance.class_setup
21
+ rescue Object => ex
22
+ puts "Superfail: Crashed when running #{test_class.name}::class_setup"
23
+ puts " -> #{ex.class.name}: #{ex.message}"
24
+ pretty_print_stack_trace(ex)
25
+ setup_failed = true
26
+ end
27
+ unless setup_failed
28
+ get_all_test_method_names(test_class).each do |test_method_name|
29
+ run_test(test_instance, test_method_name)
30
+ end
31
+ end
32
+ ensure
33
+ test_instance.class_teardown
19
34
  end
20
35
  end
21
36
 
@@ -32,30 +47,32 @@ module FasTest
32
47
  def run_test(test_instance, test_method_name)
33
48
  begin
34
49
  status = TestStatuses::PASS
35
- test_instance.setup
50
+ setup_succeeded = try_test_setup(test_instance)
36
51
  test_instance.needs_teardown = true
37
- test_instance.send(test_method_name)
38
- if @verbose
39
- puts "Pass: #{test_instance.class.name}::#{test_method_name}"
52
+ if setup_succeeded
53
+ test_instance.send(test_method_name)
54
+ if @verbose
55
+ puts "Pass: #{test_instance.class.name}::#{test_method_name}"
56
+ end
40
57
  end
41
58
  rescue AssertionException => ex
42
59
  status = TestStatuses::FAIL
43
- try_teardown(test_instance)
60
+ try_test_teardown(test_instance)
44
61
  puts "Fail: #{test_instance.class.name}::#{test_method_name}"
45
62
  puts " -> #{ex.message}"
46
63
  rescue Exception => ex
47
64
  status = TestStatuses::CRASH
48
- try_teardown(test_instance)
65
+ try_test_teardown(test_instance)
49
66
  puts "Crash: #{test_instance.class.name}::#{test_method_name}"
50
67
  puts " -> #{ex.class.name}: #{ex.message}"
51
68
  pretty_print_stack_trace(ex)
52
69
  rescue Object => obj
53
70
  status = TestStatuses::CRASH
54
- try_teardown(test_instance)
71
+ try_test_teardown(test_instance)
55
72
  puts "Crash: #{test_instance.class.name}::#{test_method_name}"
56
73
  puts " -> Raised non-exception: #{obj.to_s}"
57
74
  ensure
58
- try_teardown(test_instance)
75
+ try_test_teardown(test_instance)
59
76
  record_test_result(test_instance, test_method_name, status)
60
77
  end
61
78
  end
@@ -66,10 +83,23 @@ module FasTest
66
83
  @test_results[key] = TestResult.new(test_class, test_method_name, status)
67
84
  end
68
85
 
69
- def try_teardown(test_instance)
86
+ def try_test_setup(test_instance)
87
+ setup_succeeded = true
88
+ begin
89
+ test_instance.test_setup
90
+ rescue Exception => ex
91
+ setup_succeeded = false
92
+ puts "Superfail: #{test_instance.class.name}::test_setup"
93
+ puts " -> #{ex.class.name}: #{ex.message}"
94
+ pretty_print_stack_trace(ex)
95
+ end
96
+ return setup_succeeded
97
+ end
98
+
99
+ def try_test_teardown(test_instance)
70
100
  if test_instance.needs_teardown
71
101
  begin
72
- test_instance.teardown
102
+ test_instance.test_teardown
73
103
  ensure
74
104
  test_instance.needs_teardown = false
75
105
  end
@@ -127,24 +157,27 @@ module FasTest
127
157
  end
128
158
 
129
159
  end
130
-
131
- # Types that a ruby constant can refer to
132
- class ConstantTypes
133
- CLASS = 1
134
- MODULE = 2
135
- OTHER = 3
136
- end
137
-
160
+
138
161
  # Base class for all test suites
139
162
  class TestClass
140
163
 
141
164
  attr_writer :runner
142
165
  attr_accessor :needs_teardown
143
166
 
144
- def setup
167
+ # This is called once before any of the tests in the class are run
168
+ def class_setup
169
+ end
170
+
171
+ # This is called once after ALL the tests in the class are done
172
+ def class_teardown
173
+ end
174
+
175
+ # This is called before EACH test
176
+ def test_setup
145
177
  end
146
178
 
147
- def teardown
179
+ # This is called after EACH test
180
+ def test_teardown
148
181
  end
149
182
 
150
183
  def assert_true(expression, msg = "<no msg given>")
@@ -166,6 +199,10 @@ module FasTest
166
199
  end
167
200
 
168
201
  end
202
+
203
+ # Exception thrown when an assertion in a test fails
204
+ class AssertionException < Exception
205
+ end
169
206
 
170
207
  # Represents the state of a finished test
171
208
  class TestResult
@@ -181,16 +218,19 @@ module FasTest
181
218
  end
182
219
 
183
220
  end
184
-
185
- # Exception thrown when an assertion in a test fails
186
- class AssertionException < Exception
221
+
222
+ # ENUM - Types that a ruby constant can refer to
223
+ class ConstantTypes
224
+ CLASS = 1
225
+ MODULE = 2
226
+ OTHER = 4
187
227
  end
188
-
189
- # Enum of test result states
228
+
229
+ # ENUM - Test result states
190
230
  class TestStatuses
191
231
  PASS = 1
192
232
  FAIL = 2
193
- CRASH = 3
233
+ CRASH = 4
194
234
  end
195
235
 
196
236
  end
@@ -5,14 +5,11 @@ require 'lib/fas_test'
5
5
 
6
6
  class FasTestTests < FasTest::TestClass
7
7
 
8
- def setup
8
+ def class_setup
9
9
  $stdout = StringIO.new
10
- @db = SQLite3::Database.new ":memory:"
11
- @db.execute("CREATE TABLE Foo (id int, foobar varchar(100));")
12
10
  end
13
11
 
14
- def teardown
15
- @db.execute("DELETE FROM Foo;")
12
+ def class_teardown
16
13
  $stdout = STDOUT
17
14
  end
18
15
 
@@ -22,129 +19,6 @@ class FasTestTests < FasTest::TestClass
22
19
  assert_equal "hello?\n", $stdout.string
23
20
  end
24
21
 
25
- def test__this_is_a_temp_test11
26
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
27
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
28
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
29
- rows = @db.execute("SELECT foobar FROM Foo;")
30
-
31
- assert_equal(3, rows.length)
32
- assert_equal('qwer', rows[0][0])
33
- assert_equal('asdf', rows[1][0])
34
- assert_equal('zxcv', rows[2][0])
35
- end
36
- def test__this_is_a_temp_test10
37
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
38
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
39
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
40
- rows = @db.execute("SELECT foobar FROM Foo;")
41
-
42
- assert_equal(3, rows.length)
43
- assert_equal('qwer', rows[0][0])
44
- assert_equal('asdf', rows[1][0])
45
- assert_equal('zxcv', rows[2][0])
46
- end
47
- def test__this_is_a_temp_test9
48
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
49
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
50
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
51
- rows = @db.execute("SELECT foobar FROM Foo;")
52
-
53
- assert_equal(3, rows.length)
54
- assert_equal('qwer', rows[0][0])
55
- assert_equal('asdf', rows[1][0])
56
- assert_equal('zxcv', rows[2][0])
57
- end
58
- def test__this_is_a_temp_test8
59
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
60
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
61
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
62
- rows = @db.execute("SELECT foobar FROM Foo;")
63
-
64
- assert_equal(3, rows.length)
65
- assert_equal('qwer', rows[0][0])
66
- assert_equal('asdf', rows[1][0])
67
- assert_equal('zxcv', rows[2][0])
68
- end
69
- def test__this_is_a_temp_test7
70
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
71
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
72
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
73
- rows = @db.execute("SELECT foobar FROM Foo;")
74
-
75
- assert_equal(3, rows.length)
76
- assert_equal('qwer', rows[0][0])
77
- assert_equal('asdf', rows[1][0])
78
- assert_equal('zxcv', rows[2][0])
79
- end
80
- def test__this_is_a_temp_test6
81
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
82
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
83
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
84
- rows = @db.execute("SELECT foobar FROM Foo;")
85
-
86
- assert_equal(3, rows.length)
87
- assert_equal('qwer', rows[0][0])
88
- assert_equal('asdf', rows[1][0])
89
- assert_equal('zxcv', rows[2][0])
90
- end
91
- def test__this_is_a_temp_test5
92
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
93
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
94
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
95
- rows = @db.execute("SELECT foobar FROM Foo;")
96
-
97
- assert_equal(3, rows.length)
98
- assert_equal('qwer', rows[0][0])
99
- assert_equal('asdf', rows[1][0])
100
- assert_equal('zxcv', rows[2][0])
101
- end
102
- def test__this_is_a_temp_test4
103
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
104
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
105
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
106
- rows = @db.execute("SELECT foobar FROM Foo;")
107
-
108
- assert_equal(3, rows.length)
109
- assert_equal('qwer', rows[0][0])
110
- assert_equal('asdf', rows[1][0])
111
- assert_equal('zxcv', rows[2][0])
112
- end
113
- def test__this_is_a_temp_test3
114
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
115
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
116
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
117
- rows = @db.execute("SELECT foobar FROM Foo;")
118
-
119
- assert_equal(3, rows.length)
120
- assert_equal('qwer', rows[0][0])
121
- assert_equal('asdf', rows[1][0])
122
- assert_equal('zxcv', rows[2][0])
123
- end
124
- def test__this_is_a_temp_test2
125
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
126
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
127
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
128
- rows = @db.execute("SELECT foobar FROM Foo;")
129
-
130
- assert_equal(3, rows.length)
131
- assert_equal('qwer', rows[0][0])
132
- assert_equal('asdf', rows[1][0])
133
- assert_equal('zxcv', rows[2][0])
134
- end
135
- def test__this_is_a_temp_test12
136
- @db.execute("INSERT INTO Foo VALUES (1, 'qwer')")
137
- @db.execute("INSERT INTO Foo VALUES (1, 'asdf')")
138
- @db.execute("INSERT INTO Foo VALUES (1, 'zxcv')")
139
- rows = @db.execute("SELECT foobar FROM Foo;")
140
-
141
- assert_equal(3, rows.length)
142
- assert_equal('qwer', rows[0][0])
143
- assert_equal('asdf', rows[1][0])
144
- assert_equal('zxcv', rows[2][0])
145
- end
146
-
147
-
148
22
  def test__run_tests_in_class__results_are_valid
149
23
  runner = FasTest::TestRunner.new
150
24
  runner.run_tests_in_class(FasTestTestClassTests)
@@ -170,6 +44,7 @@ class FasTestTests < FasTest::TestClass
170
44
  assert_equal(
171
45
  FasTest::TestStatuses::PASS,
172
46
  runner.test_results['FasTestTests::FasTestTestClassTests::test__asert_true_with_true'].status)
47
+
173
48
  end
174
49
 
175
50
  class FasTestTestClassTests < FasTest::TestClass
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fas_test
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
8
+ - 1
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Graeme Hill
@@ -19,7 +19,7 @@ date: 2011-02-25 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: "Auto-discovers test classes in the working directory and runs the tests with<br/><br/>basically no boot up time and no configuration. It doesn't matter how you<br/><br/>structure your project, instead, simple naming conventions are used:<br/><br/><br/><br/> - All test files should be named *_tests.rb<br/><br/> - All test methods should be named test__*<br/><br/><br/><br/>Other things you need to know:<br/><br/><br/><br/> - All test classes should inherit FasTest::TestClass<br/><br/> - Your test class can define \"setup\" and/or \"teardown\" methods. They do what<br/><br/> it sounds like they do.<br/><br/><br/><br/>Take a look in the test folder to see an example of how the library is used.<br/><br/>(fas_test is used to test itself).<br/><br/><br/><br/>To actually run your tests just invoke fastest.rb from a command line. It will<br/><br/>automatically recursively discover all of your test classes within the working<br/><br/>directory and run there tests. "
22
+ description: "Auto-discovers test classes in the working directory and runs the tests with<br/><br/>basically no boot up time and no configuration. It doesn't matter how you<br/><br/>structure your project, instead, simple naming conventions are used:<br/><br/><br/><br/> - All test files should be named *_tests.rb<br/><br/> - All test methods should be named test__*<br/><br/><br/><br/>Other things you need to know:<br/><br/><br/><br/> - All test classes should inherit FasTest::TestClass<br/><br/> - There are two setup and two teardown methods:<br/><br/> - class_setup: Called once before any of the tests<br/><br/> - class_teardown: Called once after any of the tests<br/><br/> - test_setup: Called before each test<br/><br/> - test_teardown: Called after each test<br/><br/><br/><br/>Take a look in the test folder to see an example of how the library is used.<br/><br/>(fas_test is used to test itself).<br/><br/><br/><br/>To actually run your tests just invoke fastest.rb from a command line. It will<br/><br/>automatically recursively discover all of your test classes within the working<br/><br/>directory and run there tests. "
23
23
  email: graemekh@gmail.com
24
24
  executables:
25
25
  - fastest