assert 2.18.2 → 2.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/assert.gemspec +1 -1
  4. data/lib/assert/actual_value.rb +127 -0
  5. data/lib/assert/assertions.rb +11 -20
  6. data/lib/assert/context.rb +13 -5
  7. data/lib/assert/context/let_dsl.rb +13 -0
  8. data/lib/assert/context/method_missing.rb +19 -0
  9. data/lib/assert/macros/methods.rb +4 -4
  10. data/lib/assert/stub.rb +4 -0
  11. data/lib/assert/version.rb +1 -1
  12. data/test/helper.rb +23 -25
  13. data/test/support/factory.rb +15 -0
  14. data/test/system/stub_tests.rb +348 -333
  15. data/test/system/test_tests.rb +111 -109
  16. data/test/unit/actual_value_tests.rb +335 -0
  17. data/test/unit/assert_tests.rb +84 -59
  18. data/test/unit/assertions/assert_block_tests.rb +32 -31
  19. data/test/unit/assertions/assert_empty_tests.rb +35 -32
  20. data/test/unit/assertions/assert_equal_tests.rb +81 -75
  21. data/test/unit/assertions/assert_file_exists_tests.rb +34 -33
  22. data/test/unit/assertions/assert_includes_tests.rb +40 -37
  23. data/test/unit/assertions/assert_instance_of_tests.rb +36 -33
  24. data/test/unit/assertions/assert_kind_of_tests.rb +36 -33
  25. data/test/unit/assertions/assert_match_tests.rb +36 -33
  26. data/test/unit/assertions/assert_nil_tests.rb +32 -31
  27. data/test/unit/assertions/assert_raises_tests.rb +55 -55
  28. data/test/unit/assertions/assert_respond_to_tests.rb +38 -35
  29. data/test/unit/assertions/assert_same_tests.rb +91 -80
  30. data/test/unit/assertions/assert_true_false_tests.rb +64 -60
  31. data/test/unit/assertions_tests.rb +15 -13
  32. data/test/unit/config_helpers_tests.rb +36 -35
  33. data/test/unit/config_tests.rb +33 -34
  34. data/test/unit/context/let_dsl_tests.rb +10 -0
  35. data/test/unit/context/setup_dsl_tests.rb +70 -81
  36. data/test/unit/context/subject_dsl_tests.rb +16 -43
  37. data/test/unit/context/suite_dsl_tests.rb +16 -16
  38. data/test/unit/context/test_dsl_tests.rb +50 -54
  39. data/test/unit/context_info_tests.rb +16 -15
  40. data/test/unit/context_tests.rb +170 -157
  41. data/test/unit/default_runner_tests.rb +2 -5
  42. data/test/unit/default_suite_tests.rb +51 -53
  43. data/test/unit/factory_tests.rb +3 -3
  44. data/test/unit/file_line_tests.rb +31 -33
  45. data/test/unit/macro_tests.rb +9 -10
  46. data/test/unit/result_tests.rb +150 -163
  47. data/test/unit/runner_tests.rb +63 -63
  48. data/test/unit/suite_tests.rb +57 -54
  49. data/test/unit/test_tests.rb +134 -126
  50. data/test/unit/utils_tests.rb +41 -45
  51. data/test/unit/view_helpers_tests.rb +55 -52
  52. data/test/unit/view_tests.rb +20 -22
  53. metadata +11 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93616ac8a1849d9f356088b0386907f946cf89465e84aaa6321ceff60f7012de
4
- data.tar.gz: a4436d1c9d437cb56343318885b1a32d804ad2e71c956408cd877d695f3d9675
3
+ metadata.gz: ff0d6ff9233adc09dda972e165c47c125e158e46b0329b927eb7de201ddebf65
4
+ data.tar.gz: 8f77b5326cf44e2ed0c7ed72cac390a7147191634354feb2b890f73d572b366f
5
5
  SHA512:
6
- metadata.gz: 424110cb0d83c44fcdc66129532bc53859a74a0b2f63f2b08081955d6aee813a9df11f37afbdc325f464866ca0263fc98164992d08949fa2573410f9056334c6
7
- data.tar.gz: 25b2980b91b9e4dddf9724f64cbdc81214c910008157f0ac88f3e3a1c6f4ae8162065d08ef4a2c2eb78ff2211cdc49fdac893397e50e04b5816174eb8293c01b
6
+ metadata.gz: 25b58fd65c099c0c9f8ff16a652e28d5baeae76838b640872224abd7d063759d6fd40b3ec927220260d82321f78cc4b7617d50a081c7ba336b04d45acec8f618
7
+ data.tar.gz: 669749ff845ae1811802042dd28e27e7a387d9d39a9504d73b8b04667c9597c4da08bd56cc26a7b34838e5afde2970215027a7d3967ad1e7f99175c62c49a08e
data/README.md CHANGED
@@ -9,7 +9,7 @@ require "assert"
9
9
 
10
10
  class MyTests < Assert::Context
11
11
  test "something" do
12
- assert_equal 1, 1
12
+ assert_that(1).equals(1)
13
13
  end
14
14
  end
15
15
  ```
@@ -33,13 +33,13 @@ Running tests in random order, seeded with "56382"
33
33
 
34
34
  ## What Assert is not
35
35
 
36
- * **RSpec/spec-anything**: define tests using assertion statements
37
- * **Unit/Functional/Integration/etc**: Assert is agnostic - you define whatever kinds of tests you like (one or more of the above) and assert runs them in context
38
- * **Mock/Spec/BDD/etc**: Assert is the framework and there are a variety of 3rd party tools to do such things - feel free to use whatever you like
36
+ * **RSpec/spec-anything**: define tests using assertion statements.
37
+ * **Unit/Functional/Integration/etc**: Assert is agnostic - you define whatever kinds of tests you like and Assert runs them in context.
38
+ * **Mock/Spec/BDD/etc**: Assert is the framework and there are a variety of 3rd party tools to do such things. Feel free to use whatever you like.
39
39
 
40
40
  ## Description
41
41
 
42
- Assert is an assertion style testing framework, meaning you use assertion statements to define your tests and create results. Assert uses class-based contexts so if you want to nest your contexts, use inheritance.
42
+ Assert is an assertion-style testing framework, meaning you use assertion statements to define your tests and create results. Assert uses class-based contexts so if you want to nest your contexts, use inheritance.
43
43
 
44
44
  ### Features
45
45
 
@@ -50,6 +50,7 @@ Assert is an assertion style testing framework, meaning you use assertion statem
50
50
  * class-based contexts
51
51
  * multiple before/setup & after/teardown blocks
52
52
  * around blocks
53
+ * `let` value declarations
53
54
  * full backtrace for errors
54
55
  * optionally pretty print objects in failure descriptions
55
56
  * [stubbing API](https://github.com/redding/assert#stub)
@@ -666,4 +667,4 @@ If submitting a Pull Request, please:
666
667
 
667
668
  One note: please respect that Assert itself is intended to be the flexible, base-level, framework-type logic that should change little if at all. Pull requests for niche functionality or personal testing philosphy stuff will likely not be accepted.
668
669
 
669
- If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency.
670
+ If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in its own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency.
@@ -21,5 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.required_ruby_version = "~> 2.5"
22
22
 
23
23
  gem.add_dependency("much-factory", ["~> 0.1.0"])
24
- gem.add_dependency("much-stub", ["~> 0.1.3"])
24
+ gem.add_dependency("much-stub", ["~> 0.1.4"])
25
25
  end
@@ -0,0 +1,127 @@
1
+ require "much-stub"
2
+
3
+ module Assert; end
4
+ class Assert::ActualValue
5
+ def initialize(value, context:)
6
+ @value = value
7
+ @context = context
8
+ end
9
+
10
+ def returns_true(*args)
11
+ @context.assert_block(*args, &@value)
12
+ end
13
+
14
+ def does_not_return_true(*args)
15
+ @context.assert_not_block(*args, &@value)
16
+ end
17
+
18
+ def raises(*expected_exceptions)
19
+ @context.assert_raises(*expected_exceptions, &@value)
20
+ end
21
+
22
+ def does_not_raise(*expected_exceptions)
23
+ @context.assert_nothing_raised(*expected_exceptions, &@value)
24
+ end
25
+
26
+ def is_a_kind_of(expected_class, *args)
27
+ @context.assert_kind_of(expected_class, @value, *args)
28
+ end
29
+ alias_method :is_kind_of, :is_a_kind_of
30
+
31
+ def is_not_a_kind_of(expected_class, *args)
32
+ @context.assert_not_kind_of(expected_class, @value, *args)
33
+ end
34
+ alias_method :is_not_kind_of, :is_not_a_kind_of
35
+
36
+ def is_an_instance_of(expected_class, *args)
37
+ @context.assert_instance_of(expected_class, @value, *args)
38
+ end
39
+ alias_method :is_instance_of, :is_an_instance_of
40
+
41
+ def is_not_an_instance_of(expected_class, *args)
42
+ @context.assert_not_instance_of(expected_class, @value, *args)
43
+ end
44
+ alias_method :is_not_instance_of, :is_not_an_instance_of
45
+
46
+ def responds_to(expected_method_name, *args)
47
+ @context.assert_responds_to(expected_method_name, @value, *args)
48
+ end
49
+
50
+ def does_not_respond_to(expected_method_name, *args)
51
+ @context.assert_not_responds_to(expected_method_name, @value, *args)
52
+ end
53
+
54
+ def is_the_same_as(expected_object, *args)
55
+ @context.assert_same(expected_object, @value, *args)
56
+ end
57
+
58
+ def is_not_the_same_as(expected_object, *args)
59
+ @context.assert_not_same(expected_object, @value, *args)
60
+ end
61
+
62
+ def equals(expected_value, *args)
63
+ @context.assert_equal(expected_value, @value, *args)
64
+ end
65
+ alias_method :is_equal_to, :equals
66
+
67
+ def does_not_equal(expected_value, *args)
68
+ @context.assert_not_equal(expected_value, @value, *args)
69
+ end
70
+ alias_method :is_not_equal_to, :does_not_equal
71
+
72
+ def matches(expected_regex, *args)
73
+ @context.assert_match(expected_regex, @value, *args)
74
+ end
75
+
76
+ def does_not_match(expected_regex, *args)
77
+ @context.assert_not_match(expected_regex, @value, *args)
78
+ end
79
+
80
+ def is_empty(*args)
81
+ @context.assert_empty(@value, *args)
82
+ end
83
+
84
+ def is_not_empty(*args)
85
+ @context.assert_not_empty(@value, *args)
86
+ end
87
+
88
+ def includes(object, *args)
89
+ @context.assert_includes(object, @value, *args)
90
+ end
91
+
92
+ def does_not_include(object, *args)
93
+ @context.assert_not_includes(object, @value, *args)
94
+ end
95
+
96
+ def is_nil(*args)
97
+ @context.assert_nil(@value, *args)
98
+ end
99
+
100
+ def is_not_nil(*args)
101
+ @context.assert_not_nil(@value, *args)
102
+ end
103
+
104
+ def is_true(*args)
105
+ @context.assert_true(@value, *args)
106
+ end
107
+
108
+ def is_not_true(*args)
109
+ @context.assert_not_true(@value, *args)
110
+ end
111
+
112
+ def is_false(*args)
113
+ @context.assert_false(@value, *args)
114
+ end
115
+
116
+ def is_not_false(*args)
117
+ @context.assert_not_false(@value, *args)
118
+ end
119
+
120
+ def is_a_file(*args)
121
+ @context.assert_file_exists(@value, *args)
122
+ end
123
+
124
+ def is_not_a_file(*args)
125
+ @context.assert_not_file_exists(@value, *args)
126
+ end
127
+ end
@@ -2,6 +2,15 @@ require "assert/utils"
2
2
 
3
3
  module Assert
4
4
  module Assertions
5
+ IGNORED_ASSERTION_HELPERS =
6
+ [
7
+ :assert_throws, :assert_nothing_thrown,
8
+ :assert_operator, :refute_operator,
9
+ :assert_in_epsilon, :refute_in_epsilon,
10
+ :assert_in_delta, :refute_in_delta,
11
+ :assert_send
12
+ ]
13
+
5
14
  def assert_block(desc = nil)
6
15
  assert(yield, desc){ "Expected block to return a true value." }
7
16
  end
@@ -25,7 +34,7 @@ module Assert
25
34
  alias_method :refute_empty, :assert_not_empty
26
35
 
27
36
  def assert_equal(exp, act, desc = nil)
28
- assert(exp == act, desc) do
37
+ assert(act == exp, desc) do
29
38
  c = __assert_config__
30
39
  exp_show = Assert::U.show_for_diff(exp, c)
31
40
  act_show = Assert::U.show_for_diff(act, c)
@@ -40,7 +49,7 @@ module Assert
40
49
  end
41
50
 
42
51
  def assert_not_equal(exp, act, desc = nil)
43
- assert(exp != act, desc) do
52
+ assert(act != exp, desc) do
44
53
  c = __assert_config__
45
54
  exp_show = Assert::U.show_for_diff(exp, c)
46
55
  act_show = Assert::U.show_for_diff(act, c)
@@ -244,24 +253,6 @@ module Assert
244
253
  end
245
254
  alias_method :refute_same, :assert_not_same
246
255
 
247
- # ignored assertion helpers
248
-
249
- IGNORED_ASSERTION_HELPERS = [
250
- :assert_throws, :assert_nothing_thrown,
251
- :assert_operator, :refute_operator,
252
- :assert_in_epsilon, :refute_in_epsilon,
253
- :assert_in_delta, :refute_in_delta,
254
- :assert_send
255
- ]
256
- def method_missing(method, *args, &block)
257
- if IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
258
- ignore "The assertion `#{method}` is not supported."\
259
- " Please use another assertion or the basic `assert`."
260
- else
261
- super
262
- end
263
- end
264
-
265
256
  private
266
257
 
267
258
  def __assert_config__
@@ -1,4 +1,7 @@
1
+ require "assert/actual_value"
1
2
  require "assert/assertions"
3
+ require "assert/context/let_dsl"
4
+ require "assert/context/method_missing"
2
5
  require "assert/context/setup_dsl"
3
6
  require "assert/context/subject_dsl"
4
7
  require "assert/context/suite_dsl"
@@ -16,6 +19,8 @@ module Assert
16
19
  extend SubjectDSL
17
20
  extend SuiteDSL
18
21
  extend TestDSL
22
+ extend LetDSL
23
+ include MethodMissing
19
24
  include Assert::Assertions
20
25
  include Assert::Macros::Methods
21
26
 
@@ -61,9 +66,8 @@ module Assert
61
66
  end
62
67
  end
63
68
 
64
- # check if the assertion is a truthy value, if so create a new pass result,
65
- # otherwise create a new fail result with the desc and what failed msg.
66
- # all other assertion helpers use this one in the end
69
+ # Check if the result is true. If so, create a new pass result, Otherwise
70
+ # create a new fail result with the desc and fail msg.
67
71
  def assert(assertion, desc = nil)
68
72
  if assertion
69
73
  pass
@@ -78,8 +82,8 @@ module Assert
78
82
  end
79
83
  end
80
84
 
81
- # the opposite of assert, check if the assertion is a false value, if so create a new pass
82
- # result, otherwise create a new fail result with the desc and it's what failed msg
85
+ # The opposite of assert. Check if the result is false. If so, create a new
86
+ # pass result. Otherwise create a new fail result with the desc and fail msg.
83
87
  def assert_not(assertion, fail_desc = nil)
84
88
  assert(!assertion, fail_desc) do
85
89
  "Failed assert_not: assertion was "\
@@ -88,6 +92,10 @@ module Assert
88
92
  end
89
93
  alias_method :refute, :assert_not
90
94
 
95
+ def assert_that(actual_value)
96
+ Assert::ActualValue.new(actual_value, context: self)
97
+ end
98
+
91
99
  # adds a Pass result to the end of the test's results
92
100
  # does not break test execution
93
101
  def pass(pass_msg = nil)
@@ -0,0 +1,13 @@
1
+ module Assert; end
2
+ class Assert::Context; end
3
+ module Assert::Context::LetDSL
4
+ def let(name, &block)
5
+ self.send(:define_method, name, &-> {
6
+ if instance_variable_get("@#{name}").nil?
7
+ instance_variable_set("@#{name}", instance_eval(&block))
8
+ end
9
+
10
+ instance_variable_get("@#{name}")
11
+ })
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require "assert/assertions"
2
+
3
+ module Assert; end
4
+ class Assert::Context; end
5
+ module Assert::Context::MethodMissing
6
+ def method_missing(method, *args, &block)
7
+ if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
8
+ ignore "The assertion `#{method}` is not supported."\
9
+ " Please use another assertion or the basic `assert`."
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def respond_to_missing?(method, *)
16
+ Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym) ||
17
+ super
18
+ end
19
+ end
@@ -102,28 +102,28 @@ module Assert::Macros
102
102
  self.class._methods_macro_instance_methods.each do |(method, called_from)|
103
103
  msg = "#{subject.class.name} does not have instance method ##{method}"
104
104
  with_backtrace([called_from]) do
105
- assert_respond_to method, subject, msg
105
+ assert_that(subject).responds_to(method, msg)
106
106
  end
107
107
  end
108
108
 
109
109
  self.class._methods_macro_class_methods.each do |(method, called_from)|
110
110
  msg = "#{subject.class.name} does not have class method ##{method}"
111
111
  with_backtrace([called_from]) do
112
- assert_respond_to method, subject.class, msg
112
+ assert_that(subject.class).responds_to(method, msg)
113
113
  end
114
114
  end
115
115
 
116
116
  self.class._methods_macro_not_instance_methods.each do |(method, called_from)|
117
117
  msg = "#{subject.class.name} has instance method ##{method}"
118
118
  with_backtrace([called_from]) do
119
- assert_not_respond_to method, subject, msg
119
+ assert_that(subject).does_not_respond_to(method, msg)
120
120
  end
121
121
  end
122
122
 
123
123
  self.class._methods_macro_not_class_methods.each do |(method, called_from)|
124
124
  msg = "#{subject.class.name} has class method ##{method}"
125
125
  with_backtrace([called_from]) do
126
- assert_not_respond_to method, subject.class, msg
126
+ assert_that(subject.class).does_not_respond_to(method, msg)
127
127
  end
128
128
  end
129
129
  end
@@ -9,6 +9,10 @@ module Assert
9
9
  MuchStub.stub(*args, &block)
10
10
  end
11
11
 
12
+ def self.stub_on_call(*args, &block)
13
+ MuchStub.stub_on_call(*args, &block)
14
+ end
15
+
12
16
  def self.unstub(*args)
13
17
  MuchStub.unstub(*args)
14
18
  end
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.18.2"
2
+ VERSION = "2.18.3"
3
3
  end
@@ -9,38 +9,36 @@ $LOAD_PATH.unshift(ROOT_PATH)
9
9
  require "pry"
10
10
  require "test/support/factory"
11
11
 
12
- class Assert::Test
13
- module TestHelpers
14
- def self.included(receiver)
15
- receiver.class_eval do
16
- setup do
17
- @test_run_results = []
18
- @run_callback = proc{ |result| @test_run_results << result }
19
- end
12
+ module Assert::Test::TestHelpers
13
+ def self.included(receiver)
14
+ receiver.class_eval do
15
+ setup do
16
+ @test_run_results = []
17
+ @run_callback = proc { |result| @test_run_results << result }
20
18
  end
19
+ end
21
20
 
22
- private
21
+ private
23
22
 
24
- def test_run_callback
25
- @run_callback
26
- end
23
+ def test_run_callback
24
+ @run_callback
25
+ end
27
26
 
28
- def test_run_results(type = nil)
29
- return @test_run_results if type.nil?
30
- @test_run_results.select{ |r| r.type == type }
31
- end
27
+ def test_run_results(type = nil)
28
+ return @test_run_results if type.nil?
29
+ @test_run_results.select{ |r| r.type == type }
30
+ end
32
31
 
33
- def test_run_result_count(type = nil)
34
- test_run_results(type).count
35
- end
32
+ def test_run_result_count(type = nil)
33
+ test_run_results(type).count
34
+ end
36
35
 
37
- def test_run_result_messages
38
- @test_run_results.map(&:message)
39
- end
36
+ def test_run_result_messages
37
+ @test_run_results.map(&:message)
38
+ end
40
39
 
41
- def last_test_run_result
42
- @test_run_results.last
43
- end
40
+ def last_test_run_result
41
+ @test_run_results.last
44
42
  end
45
43
  end
46
44
  end
@@ -85,4 +85,19 @@ module Factory
85
85
  instance_eval(&block) if !block.nil?
86
86
  end
87
87
  end
88
+
89
+ def self.modes_off_context(&result_block)
90
+ test = Factory.test
91
+ Factory.modes_off_context_class.new(
92
+ test,
93
+ test.config,
94
+ result_block || proc { |r| }
95
+ )
96
+ end
97
+
98
+ def self.backtrace
99
+ assert_lib_path =
100
+ File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
101
+ (Factory.integer(3).times.map{ Factory.string } + [assert_lib_path]).shuffle
102
+ end
88
103
  end