magic-support 0.1.0 → 0.2.1

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: 9f7037e20104047261af68821013d1bc6b2bb56fdd45b6f598d3cd59cf0eac11
4
- data.tar.gz: c03b20aa6bf855ea037ec6779cb7c396705c7daed59a44fff7b515b82c63b6a9
3
+ metadata.gz: b309e0c4212931c949a0cfe73bc7aea984ad4eb4d70c8dbadf433e224147d9f9
4
+ data.tar.gz: bf84fd93b7fcfa2ac15a4b89e440cd3ee1cae63f779ca67d6b74244aa28b92e4
5
5
  SHA512:
6
- metadata.gz: 9b8d8c4f7b1af05776084e0a87839b357e9653267cac8c00a0fcd6f27e975e84f2b0b581ad3bbceecb1d5c45433334c0afbb6e11cd86c676a28593f6b3354673
7
- data.tar.gz: 6bac701a2559fa55207d088da2d004b2d7e0cc012007f352e6c9d45fdcd577aa094fb71b1afbae1b7ade2be7706a1cc4846cfe45cdfa55299156b52028d8b6f7
6
+ metadata.gz: cbbf0b2f3347a495e5265391b529a42c42692e8d35ee7e5ff532faecd1e55c8602443df7524318bf5bd9f39efba608cf4ef344f4d7b0a679839062ef4fe01339
7
+ data.tar.gz: b62b4ec44998f16f0bc04293938d93883157c276d4f2ba537fc60abf38f62990f59e1aa58652391846dd10184f114c1306606d90dc6727b803fb75401919f727
data/.rubocop.yml CHANGED
@@ -2,6 +2,6 @@ inherit_from:
2
2
  - https://github.com/Alexander-Senko/Alexander-Senko/raw/refs/heads/main/.rubocop.yml
3
3
  - https://github.com/Alexander-Senko/Alexander-Senko/raw/refs/heads/main/.rubocop-rspec.yml
4
4
 
5
- require:
5
+ plugins:
6
6
  - rubocop-rspec
7
7
  - rubocop-rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,37 @@
1
+ ## [0.2.1] — 2025-05-13
2
+
3
+ ### RSpec
4
+
5
+ #### Method specs
6
+
7
+ ##### Fixed
8
+
9
+ - Method specs with implicit subjects got broken in v0.2.0.
10
+
11
+
12
+ ## [0.2.0] — 2025-05-13
13
+
14
+ ### Core extensions
15
+
16
+ #### Fixed
17
+
18
+ - Don’t forget to `require 'pathname'` as it’s not a core class.
19
+ - Don’t load all core extensions unless required explicitly.
20
+
21
+ ### RSpec
22
+
23
+ #### Method specs
24
+
25
+ ##### Added
26
+
27
+ - Receiver objects are exposed via `receiver`.
28
+ - Emit warnings on missing methods.
29
+
30
+ ##### Fixed
31
+
32
+ - Don’t swallow unrelated name errors.
33
+
34
+
1
35
  ## [0.1.0] — 2024-11-28
2
36
 
3
37
  ### Added
data/README.md CHANGED
@@ -19,18 +19,16 @@ It’s inspired by [Active Support](
19
19
 
20
20
  ## Installation
21
21
 
22
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
23
-
24
- Install the gem and add to the application's Gemfile by executing:
22
+ Install the gem and add to the application’s Gemfile by executing:
25
23
 
26
24
  ```bash
27
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
25
+ bundle add magic-support
28
26
  ```
29
27
 
30
- If bundler is not being used to manage dependencies, install the gem by executing:
28
+ If Bundler is not being used to manage dependencies, install the gem by executing:
31
29
 
32
30
  ```bash
33
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
31
+ gem install magic-support
34
32
  ```
35
33
 
36
34
  ## Core extensions
@@ -107,7 +105,7 @@ It holds authors info to be used primarily in gem specs.
107
105
  Pre-install Magic Support if you plan to use `Gem::Author` in your gemspec.
108
106
 
109
107
  ```bash
110
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
108
+ gem install magic-support
111
109
  ```
112
110
 
113
111
  #### Usage
@@ -186,6 +184,7 @@ In cases when the method couldn’t be found (e.g., due to delegation via `metho
186
184
  instead.
187
185
  Anyway, one may treat it as something _callable_.
188
186
 
187
+ A receiver object is exposed via `receiver`.
189
188
  A method name is exposed as a `Symbol` via `method_name`.
190
189
 
191
190
  > [!NOTE]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'magic/core_ext'
3
+ require_relative 'utils'
4
4
 
5
5
  Magic::CoreExt.kernel do
6
6
  # Yields self to the block and returns the result of the block if it’s
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magic # :nodoc:
4
+ module CoreExt # :nodoc:
5
+ module Kernel
6
+ # Some classes copy Kernel methods on initialization instead of
7
+ # including Kernel itself. Thus, new methods should be defined
8
+ # explicitly for them.
9
+ MODULES = [ # classes/modules including Kernel methods
10
+ ::Kernel,
11
+ (Delegator if defined? Delegator),
12
+ ].compact.freeze
13
+ end
14
+
15
+ module_function
16
+
17
+ def kernel(&)
18
+ Module.new(&).tap do |kernel|
19
+ Kernel::MODULES.each { _1.include kernel }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,27 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'magic/core_ext'
3
+ require 'magic/loader'
4
4
 
5
- module Magic # :nodoc:
6
- module CoreExt # :nodoc:
7
- module Kernel
8
- # Some classes copy Kernel methods on initialization instead of
9
- # including Kernel itself. Thus, new methods should be defined
10
- # explicitly for them.
11
- MODULES = [ # classes/modules including Kernel methods
12
- ::Kernel,
13
- (Delegator if defined? Delegator),
14
- ].compact.freeze
15
- end
16
-
17
- module_function
18
-
19
- def kernel(&)
20
- Module.new(&).tap do |kernel|
21
- Kernel::MODULES.each { _1.include kernel }
22
- end
23
- end
24
- end
25
-
26
- CoreExt.require_all __FILE__
27
- end
5
+ Magic::Loader.require_all
@@ -1,17 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Magic # :nodoc:
4
- module CoreExt # :nodoc:
5
- module_function
3
+ require 'magic/loader'
6
4
 
7
- def require_all scope = __FILE__
8
- scope
9
- .delete_suffix('.rb')
10
- .then { Pathname _1 }
11
- .glob('*.rb')
12
- .each { require _1 }
13
- end
14
- end
15
-
16
- CoreExt.require_all
17
- end
5
+ Magic::Loader.require_all
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Magic # :nodoc:
6
+ module Loader # :nodoc:
7
+ module_function
8
+
9
+ def require_all scope = caller_locations[0].path
10
+ Pathname(scope)
11
+ .sub_ext('')
12
+ .glob('*.rb')
13
+ .each { require _1 }
14
+ end
15
+ end
16
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Magic
4
4
  module Support
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
data/lib/rspec/method.rb CHANGED
@@ -30,22 +30,21 @@ module RSpec # :nodoc:
30
30
  subject_method = subject_method.super_method or break
31
31
  end
32
32
 
33
- define_method :subject do
34
- receiver =
35
- case [ scope, subject_method&.bind_call(self) || super() ]
36
- in '#', receiver
37
- receiver
38
- in '.', Module => receiver
39
- receiver
40
- in '.', receiver
41
- receiver.class
42
- end
43
-
44
- receiver.method name
45
- rescue NameError
46
- # TODO: emit a warning
47
-
48
- -> *args { receiver.send name, *args }
33
+ if subject_method
34
+ let(:__subject__) { subject_method.bind_call self }
35
+ else
36
+ let(:__subject__) { method(:subject).super_method[] }
37
+ end
38
+
39
+ let :receiver do
40
+ case [ scope, __subject__ ]
41
+ in '#', receiver
42
+ receiver
43
+ in '.', Module => receiver
44
+ receiver
45
+ in '.', receiver
46
+ receiver.class
47
+ end
49
48
  end
50
49
 
51
50
  let(:method_name) { name.to_sym }
@@ -62,6 +61,17 @@ module RSpec # :nodoc:
62
61
 
63
62
  def its_result(*args, &) = its(args, &)
64
63
  end
64
+
65
+ def subject
66
+ receiver.method method_name
67
+ rescue NameError => error
68
+ raise unless
69
+ (receiver.is_a? error.receiver rescue false)
70
+
71
+ warn "Testing #{error}"
72
+
73
+ -> *args { receiver.send method_name, *args }
74
+ end
65
75
  end
66
76
  end
67
77
 
@@ -1,7 +1,5 @@
1
1
  module Magic
2
2
  module CoreExt
3
- def require_all: (?String) -> Array[Pathname]
4
-
5
3
  def kernel: () { () -> void } -> Module
6
4
  end
7
5
  end
@@ -0,0 +1,5 @@
1
+ module Magic
2
+ module Loader
3
+ def require_all: (?(String | Pathname)) -> Array[Pathname]
4
+ end
5
+ end
data/sig/rspec/method.rbs CHANGED
@@ -1,5 +1,9 @@
1
1
  module RSpec
2
2
  module Method
3
3
  REFERENCE: Regexp
4
+
5
+ module ExampleGroup
6
+ def subject: () -> (::Method | Proc)
7
+ end
4
8
  end
5
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Senko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-11-28 00:00:00.000000000 Z
10
+ date: 2025-05-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -40,6 +40,8 @@ files:
40
40
  - lib/magic/core_ext.rb
41
41
  - lib/magic/core_ext/kernel.rb
42
42
  - lib/magic/core_ext/kernel/optional.rb
43
+ - lib/magic/core_ext/kernel/utils.rb
44
+ - lib/magic/loader.rb
43
45
  - lib/magic/support.rb
44
46
  - lib/magic/support/authors.rb
45
47
  - lib/magic/support/version.rb
@@ -48,6 +50,7 @@ files:
48
50
  - sig/lib/magic/support/author.rbs
49
51
  - sig/magic/core_ext.rbs
50
52
  - sig/magic/core_ext/kernel.rbs
53
+ - sig/magic/loader.rbs
51
54
  - sig/magic/support.rbs
52
55
  - sig/rspec/method.rbs
53
56
  - sig/rubygems/author.rbs
@@ -56,7 +59,7 @@ licenses:
56
59
  - MIT
57
60
  metadata:
58
61
  source_code_uri: https://github.com/Alexander-Senko/magic-support
59
- changelog_uri: https://github.com/Alexander-Senko/magic-support/blob/v0.1.0/CHANGELOG.md
62
+ changelog_uri: https://github.com/Alexander-Senko/magic-support/blob/v0.2.1/CHANGELOG.md
60
63
  rdoc_options: []
61
64
  require_paths:
62
65
  - lib
@@ -71,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
74
  - !ruby/object:Gem::Version
72
75
  version: '0'
73
76
  requirements: []
74
- rubygems_version: 3.6.0.dev
77
+ rubygems_version: 3.6.5
75
78
  specification_version: 4
76
79
  summary: Active Support extended
77
80
  test_files: []