Skip to content

Commit 1d5d4bf

Browse files
committed
Replace OpenStruct with Struct
1 parent cb957b3 commit 1d5d4bf

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
tailwindcss-rails (4.2.2)
4+
tailwindcss-rails (4.2.3)
55
railties (>= 7.0.0)
66
tailwindcss-ruby (~> 4.0)
77

test/lib/tailwindcss/commands_test.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "test_helper"
2-
require "ostruct"
32
require "minitest/mock"
43

54
class Tailwindcss::CommandsTest < ActiveSupport::TestCase
@@ -227,6 +226,13 @@ def self.root
227226
end
228227

229228
private
229+
# Define Structs outside of methods to avoid redefining them
230+
ConfigStruct = Struct.new(:engines)
231+
AssetsStruct = Struct.new(:css_compressor)
232+
TailwindStruct = Struct.new(:tailwindcss_rails, :assets)
233+
AppStruct = Struct.new(:config)
234+
EngineStruct = Struct.new(:name, :root, :css_path)
235+
230236
def with_rails_app
231237
Object.send(:remove_const, :Rails) if Object.const_defined?(:Rails)
232238
Object.const_set(:Rails, setup_mock_rails)
@@ -257,12 +263,10 @@ def const_get(const_name)
257263

258264
mock_rails.const_set(:Engine, mock_engine)
259265
mock_rails.root = Pathname.new(@tmp_dir)
260-
mock_rails.application = OpenStruct.new(
261-
config: OpenStruct.new(
262-
tailwindcss_rails: OpenStruct.new(engines: []),
263-
assets: OpenStruct.new(css_compressor: nil)
264-
)
265-
)
266+
tailwind_config = ConfigStruct.new([])
267+
assets_config = AssetsStruct.new(nil)
268+
app_config = TailwindStruct.new(tailwind_config, assets_config)
269+
mock_rails.application = AppStruct.new(app_config)
266270
mock_rails
267271
end
268272

@@ -290,10 +294,11 @@ def within_engine_configs
290294

291295
def create_test_engines
292296
[1, 2, 3].map do |i|
293-
engine = OpenStruct.new
294-
engine.name = "test_engine#{i}"
295-
engine.root = File.join(@tmp_dir, "engine#{i}")
296-
engine.css_path = File.join(@tmp_dir, "app/assets/tailwind/test_engine#{i}/application.css")
297+
engine = EngineStruct.new(
298+
"test_engine#{i}",
299+
File.join(@tmp_dir, "engine#{i}"),
300+
File.join(@tmp_dir, "app/assets/tailwind/test_engine#{i}/application.css")
301+
)
297302
FileUtils.mkdir_p(File.dirname(engine.css_path))
298303
FileUtils.touch(engine.css_path)
299304
engine

0 commit comments

Comments
 (0)