-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from dry-rb/set-dependencies-before-super
Set dependency ivars before call to super in generated #initialize methods
- Loading branch information
Showing
6 changed files
with
155 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "args / super #initialize method" do | ||
before do | ||
module Test | ||
AutoInject = Dry::AutoInject(one: "dep 1") | ||
end | ||
end | ||
|
||
describe "super #initialize using on dependencies set in the child class" do | ||
let(:child_class) { | ||
Class.new(parent_class) do | ||
include Test::AutoInject.args[:one] | ||
end | ||
} | ||
|
||
context "super #initialize without parameters" do | ||
let(:parent_class) { | ||
Class.new do | ||
attr_reader :excited_one | ||
|
||
def initialize | ||
@excited_one = "#{one}!" | ||
end | ||
end | ||
} | ||
|
||
it "sets the dependencies in the generated #initialize before calling super" do | ||
expect(child_class.new.excited_one).to eq "dep 1!" | ||
end | ||
end | ||
|
||
context "super #initiailze with parameters" do | ||
let(:parent_class) { | ||
Class.new do | ||
attr_reader :excited_one | ||
|
||
def initialize(one) | ||
@excited_one = "#{one}!" | ||
end | ||
end | ||
} | ||
|
||
it "sets the dependenceies in the generated #initialize before caling super" do | ||
expect(child_class.new.excited_one).to eq "dep 1!" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "hash / super #initialize method" do | ||
before do | ||
module Test | ||
AutoInject = Dry::AutoInject(one: "dep 1") | ||
end | ||
end | ||
|
||
describe "super #initialize using on dependencies set in the child class" do | ||
let(:child_class) { | ||
Class.new(parent_class) do | ||
include Test::AutoInject.hash[:one] | ||
end | ||
} | ||
|
||
context "super #initialize without parameters" do | ||
let(:parent_class) { | ||
Class.new do | ||
attr_reader :excited_one | ||
|
||
def initialize | ||
@excited_one = "#{one}!" | ||
end | ||
end | ||
} | ||
|
||
it "sets the dependencies in the generated #initialize before calling super" do | ||
expect(child_class.new.excited_one).to eq "dep 1!" | ||
end | ||
end | ||
|
||
context "super #initiailze with parameters" do | ||
let(:parent_class) { | ||
Class.new do | ||
attr_reader :excited_one | ||
|
||
def initialize(options = {}) | ||
@excited_one = "#{one}!" | ||
@two = options.fetch(:two) | ||
end | ||
end | ||
} | ||
|
||
it "sets the dependenceies in the generated #initialize before caling super" do | ||
expect(child_class.new(two: "_").excited_one).to eq "dep 1!" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters