inline_tests 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52d7f5e865cea20d021f5869af73cdaaa17cfbba58c8a57b88f8defe5ffef04f
4
- data.tar.gz: 24ff7a42c0250974f2736d0376f0aead4c50f23e295a4d50696670061f1f3d87
3
+ metadata.gz: e0bf7709504a4c8d34e6678f645aab6e3ef89e7870c2726250f6cbc2c610c661
4
+ data.tar.gz: 76de1fed7a5bd34e8d14a29cc25d9d502eb75092d49f28cbff967ef5050eafc9
5
5
  SHA512:
6
- metadata.gz: 16dd438c1236501535d6cf77e0716b22bcaa1c27628a94c47636beb054eaa7c33bce8b72890770d5b641e210d05a5bc9d6c2fe2d14ff9ae2ba897754e79d900a
7
- data.tar.gz: c64d00f930b82d514bed71b120492d3ea97b6a28225650d069fbd1aef08e145708054a8a480a5633409c3614dd42d0f254855e1f9db9b4f1b83a0170f46a5967
6
+ metadata.gz: c48155eb8ef76de889be36d17a1bfd75add615ece1b8ef518d878f29edfaa86058bcc570203c887cb0c2e152a2150f006d2caf65a07043b08acfc476db5d1bb0
7
+ data.tar.gz: 7d6d2c52c453b059a5dd0c08ee493cd378e093f40de657dedf37031d2c9ff434ec51905d5ad8c18665edeb3c8d4ecb3665c5a092067888a39666eb6f17691630
@@ -23,51 +23,6 @@ module Kernel
23
23
  METHODS_THAT_NEED_TESTS.push method
24
24
  end
25
25
 
26
- def assert(some_statement, description = '')
27
- passed = !!some_statement
28
- raise InlineTestFailure.new('assert', some_statement, nil, description) unless passed
29
-
30
- passed
31
- end
32
-
33
- def assert_equal(lhs, rhs, description = '')
34
- passed = !!flexible_assert(lhs, rhs, "[lhs] == [rhs]")
35
- raise InlineTestFailure.new('assert_equal', lhs, rhs, description) unless passed
36
-
37
- passed
38
- end
39
-
40
- def assert_not_equal(lhs, rhs, description = '')
41
- passed = !!flexible_assert(lhs, rhs, "[lhs] != [rhs]")
42
- raise InlineTestFailure.new('assert_not_equal', lhs, rhs, description) unless passed
43
-
44
- passed
45
- end
46
-
47
- def assert_less_than(lhs, rhs, description = '')
48
- passed = !!flexible_assert(lhs, rhs, "[lhs] < [rhs]")
49
- raise InlineTestFailure.new('assert_less_than', lhs, rhs, description) unless passed
50
-
51
- passed
52
- end
53
-
54
- def assert_greater_than(lhs, rhs, description = '')
55
- passed = !!flexible_assert(lhs, rhs, "[lhs] > [rhs]")
56
- raise InlineTestFailure.new('assert_greater_than', lhs, rhs, description) unless passed
57
-
58
- passed
59
- end
60
-
61
- def assert_divisible_by(lhs, rhs, description = '')
62
- passed = !!flexible_assert(lhs, rhs, "[lhs] % [rhs] == 0")
63
- raise InlineTestFailure.new('assert_divisible_by', lhs, rhs, description) unless passed
64
-
65
- passed
66
- end
67
-
68
- # TODO: assert_positive
69
- # TODO: assert_negative
70
-
71
26
  # dirty hacks for global constants :(
72
27
  module Infinity; def to_s; Float::INFINITY; end; end
73
28
  module NaN; def to_s; 0 * Float::INFINITY; end; end
@@ -21,7 +21,18 @@ class Method
21
21
  end
22
22
 
23
23
  def run_inline_tests
24
- inline_tests.call self if inline_tests && inline_tests.respond_to?(:call)
24
+ # TODO: this is probably a good place to manage per-test state, reset DB if needed, etc
25
+
26
+ # Gem users should be able to use assert(), assert_equal(), etc in their test blocks, but
27
+ # I don't want to pollute the global namespace, so we instantiate a TestHelper (which contains
28
+ # all of those methods) and run each block of inline texts within that TestHelper's context,
29
+ # meaning they can use assert(true) in their test blocks anywhere without having to litter
30
+ # Kernel with global methods OR require people to do something like TestHelper::assert(true).
31
+
32
+ testhelper = TestHelper.new
33
+ testhelper.method = self
34
+ testhelper.fuzz = self
35
+ testhelper.instance_exec(&inline_tests) if inline_tests && inline_tests.respond_to?(:call)
25
36
  end
26
37
 
27
38
  private
@@ -0,0 +1,49 @@
1
+ # The methods in this class are available whenever you're in a tests do ... end block.
2
+ class TestHelper
3
+ attr_accessor :method, :fuzz # The method being tested
4
+
5
+ def assert(some_statement, description = '')
6
+ passed = !!some_statement
7
+ raise InlineTestFailure.new('assert', some_statement, nil, description) unless passed
8
+
9
+ passed
10
+ end
11
+
12
+ def assert_equal(lhs, rhs, description = '')
13
+ passed = !!flexible_assert(lhs, rhs, "[lhs] == [rhs]")
14
+ raise InlineTestFailure.new('assert_equal', lhs, rhs, description) unless passed
15
+
16
+ passed
17
+ end
18
+
19
+ def assert_not_equal(lhs, rhs, description = '')
20
+ passed = !!flexible_assert(lhs, rhs, "[lhs] != [rhs]")
21
+ raise InlineTestFailure.new('assert_not_equal', lhs, rhs, description) unless passed
22
+
23
+ passed
24
+ end
25
+
26
+ def assert_less_than(lhs, rhs, description = '')
27
+ passed = !!flexible_assert(lhs, rhs, "[lhs] < [rhs]")
28
+ raise InlineTestFailure.new('assert_less_than', lhs, rhs, description) unless passed
29
+
30
+ passed
31
+ end
32
+
33
+ def assert_greater_than(lhs, rhs, description = '')
34
+ passed = !!flexible_assert(lhs, rhs, "[lhs] > [rhs]")
35
+ raise InlineTestFailure.new('assert_greater_than', lhs, rhs, description) unless passed
36
+
37
+ passed
38
+ end
39
+
40
+ def assert_divisible_by(lhs, rhs, description = '')
41
+ passed = !!flexible_assert(lhs, rhs, "[lhs] % [rhs] == 0")
42
+ raise InlineTestFailure.new('assert_divisible_by', lhs, rhs, description) unless passed
43
+
44
+ passed
45
+ end
46
+
47
+ # TODO: assert_positive
48
+ # TODO: assert_negative
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Brown
@@ -20,6 +20,7 @@ files:
20
20
  - lib/inline_tests.rb
21
21
  - lib/kernel_extensions.rb
22
22
  - lib/method_extensions.rb
23
+ - lib/test_helper.rb
23
24
  homepage: https://github.com/drusepth/inline-tests-gem
24
25
  licenses:
25
26
  - MIT