Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #318 from benedikt/master
Browse files Browse the repository at this point in the history
Allow overrides to be `nil`
  • Loading branch information
paulelliott committed Apr 2, 2020
2 parents 2fe931c + ffd0153 commit 586c110
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fabrication/generator/base.rb
Expand Up @@ -76,7 +76,7 @@ def initialize(klass)
end

def method_missing(method_name, *args, &block)
_attributes[method_name] || super
_attributes.fetch(method_name) { super }
end

protected
Expand Down
9 changes: 8 additions & 1 deletion spec/fabrication/generator/base_spec.rb
Expand Up @@ -85,7 +85,7 @@
let(:schematic) do
Fabrication::Schematic::Definition.new('ClassWithInit') do
arg1 10
initialize_with { Struct.new(:arg1, :arg2).new(arg1, arg1 + 10) }
initialize_with { Struct.new(:arg1, :arg2).new(arg1, arg1.to_i + 10) }
end
end

Expand All @@ -104,6 +104,13 @@
end
end

context "with nil override" do
subject { schematic.fabricate(arg1: nil) }
it "saves the return value of the block as instance" do
expect(subject.arg1).to eq(nil)
expect(subject.arg2).to eq(10)
end
end
end
end

Expand Down

0 comments on commit 586c110

Please sign in to comment.