WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 01de751

Browse files
committed
Remove OpenStruct references, use Data instead
1 parent 0fd48a3 commit 01de751

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

spec/unit/hanami/utils/hash_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "bigdecimal"
4-
require "ostruct"
54
require "hanami/utils/hash"
65

76
RSpec.describe Hanami::Utils::Hash do
@@ -210,9 +209,13 @@
210209

211210
describe ".deep_serialize" do
212211
let(:input) do
213-
klass = Class.new(OpenStruct) do # rubocop:disable Style/OpenStructUse
212+
klass = Class.new do
213+
def initialize(attributes)
214+
@attributes = attributes
215+
end
216+
214217
def to_hash
215-
to_h
218+
@attributes
216219
end
217220
end
218221

spec/unit/hanami/utils/kernel_spec.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# frozen_string_literal: true
22

3-
require "ostruct"
43
require "bigdecimal"
54
require "securerandom"
65
require "hanami/utils/kernel"
7-
8-
# rubocop:disable Style/OpenStructUse
96
RSpec.describe Hanami::Utils::Kernel do
107
describe ".Array" do
118
describe "successful operations" do
@@ -613,7 +610,7 @@ def to_int
613610
end
614611

615612
describe "when a an object that doesn't implement any integer interface" do
616-
let(:input) { OpenStruct.new(color: "purple") }
613+
let(:input) { Data.define(:color).new(color: "purple") }
617614

618615
it "raises error" do
619616
expect { Hanami::Utils::Kernel.Integer(input) }.to raise_error(TypeError)
@@ -1175,7 +1172,7 @@ def to_f
11751172
end
11761173

11771174
describe "when a an object that doesn't implement any float interface" do
1178-
let(:input) { OpenStruct.new(color: "purple") }
1175+
let(:input) { Data.define(:color).new(color: "purple") }
11791176

11801177
it "raises error" do
11811178
expect { Hanami::Utils::Kernel.Float(input) }.to raise_error(TypeError)
@@ -1424,11 +1421,11 @@ def to_str
14241421
end
14251422
end
14261423

1427-
describe "when an open struct is given" do
1428-
let(:input) { OpenStruct.new(title: "DDD") }
1424+
describe "when a data object is given" do
1425+
let(:input) { Data.define(:title).new(title: "DDD") }
14291426

14301427
it "returns the string representation" do
1431-
expect(@result).to eq '#<OpenStruct title="DDD">'
1428+
expect(@result).to eq '#<data title="DDD">'
14321429
end
14331430
end
14341431

@@ -2510,4 +2507,3 @@ def to_sym
25102507
end
25112508
end
25122509
end
2513-
# rubocop:enable Style/OpenStructUse

0 commit comments

Comments
 (0)