bridgetown-foundation 2.0.3 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1478f1ce19153ecd82462705924320ec0af273470daa8db76878a69d5df8ef79
4
- data.tar.gz: d9e027cedf68e3be388cd2c0dca6f8eb911d2169b6630bac8db2372650f42e78
3
+ metadata.gz: 7bac229d28262dd95ff12ab4ae435921d01b135a97e451901671f1b34d30a373
4
+ data.tar.gz: 6d65ba98e9d6407ea0e78af33f5de51ecc1b53d55d72425f300abf46e5142aca
5
5
  SHA512:
6
- metadata.gz: eb8ef2c9e5aa68647fcd034539f250be7eaa2ad116f864b7f1e407a0abc6bfa5b7e2d15e25812b95280b6acb9f899d01b64b97a9690dadf62f1a5884e3468e59
7
- data.tar.gz: b18d156f3d6d9f7dfa4e380ba4c42beb1492aed9a98866c18ac6d9d753cc94dea2a080cfd24f0054f7a97a83a2d89941dc9ffca5690cf5bb642dd61646abb772
6
+ metadata.gz: f13037d4cf6c30e40ed40f7ba3cf4c590d7b5771065c5b7759566f0f6faa2c24a1d5e97e2c680afd5912d6c2aa2ec90ce708edf6e8b64cebbda48f8d18abe157
7
+ data.tar.gz: 30c9dffa6f4ef76ba7e57b88f8150d79b696be9fe54f54aeedb08f36ccef3f3cb33b1d07686b7de249ac05061629468b5da8535f58c40be9fc9d7c1258e23530
data/.rubocop.yml CHANGED
@@ -5,3 +5,7 @@ AllCops:
5
5
  Exclude:
6
6
  - "*.gemspec"
7
7
  - "script/console"
8
+
9
+ Lint/Void:
10
+ Exclude:
11
+ - test/**/*.rb
@@ -0,0 +1,203 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown/foundation/refine_ext/object"
4
+
5
+ module Bridgetown::Foundation
6
+ # This module provides a set of Ruby syntax-inspired mechanism for writing expectations
7
+ # which wrap the native statements within `Minitest::Expectation`.
8
+ #
9
+ # Generally the methods here return self, so you can chain multiple expectations together
10
+ # for a single object.
11
+ module IntuitiveExpectations
12
+ using Bridgetown::Foundation::RefineExt::Object
13
+
14
+ # Use this in your main test helper to enrich `Minitest::Expectation`, or something akin to it
15
+ #
16
+ # @param [Module(Minitest)]
17
+ def self.enrich(mod)
18
+ mod::Expectation.include self
19
+ filter_exp = %r!bridgetown/foundation/intuitive_expectations\.rb!
20
+ if mod.backtrace_filter.respond_to?(:add_filter)
21
+ mod.backtrace_filter.add_filter filter_exp
22
+ else
23
+ mod.backtrace_filter = mod::BacktraceFilter.new(%r!#{mod::BacktraceFilter::MT_RE}|#{filter_exp}!)
24
+ end
25
+ end
26
+
27
+ # Expect the object to be a truthy value
28
+ # @return [Minitest::Expectation]
29
+ def truthy?(msg = nil)
30
+ ctx.assert target, msg
31
+ self
32
+ end
33
+ alias_method :true?, :truthy?
34
+
35
+ # Expect the object to be a falsy value
36
+ # @return [Minitest::Expectation]
37
+ def falsy?(msg = nil)
38
+ ctx.refute target, msg
39
+ self
40
+ end
41
+ alias_method :falsey?, :falsy?
42
+ alias_method :false?, :falsy?
43
+
44
+ # Expect the object to return a truthy value from a predicate, e.g.
45
+ # `expect(new_user).is? :new?`
46
+ # @return [Minitest::Expectation]
47
+ def is?(sym, msg = nil)
48
+ must_be(sym, Minitest::Assertions::UNDEFINED, msg)
49
+ self
50
+ end
51
+
52
+ # Expect the object to return a falsy value from a predicate, e.g.
53
+ # `expect(saved_user).isnt? :new?`
54
+ # @return [Minitest::Expectation]
55
+ def isnt?(sym, msg = nil)
56
+ wont_be(sym, Minitest::Assertions::UNDEFINED, msg)
57
+ self
58
+ end
59
+
60
+ # Expect the object to equal a value
61
+ # @return [Minitest::Expectation]
62
+ def equal?(other, msg = nil)
63
+ must_equal(other, msg)
64
+ self
65
+ end
66
+ alias_method :==, :equal?
67
+
68
+ # Expect the object not to equal a value
69
+ # @return [Minitest::Expectation]
70
+ def not_equal?(other, msg = nil)
71
+ wont_equal(other, msg)
72
+ self
73
+ end
74
+ alias_method :!=, :not_equal?
75
+
76
+ # Expect the object to be within another value (as defined by the `within?`
77
+ # object refinement)
78
+ # @return [Minitest::Expectation]
79
+ def within?(other, msg = nil)
80
+ msg = ctx.message(msg) { "Expected #{ctx.mu_pp target} to be within #{ctx.mu_pp other}" }
81
+ ctx.assert target.within?(other), msg
82
+ self
83
+ end
84
+
85
+ # Expect the object not to be within another value (as defined by the `within?`
86
+ # object refinement)
87
+ # @return [Minitest::Expectation]
88
+ def not_within?(other, msg = nil)
89
+ msg = ctx.message(msg) { "Expected #{ctx.mu_pp target} to not be within #{ctx.mu_pp other}" }
90
+ ctx.refute target.within?(other), msg
91
+ self
92
+ end
93
+
94
+ # Expect the object to be nil
95
+ # @return [Minitest::Expectation]
96
+ def nil?(msg = nil)
97
+ must_be_nil(msg)
98
+ self
99
+ end
100
+
101
+ # Expect the object not to be nil
102
+ # @return [Minitest::Expectation]
103
+ def not_nil?(msg = nil)
104
+ wont_be_nil(msg)
105
+ self
106
+ end
107
+
108
+ # Expect the object (like a string, array, etc.) to be empty
109
+ # @return [Minitest::Expectation]
110
+ def empty?(msg = nil)
111
+ must_be_empty(msg)
112
+ self
113
+ end
114
+
115
+ # Expect the object (like a string, array, etc.) not to be empty
116
+ # @return [Minitest::Expectation]
117
+ def not_empty?(msg = nil)
118
+ wont_be_empty(msg)
119
+ self
120
+ end
121
+ alias_method :filled?, :not_empty?
122
+
123
+ # Expect the object (like a string, array, etc.) to include another value
124
+ # @return [Minitest::Expectation]
125
+ def include?(other, msg = nil)
126
+ must_include(other, msg)
127
+ self
128
+ end
129
+ alias_method :<<, :include?
130
+
131
+ # Expect the object (like a string, array, etc.) not to include another value
132
+ # @return [Minitest::Expectation]
133
+ def exclude?(other, msg = nil)
134
+ wont_include(other, msg)
135
+ self
136
+ end
137
+ alias_method :not_include?, :exclude?
138
+
139
+ # Expect the object to match a regular expression
140
+ # @return [Minitest::Expectation]
141
+ def match?(other, msg = nil)
142
+ must_match(other, msg)
143
+ self
144
+ end
145
+ alias_method :=~, :match?
146
+
147
+ # Expect the object not to match a regular expression
148
+ # @return [Minitest::Expectation]
149
+ def not_match?(other, msg = nil)
150
+ wont_match(other, msg)
151
+ self
152
+ end
153
+
154
+ # Expect the object to be an instance of a class (or a subclass)
155
+ # @return [Minitest::Expectation]
156
+ def is_a?(klass, msg = nil)
157
+ must_be_kind_of(klass, msg)
158
+ self
159
+ end
160
+ alias_method :kind_of?, :is_a?
161
+
162
+ # Expect the object not to be an instance of a class (or a subclass)
163
+ # @return [Minitest::Expectation]
164
+ def not_a?(klass, msg = nil)
165
+ wont_be_kind_of(klass, msg)
166
+ self
167
+ end
168
+ alias_method :isnt_a?, :not_a?
169
+ alias_method :is_not_a?, :not_a?
170
+ alias_method :not_kind_of?, :not_a?
171
+
172
+ # Expect the block not to raise the exception
173
+ # @return [Minitest::Expectation]
174
+ def raise?(exception, msg = nil)
175
+ Warning.warn "Calling `#{__callee__}` for the same block re-executes the block" if @block_ran
176
+ @block_ran ||= true
177
+ # we need this ternary operator because `must_raise` takes a variable number of arguments
178
+ msg ? must_raise(exception, msg) : must_raise(exception)
179
+ self
180
+ end
181
+
182
+ # Expect the block to send output to stdout and/or stderr
183
+ # @param stdout [String, Regexp]
184
+ # @param stderr [String, Regexp]
185
+ # @return [Minitest::Expectation]
186
+ def output?(stdout = nil, stderr = nil)
187
+ Warning.warn "Calling `#{__callee__}` for the same block re-executes the block" if @block_ran
188
+ @block_ran ||= true
189
+ must_output stdout, stderr
190
+ self
191
+ end
192
+
193
+ # Expect the block not to send output to stdout and stderr
194
+ # @return [Minitest::Expectation]
195
+ def not_output?
196
+ Warning.warn "Calling `#{__callee__}` for the same block re-executes the block" if @block_ran
197
+ @block_ran ||= true
198
+ must_be_silent
199
+ self
200
+ end
201
+ alias_method :silent?, :not_output?
202
+ end
203
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "2.0.3"
4
+ VERSION = "2.0.4"
5
5
  CODE_NAME = "River City"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-foundation
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-18 00:00:00.000000000 Z
11
+ date: 2025-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hash_with_dot_access
@@ -65,6 +65,7 @@ files:
65
65
  - lib/bridgetown-foundation.rb
66
66
  - lib/bridgetown/foundation/core_ext/class.rb
67
67
  - lib/bridgetown/foundation/core_ext/string.rb
68
+ - lib/bridgetown/foundation/intuitive_expectations.rb
68
69
  - lib/bridgetown/foundation/packages/ansi.rb
69
70
  - lib/bridgetown/foundation/packages/pid_tracker.rb
70
71
  - lib/bridgetown/foundation/packages/safe_translations.rb