dinja 1.1.0 → 1.2.0
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 +4 -4
- data/README.md +41 -1
- data/config/inflections.rb +5 -0
- data/lib/dinja.rb +5 -1
- data/lib/dinja/rspec.rb +20 -0
- data/lib/dinja/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c740560e98de13900ebd205727ab8ab3db61e383e999338ad7af62bd60fa7d4
|
4
|
+
data.tar.gz: 6d52ab750f704ebec9637ab85ce557af9f6fd75066d0c4072c35e8dd0485d0a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4619b5dab77e5e102d2501394a039475744a758e830cfa7f21ec35c6b99af4a0419807f6cf97896d7a70f1cb72c54f02e25242180da7cc7104348b35d8f594b
|
7
|
+
data.tar.gz: b5766618c4379604aecc6619d8d726a369353f1e11633a60998e6a9c295b2d205547a40095e859250fa2e1653958f694ad2c0b787e0d7078ba9e412a979fe7ef
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ module MyGem
|
|
94
94
|
def container
|
95
95
|
@container ||= Dinja::Container.new
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def setup
|
99
99
|
# ...other stuff here
|
100
100
|
|
@@ -123,6 +123,46 @@ my_dependency.name
|
|
123
123
|
# => "foobar"
|
124
124
|
```
|
125
125
|
|
126
|
+
### RSpec
|
127
|
+
|
128
|
+
If you need to mock resolution calls to a container, you can do as following.
|
129
|
+
|
130
|
+
In `spec/rails_helper.rb` or `spec/spec_helper.rb`:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
require "dinja/rspec"
|
134
|
+
include Dinja::RSpec
|
135
|
+
```
|
136
|
+
|
137
|
+
In `config/dependencies.rb`:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
register("my_service") do |name|
|
141
|
+
OpenStruct.new(name: name)
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
In `spec/my_app/my_model_spec.rb`:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
RSpec.describe MyApp::MyModel do
|
149
|
+
subject(:my_model) { described_class.new }
|
150
|
+
|
151
|
+
it "calls my service" do
|
152
|
+
my_service = dinja_mock!("my_service")
|
153
|
+
|
154
|
+
allow(my_service)
|
155
|
+
.to receive(:call)
|
156
|
+
.and_return true
|
157
|
+
|
158
|
+
my_model.call_service
|
159
|
+
|
160
|
+
expect(my_service).to have_received(:call)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
```
|
165
|
+
|
126
166
|
## Development
|
127
167
|
|
128
168
|
To release a new version, update the version number in `lib/dinja/version.rb`, update the changelog, commit the files and create a git tag starting with `v`, and push it to the repository.
|
data/lib/dinja.rb
CHANGED
@@ -15,8 +15,12 @@ module Dinja
|
|
15
15
|
def setup
|
16
16
|
@loader = Zeitwerk::Loader.for_gem
|
17
17
|
|
18
|
-
#
|
18
|
+
# Register inflections
|
19
|
+
require root.join("config/inflections.rb")
|
20
|
+
|
21
|
+
# Do not eager load integrations
|
19
22
|
loader.do_not_eager_load(root.join("lib/dinja/railtie.rb"))
|
23
|
+
loader.do_not_eager_load(root.join("lib/dinja/rspec.rb"))
|
20
24
|
|
21
25
|
loader.setup
|
22
26
|
loader.eager_load
|
data/lib/dinja/rspec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dinja
|
4
|
+
module RSpec
|
5
|
+
def dinja_mock!(key, *args)
|
6
|
+
mock = instance_double(key)
|
7
|
+
|
8
|
+
allow_any_instance_of(Dinja::Container)
|
9
|
+
.to receive(:resolve)
|
10
|
+
.and_call_original
|
11
|
+
|
12
|
+
allow_any_instance_of(Dinja::Container)
|
13
|
+
.to receive(:resolve)
|
14
|
+
.with(key, *args)
|
15
|
+
.and_return mock
|
16
|
+
|
17
|
+
mock
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/dinja/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dinja
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Dejonckheere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -217,9 +217,11 @@ files:
|
|
217
217
|
- Gemfile
|
218
218
|
- LICENSE.md
|
219
219
|
- README.md
|
220
|
+
- config/inflections.rb
|
220
221
|
- lib/dinja.rb
|
221
222
|
- lib/dinja/container.rb
|
222
223
|
- lib/dinja/railtie.rb
|
224
|
+
- lib/dinja/rspec.rb
|
223
225
|
- lib/dinja/version.rb
|
224
226
|
homepage: https://github.com/floriandejonckheere/dinja
|
225
227
|
licenses:
|