assert 2.18.2 → 2.19.2

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/README.md +7 -6
  4. data/assert.gemspec +5 -2
  5. data/bin/assert +1 -0
  6. data/lib/assert.rb +2 -0
  7. data/lib/assert/actual_value.rb +143 -0
  8. data/lib/assert/assert_runner.rb +2 -0
  9. data/lib/assert/assertions.rb +82 -20
  10. data/lib/assert/cli.rb +2 -0
  11. data/lib/assert/config.rb +2 -0
  12. data/lib/assert/config_helpers.rb +2 -0
  13. data/lib/assert/context.rb +33 -37
  14. data/lib/assert/context/let_dsl.rb +16 -0
  15. data/lib/assert/context/method_missing.rb +22 -0
  16. data/lib/assert/context/setup_dsl.rb +3 -0
  17. data/lib/assert/context/subject_dsl.rb +26 -24
  18. data/lib/assert/context/suite_dsl.rb +3 -0
  19. data/lib/assert/context/test_dsl.rb +3 -0
  20. data/lib/assert/context_info.rb +2 -0
  21. data/lib/assert/default_runner.rb +2 -0
  22. data/lib/assert/default_suite.rb +2 -0
  23. data/lib/assert/default_view.rb +2 -0
  24. data/lib/assert/factory.rb +2 -0
  25. data/lib/assert/file_line.rb +2 -0
  26. data/lib/assert/macro.rb +2 -0
  27. data/lib/assert/macros/methods.rb +6 -4
  28. data/lib/assert/result.rb +8 -1
  29. data/lib/assert/runner.rb +2 -0
  30. data/lib/assert/stub.rb +45 -0
  31. data/lib/assert/suite.rb +9 -10
  32. data/lib/assert/test.rb +3 -9
  33. data/lib/assert/utils.rb +3 -1
  34. data/lib/assert/version.rb +3 -1
  35. data/lib/assert/view.rb +2 -0
  36. data/lib/assert/view_helpers.rb +2 -0
  37. data/test/helper.rb +28 -28
  38. data/test/support/factory.rb +17 -0
  39. data/test/support/inherited_stuff.rb +2 -0
  40. data/test/system/stub_tests.rb +334 -333
  41. data/test/system/test_tests.rb +101 -109
  42. data/test/unit/actual_value_tests.rb +373 -0
  43. data/test/unit/assert_tests.rb +79 -61
  44. data/test/unit/assertions/assert_block_tests.rb +32 -31
  45. data/test/unit/assertions/assert_changes_tests.rb +99 -0
  46. data/test/unit/assertions/assert_empty_tests.rb +35 -32
  47. data/test/unit/assertions/assert_equal_tests.rb +96 -74
  48. data/test/unit/assertions/assert_file_exists_tests.rb +34 -33
  49. data/test/unit/assertions/assert_includes_tests.rb +40 -37
  50. data/test/unit/assertions/assert_instance_of_tests.rb +36 -33
  51. data/test/unit/assertions/assert_kind_of_tests.rb +36 -33
  52. data/test/unit/assertions/assert_match_tests.rb +36 -33
  53. data/test/unit/assertions/assert_nil_tests.rb +32 -31
  54. data/test/unit/assertions/assert_raises_tests.rb +57 -55
  55. data/test/unit/assertions/assert_respond_to_tests.rb +38 -35
  56. data/test/unit/assertions/assert_same_tests.rb +88 -81
  57. data/test/unit/assertions/assert_true_false_tests.rb +62 -60
  58. data/test/unit/assertions_tests.rb +28 -24
  59. data/test/unit/config_helpers_tests.rb +45 -38
  60. data/test/unit/config_tests.rb +40 -34
  61. data/test/unit/context/let_dsl_tests.rb +12 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -81
  63. data/test/unit/context/subject_dsl_tests.rb +17 -43
  64. data/test/unit/context/suite_dsl_tests.rb +17 -16
  65. data/test/unit/context/test_dsl_tests.rb +52 -52
  66. data/test/unit/context_info_tests.rb +25 -15
  67. data/test/unit/context_tests.rb +186 -179
  68. data/test/unit/default_runner_tests.rb +4 -5
  69. data/test/unit/default_suite_tests.rb +59 -53
  70. data/test/unit/factory_tests.rb +7 -3
  71. data/test/unit/file_line_tests.rb +35 -35
  72. data/test/unit/macro_tests.rb +16 -10
  73. data/test/unit/result_tests.rb +161 -183
  74. data/test/unit/runner_tests.rb +67 -65
  75. data/test/unit/suite_tests.rb +58 -59
  76. data/test/unit/test_tests.rb +120 -139
  77. data/test/unit/utils_tests.rb +45 -45
  78. data/test/unit/view_helpers_tests.rb +56 -52
  79. data/test/unit/view_tests.rb +24 -23
  80. metadata +29 -6
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Assert; end
4
+ class Assert::Context; end
5
+
6
+ module Assert::Context::LetDSL
7
+ def let(name, &block)
8
+ self.send(:define_method, name, &-> {
9
+ unless instance_variable_defined?("@__assert_let_#{name}__")
10
+ instance_variable_set("@__assert_let_#{name}__", instance_eval(&block))
11
+ end
12
+
13
+ instance_variable_get("@__assert_let_#{name}__")
14
+ })
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "assert/assertions"
4
+
5
+ module Assert; end
6
+ class Assert::Context; end
7
+
8
+ module Assert::Context::MethodMissing
9
+ def method_missing(method, *args, &block)
10
+ if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
11
+ ignore "The assertion `#{method}` is not supported."\
12
+ " Please use another assertion or the basic `assert`."
13
+ else
14
+ super
15
+ end
16
+ end
17
+
18
+ def respond_to_missing?(method, *)
19
+ Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym) ||
20
+ super
21
+ end
22
+ end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
4
+
2
5
  class Assert::Context
3
6
  module SetupDSL
4
7
  def setup_once(&block)
@@ -1,33 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
2
- class Assert::Context
3
- module SubjectDSL
4
- # Add a piece of description text or return the full description for the context
5
- def description(text = nil)
6
- if text
7
- self.descriptions << text.to_s
8
- else
9
- parent = self.superclass.desc if self.superclass.respond_to?(:desc)
10
- own = self.descriptions
11
- [parent, *own].compact.reject(&:empty?).join(" ")
12
- end
4
+ class Assert::Context; end
5
+
6
+ module Assert::Context::SubjectDSL
7
+ # Add a piece of description text or return the full description for the context
8
+ def description(text = nil)
9
+ if text
10
+ self.descriptions << text.to_s
11
+ else
12
+ parent = self.superclass.desc if self.superclass.respond_to?(:desc)
13
+ own = self.descriptions
14
+ [parent, *own].compact.reject(&:empty?).join(" ")
13
15
  end
14
- alias_method :desc, :description
15
- alias_method :describe, :description
16
+ end
17
+ alias_method :desc, :description
18
+ alias_method :describe, :description
16
19
 
17
- def subject(&block)
18
- if block_given?
19
- @subject = block
20
- else
21
- @subject || if superclass.respond_to?(:subject)
22
- superclass.subject
23
- end
20
+ def subject(&block)
21
+ if block_given?
22
+ @subject = block
23
+ else
24
+ @subject || if superclass.respond_to?(:subject)
25
+ superclass.subject
24
26
  end
25
27
  end
28
+ end
26
29
 
27
- protected
30
+ protected
28
31
 
29
- def descriptions
30
- @descriptions ||= []
31
- end
32
+ def descriptions
33
+ @descriptions ||= []
32
34
  end
33
35
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
4
+
2
5
  class Assert::Context
3
6
  module SuiteDSL
4
7
  def suite(suite_obj = nil)
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/context_info"
2
4
  require "assert/macro"
3
5
  require "assert/suite"
4
6
  require "assert/test"
5
7
 
6
8
  module Assert; end
9
+
7
10
  class Assert::Context
8
11
  module TestDSL
9
12
  def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert
2
4
  class ContextInfo
3
5
  attr_reader :called_from, :klass, :file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/runner"
2
4
 
3
5
  module Assert
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/suite"
2
4
 
3
5
  module Assert
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/view"
2
4
  require "assert/view_helpers"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "much-factory"
2
4
 
3
5
  module Assert
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert
2
4
  class FileLine
3
5
  def self.parse(file_line_path)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert
2
4
  class Macro < ::Proc
3
5
  # this class is essentially a way to define a custom set of tests using
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/macro"
2
4
 
3
5
  module Assert::Macros
@@ -102,28 +104,28 @@ module Assert::Macros
102
104
  self.class._methods_macro_instance_methods.each do |(method, called_from)|
103
105
  msg = "#{subject.class.name} does not have instance method ##{method}"
104
106
  with_backtrace([called_from]) do
105
- assert_respond_to method, subject, msg
107
+ assert_that(subject).responds_to(method, msg)
106
108
  end
107
109
  end
108
110
 
109
111
  self.class._methods_macro_class_methods.each do |(method, called_from)|
110
112
  msg = "#{subject.class.name} does not have class method ##{method}"
111
113
  with_backtrace([called_from]) do
112
- assert_respond_to method, subject.class, msg
114
+ assert_that(subject.class).responds_to(method, msg)
113
115
  end
114
116
  end
115
117
 
116
118
  self.class._methods_macro_not_instance_methods.each do |(method, called_from)|
117
119
  msg = "#{subject.class.name} has instance method ##{method}"
118
120
  with_backtrace([called_from]) do
119
- assert_not_respond_to method, subject, msg
121
+ assert_that(subject).does_not_respond_to(method, msg)
120
122
  end
121
123
  end
122
124
 
123
125
  self.class._methods_macro_not_class_methods.each do |(method, called_from)|
124
126
  msg = "#{subject.class.name} has class method ##{method}"
125
127
  with_backtrace([called_from]) do
126
- assert_not_respond_to method, subject.class, msg
128
+ assert_that(subject.class).does_not_respond_to(method, msg)
127
129
  end
128
130
  end
129
131
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/file_line"
2
4
 
3
5
  module Assert; end
6
+
4
7
  module Assert::Result
5
8
  class Base ; end
6
9
  class Pass < Base ; end
@@ -129,7 +132,11 @@ module Assert::Result
129
132
  end
130
133
 
131
134
  def ==(other_result)
132
- self.type == other_result.type && self.message == other_result.message
135
+ if other_result.is_a?(self.class)
136
+ self.type == other_result.type && self.message == other_result.message
137
+ else
138
+ super
139
+ end
133
140
  end
134
141
 
135
142
  def inspect
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/config_helpers"
2
4
  require "assert/suite"
3
5
  require "assert/view"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "much-stub"
2
4
 
3
5
  module Assert
@@ -9,6 +11,10 @@ module Assert
9
11
  MuchStub.stub(*args, &block)
10
12
  end
11
13
 
14
+ def self.stub_on_call(*args, &block)
15
+ MuchStub.stub_on_call(*args, &block)
16
+ end
17
+
12
18
  def self.unstub(*args)
13
19
  MuchStub.unstub(*args)
14
20
  end
@@ -38,4 +44,43 @@ module Assert
38
44
  def self.stub_spy(*args, &block)
39
45
  MuchStub.spy(*args, &block)
40
46
  end
47
+
48
+ StubCall = MuchStub::Call
49
+ class StubCall
50
+ def self.name
51
+ super.gsub("MuchStub::Call", "Assert::StubCall")
52
+ end
53
+
54
+ def self.to_s
55
+ super.gsub("MuchStub::Call", "Assert::StubCall")
56
+ end
57
+
58
+ def self.inspect
59
+ super.gsub("MuchStub::Call", "Assert::StubCall")
60
+ end
61
+
62
+ def inspect
63
+ super.gsub("MuchStub::Call", "Assert::StubCall")
64
+ end
65
+ end
66
+
67
+ StubCallSpy = MuchStub::CallSpy
68
+ class StubCallSpy
69
+ def self.name
70
+ super.gsub("MuchStub::CallSpy", "Assert::StubCallSpy")
71
+ end
72
+
73
+ def self.to_s
74
+ super.gsub("MuchStub::CallSpy", "Assert::StubCallSpy")
75
+ end
76
+
77
+ def self.inspect
78
+ super.gsub("MuchStub::CallSpy", "Assert::StubCallSpy")
79
+ end
80
+
81
+ # See MuchStub::CallSpy#inspect.
82
+ def inspect
83
+ "#<Assert::StubCallSpy:#{"0x0%x" % (self.__id__ << 1)}>"
84
+ end
85
+ end
41
86
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/config_helpers"
2
4
  require "assert/test"
3
5
 
@@ -10,22 +12,19 @@ module Assert
10
12
  class Suite
11
13
  include Assert::ConfigHelpers
12
14
 
13
- TEST_METHOD_REGEX = /^test./.freeze
14
-
15
15
  # A suite is a set of tests to run. When a test class subclasses
16
16
  # the Context class, that test class is pushed to the suite.
17
17
 
18
- attr_reader :config, :test_methods, :setups, :teardowns
18
+ attr_reader :config, :setups, :teardowns
19
19
  attr_accessor :start_time, :end_time
20
20
 
21
21
  def initialize(config)
22
- @config = config
23
- @tests = []
24
- @test_methods = []
25
- @setups = []
26
- @teardowns = []
27
- @start_time = Time.now
28
- @end_time = @start_time
22
+ @config = config
23
+ @tests = []
24
+ @setups = []
25
+ @teardowns = []
26
+ @start_time = Time.now
27
+ @end_time = @start_time
29
28
  end
30
29
 
31
30
  def suite; self; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "stringio"
2
4
  require "assert/file_line"
3
5
  require "assert/result"
@@ -20,14 +22,6 @@ module Assert
20
22
  }))
21
23
  end
22
24
 
23
- def self.for_method(method_name, context_info, config)
24
- self.new(self.name_file_line_context_data(context_info, method_name).merge({
25
- :context_info => context_info,
26
- :config => config,
27
- :code => proc{ self.send(method_name) }
28
- }))
29
- end
30
-
31
25
  def initialize(build_data = nil)
32
26
  @build_data = build_data || {}
33
27
  @result_callback = nil
@@ -45,7 +39,7 @@ module Assert
45
39
  end
46
40
 
47
41
  def output
48
- @output ||= (@build_data[:output] || "")
42
+ @output ||= (@build_data[:output] || +"")
49
43
  end
50
44
 
51
45
  def run_time
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
 
3
5
  module Assert
@@ -29,7 +31,7 @@ module Assert
29
31
  # Get a proc that uses stdlib `PP.pp` to pretty print objects
30
32
  def self.stdlib_pp_proc(width = nil)
31
33
  require "pp"
32
- Proc.new{ |obj| PP.pp(obj, "", width || 79).strip }
34
+ Proc.new{ |obj| PP.pp(obj, +"", width || 79).strip }
33
35
  end
34
36
 
35
37
  # Return true if if either show output has newlines or is bigger than 29 chars
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert
2
- VERSION = "2.18.2"
4
+ VERSION = "2.19.2"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/config"
2
4
  require "assert/config_helpers"
3
5
  require "assert/suite"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/config_helpers"
2
4
 
3
5
  module Assert
@@ -1,7 +1,9 @@
1
- # this file is automatically required when you run `assert`
2
- # put any test helpers here
1
+ # frozen_string_literal: true
3
2
 
4
- # add the root dir to the load path
3
+ # This file is automatically required when you run `assert`; put any test
4
+ # helpers here.
5
+
6
+ # Add the root dir to the load path.
5
7
  ROOT_PATH = File.expand_path("../..", __FILE__)
6
8
  $LOAD_PATH.unshift(ROOT_PATH)
7
9
 
@@ -9,38 +11,36 @@ $LOAD_PATH.unshift(ROOT_PATH)
9
11
  require "pry"
10
12
  require "test/support/factory"
11
13
 
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
14
+ module Assert::Test::TestHelpers
15
+ def self.included(receiver)
16
+ receiver.class_eval do
17
+ setup do
18
+ @test_run_results = []
19
+ @run_callback = proc { |result| @test_run_results << result }
20
20
  end
21
+ end
21
22
 
22
- private
23
+ private
23
24
 
24
- def test_run_callback
25
- @run_callback
26
- end
25
+ def test_run_callback
26
+ @run_callback
27
+ end
27
28
 
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
29
+ def test_run_results(type = nil)
30
+ return @test_run_results if type.nil?
31
+ @test_run_results.select{ |r| r.type == type }
32
+ end
32
33
 
33
- def test_run_result_count(type = nil)
34
- test_run_results(type).count
35
- end
34
+ def test_run_result_count(type = nil)
35
+ test_run_results(type).count
36
+ end
36
37
 
37
- def test_run_result_messages
38
- @test_run_results.map(&:message)
39
- end
38
+ def test_run_result_messages
39
+ @test_run_results.map(&:message)
40
+ end
40
41
 
41
- def last_test_run_result
42
- @test_run_results.last
43
- end
42
+ def last_test_run_result
43
+ @test_run_results.last
44
44
  end
45
45
  end
46
46
  end