fas_test 0.1.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/fas_test.gemspec +1 -1
  2. data/lib/fas_test.rb +33 -33
  3. metadata +12 -6
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "fas_test"
3
- s.version = "0.1.5"
3
+ s.version = "1.0.0"
4
4
  s.authors = ["Graeme Hill"]
5
5
  s.email = "graemekh@gmail.com"
6
6
  s.homepage = "https://github.com/graeme-hill/fas_test"
@@ -1,17 +1,17 @@
1
1
  module FasTest
2
-
2
+
3
3
  # Used to discover tests and actually run them. Normally this class will be
4
4
  # used by the command line client.
5
5
  class TestRunner
6
-
6
+
7
7
  attr_reader :test_results
8
-
8
+
9
9
  def initialize(verbose = false)
10
10
  @verbose = verbose
11
11
  @assertion_count = 0
12
12
  @test_results = {}
13
13
  end
14
-
14
+
15
15
  def run_tests_in_class(test_class)
16
16
  test_instance = init_test_instance(test_class)
17
17
  begin
@@ -33,17 +33,17 @@ module FasTest
33
33
  test_instance.class_teardown
34
34
  end
35
35
  end
36
-
36
+
37
37
  def init_test_instance(test_class)
38
38
  test_instance = test_class.new
39
39
  test_instance.runner = self
40
40
  return test_instance
41
41
  end
42
-
42
+
43
43
  def increment_assert_count
44
44
  @assertion_count += 1
45
45
  end
46
-
46
+
47
47
  def run_test(test_instance, test_method_name)
48
48
  begin
49
49
  status = TestStatuses::PASS
@@ -76,13 +76,13 @@ module FasTest
76
76
  record_test_result(test_instance, test_method_name, status)
77
77
  end
78
78
  end
79
-
79
+
80
80
  def record_test_result(test_instance, test_method_name, status)
81
81
  test_class = test_instance.class
82
82
  key = "#{test_class.name}::#{test_method_name}"
83
83
  @test_results[key] = TestResult.new(test_class, test_method_name, status)
84
84
  end
85
-
85
+
86
86
  def try_test_setup(test_instance)
87
87
  setup_succeeded = true
88
88
  begin
@@ -95,7 +95,7 @@ module FasTest
95
95
  end
96
96
  return setup_succeeded
97
97
  end
98
-
98
+
99
99
  def try_test_teardown(test_instance)
100
100
  if test_instance.needs_teardown
101
101
  begin
@@ -105,28 +105,28 @@ module FasTest
105
105
  end
106
106
  end
107
107
  end
108
-
108
+
109
109
  def pretty_print_stack_trace(exception)
110
110
  if @verbose
111
111
  exception.backtrace.each { |trace| puts " #{trace}"}
112
112
  end
113
113
  end
114
-
114
+
115
115
  def run_tests_in_folder(path)
116
116
  load_test_files(path)
117
117
  find_test_classes.each do |test_class|
118
118
  run_tests_in_class(test_class)
119
119
  end
120
120
  end
121
-
121
+
122
122
  def load_test_files(path)
123
123
  Dir[File.join(path, '/**/*_tests.rb')].each { |file_name| load file_name }
124
124
  end
125
-
125
+
126
126
  def get_all_test_method_names(test_class)
127
127
  test_class.instance_methods.find_all { |m| m.to_s.start_with?('test__') }
128
128
  end
129
-
129
+
130
130
  def find_test_classes
131
131
  classes = []
132
132
  Module.constants.each do |constant|
@@ -137,7 +137,7 @@ module FasTest
137
137
  end
138
138
  return classes
139
139
  end
140
-
140
+
141
141
  def get_constant_type(construct)
142
142
  construct_class = construct.class
143
143
  if construct_class == Class
@@ -148,7 +148,7 @@ module FasTest
148
148
  return ConstantTypes::OTHER
149
149
  end
150
150
  end
151
-
151
+
152
152
  def class_inherits_parent?(child_class, parent_class)
153
153
  child_class.ancestors.any? { |ancestor| ancestor == parent_class }
154
154
  end
@@ -163,78 +163,78 @@ module FasTest
163
163
 
164
164
  # Base class for all test suites
165
165
  class TestClass
166
-
166
+
167
167
  attr_writer :runner
168
168
  attr_accessor :needs_teardown
169
-
169
+
170
170
  # This is called once before any of the tests in the class are run
171
171
  def class_setup
172
172
  end
173
-
173
+
174
174
  # This is called once after ALL the tests in the class are done
175
175
  def class_teardown
176
176
  end
177
-
177
+
178
178
  # This is called before EACH test
179
179
  def test_setup
180
180
  end
181
-
181
+
182
182
  # This is called after EACH test
183
183
  def test_teardown
184
184
  end
185
-
185
+
186
186
  def assert_true(expression, msg = "<no msg given>")
187
187
  @runner.increment_assert_count
188
188
  if expression != true
189
189
  raise AssertionException, "#{msg} | expected true but got #{expression.to_s}"
190
190
  end
191
191
  end
192
-
192
+
193
193
  def assert_equal(a, b, msg = "<no msg given>")
194
194
  @runner.increment_assert_count
195
195
  if a != b
196
196
  raise AssertionException, "#{msg} | expected '#{a}' but got '#{b}'"
197
197
  end
198
198
  end
199
-
199
+
200
200
  def fail(msg)
201
201
  raise AssertionException, msg
202
202
  end
203
-
203
+
204
204
  end
205
205
 
206
206
  # Exception thrown when an assertion in a test fails
207
207
  class AssertionException < Exception
208
208
  end
209
-
209
+
210
210
  # Represents the state of a finished test
211
211
  class TestResult
212
-
212
+
213
213
  attr_reader :test_class
214
214
  attr_reader :method_name
215
215
  attr_reader :status
216
-
216
+
217
217
  def initialize(test_class, method_name, status)
218
218
  @test_class = test_class
219
219
  @method_name = method_name
220
220
  @status = status
221
221
  end
222
-
222
+
223
223
  end
224
-
224
+
225
225
  # ENUM - Types that a ruby constant can refer to
226
226
  class ConstantTypes
227
227
  CLASS = 1
228
228
  MODULE = 2
229
229
  OTHER = 4
230
230
  end
231
-
231
+
232
232
  # ENUM - Test result states
233
233
  class TestStatuses
234
234
  PASS = 1
235
235
  FAIL = 2
236
236
  CRASH = 4
237
237
  end
238
-
238
+
239
239
  end
240
240
 
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fas_test
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.5
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
6
10
  platform: ruby
7
11
  authors:
8
12
  - Graeme Hill
@@ -10,7 +14,7 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-02-28 00:00:00 -08:00
17
+ date: 2011-10-15 00:00:00 -07:00
14
18
  default_executable:
15
19
  dependencies: []
16
20
 
@@ -38,21 +42,23 @@ rdoc_options: []
38
42
  require_paths:
39
43
  - lib
40
44
  required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
45
  requirements:
43
46
  - - ">="
44
47
  - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
45
50
  version: "0"
46
51
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
52
  requirements:
49
53
  - - ">="
50
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
51
57
  version: "0"
52
58
  requirements: []
53
59
 
54
60
  rubyforge_project:
55
- rubygems_version: 1.5.2
61
+ rubygems_version: 1.3.6
56
62
  signing_key:
57
63
  specification_version: 3
58
64
  summary: A simple automated testing framework designed to be fast and easy to use.