2929 } )
3030 end
3131
32- describe ".load_custom_instrument_plugins" do
33- it "loads custom stats instrument plugins" do
34- # Create a custom stats plugin file
35- custom_stats_content = <<~RUBY
32+ describe ".load_custom_instrument_plugins" do
33+ it "loads custom stats instrument plugins" do
34+ # Create a custom stats plugin file
35+ custom_stats_content = <<~RUBY
3636 class CustomStats < Hooks::Plugins::Instruments::StatsBase
3737 def record(metric_name, value, tags = {})
3838 # Custom implementation
@@ -48,17 +48,17 @@ def timing(metric_name, duration, tags = {})
4848 end
4949 RUBY
5050
51- File . write ( File . join ( test_plugin_dir , "custom_stats.rb" ) , custom_stats_content )
51+ File . write ( File . join ( test_plugin_dir , "custom_stats.rb" ) , custom_stats_content )
5252
53- expect { described_class . send ( :load_custom_instrument_plugins , test_plugin_dir ) } . not_to raise_error
53+ expect { described_class . send ( :load_custom_instrument_plugins , test_plugin_dir ) } . not_to raise_error
5454
55- # Verify the stats plugin was loaded
56- expect ( described_class . instrument_plugins [ :stats ] ) . to be_a ( CustomStats )
57- end
55+ # Verify the stats plugin was loaded
56+ expect ( described_class . instrument_plugins [ :stats ] ) . to be_a ( CustomStats )
57+ end
5858
59- it "loads custom failbot instrument plugins" do
60- # Create a custom failbot plugin file
61- custom_failbot_content = <<~RUBY
59+ it "loads custom failbot instrument plugins" do
60+ # Create a custom failbot plugin file
61+ custom_failbot_content = <<~RUBY
6262 class CustomFailbot < Hooks::Plugins::Instruments::FailbotBase
6363 def report(error_or_message, context = {})
6464 # Custom implementation
@@ -74,114 +74,114 @@ def warning(message, context = {})
7474 end
7575 RUBY
7676
77- File . write ( File . join ( test_plugin_dir , "custom_failbot.rb" ) , custom_failbot_content )
77+ File . write ( File . join ( test_plugin_dir , "custom_failbot.rb" ) , custom_failbot_content )
7878
79- expect { described_class . send ( :load_custom_instrument_plugins , test_plugin_dir ) } . not_to raise_error
79+ expect { described_class . send ( :load_custom_instrument_plugins , test_plugin_dir ) } . not_to raise_error
8080
81- # Verify the failbot plugin was loaded
82- expect ( described_class . instrument_plugins [ :failbot ] ) . to be_a ( CustomFailbot )
83- end
81+ # Verify the failbot plugin was loaded
82+ expect ( described_class . instrument_plugins [ :failbot ] ) . to be_a ( CustomFailbot )
83+ end
8484
85- it "raises error for invalid inheritance" do
86- # Create an invalid plugin file that doesn't inherit from base classes
87- invalid_content = <<~RUBY
85+ it "raises error for invalid inheritance" do
86+ # Create an invalid plugin file that doesn't inherit from base classes
87+ invalid_content = <<~RUBY
8888 class InvalidInstrument
8989 def some_method
9090 # This doesn't inherit from the right base class
9191 end
9292 end
9393 RUBY
9494
95- File . write ( File . join ( test_plugin_dir , "invalid_instrument.rb" ) , invalid_content )
95+ File . write ( File . join ( test_plugin_dir , "invalid_instrument.rb" ) , invalid_content )
9696
97- expect do
98- described_class . send ( :load_custom_instrument_plugins , test_plugin_dir )
99- end . to raise_error ( StandardError , /must inherit from StatsBase or FailbotBase/ )
100- end
97+ expect do
98+ described_class . send ( :load_custom_instrument_plugins , test_plugin_dir )
99+ end . to raise_error ( StandardError , /must inherit from StatsBase or FailbotBase/ )
100+ end
101101
102- it "validates class names for security" do
103- malicious_content = <<~RUBY
102+ it "validates class names for security" do
103+ malicious_content = <<~RUBY
104104 class File < Hooks::Plugins::Instruments::StatsBase
105105 def record(metric_name, value, tags = {})
106106 # Malicious implementation
107107 end
108108 end
109109 RUBY
110110
111- File . write ( File . join ( test_plugin_dir , "file.rb" ) , malicious_content )
112-
113- expect do
114- described_class . send ( :load_custom_instrument_plugins , test_plugin_dir )
115- end . to raise_error ( StandardError , /Invalid instrument plugin class name/ )
116- end
117- end
118-
119- describe ".get_instrument_plugin" do
120- before do
121- # Load default instruments
122- described_class . send ( :load_default_instruments )
123- end
124-
125- it "returns the stats instrument" do
126- stats = described_class . get_instrument_plugin ( :stats )
127- expect ( stats ) . to be_a ( Hooks ::Plugins ::Instruments ::Stats )
128- end
111+ File . write ( File . join ( test_plugin_dir , "file.rb" ) , malicious_content )
129112
130- it "returns the failbot instrument" do
131- failbot = described_class . get_instrument_plugin ( :failbot )
132- expect ( failbot ) . to be_a ( Hooks ::Plugins ::Instruments ::Failbot )
113+ expect do
114+ described_class . send ( :load_custom_instrument_plugins , test_plugin_dir )
115+ end . to raise_error ( StandardError , /Invalid instrument plugin class name/ )
116+ end
133117 end
134118
135- it "raises error for unknown instrument type" do
136- expect do
137- described_class . get_instrument_plugin ( :unknown )
138- end . to raise_error ( StandardError , "Instrument plugin 'unknown' not found" )
119+ describe ".get_instrument_plugin" do
120+ before do
121+ # Load default instruments
122+ described_class . send ( :load_default_instruments )
123+ end
124+
125+ it "returns the stats instrument" do
126+ stats = described_class . get_instrument_plugin ( :stats )
127+ expect ( stats ) . to be_a ( Hooks ::Plugins ::Instruments ::Stats )
128+ end
129+
130+ it "returns the failbot instrument" do
131+ failbot = described_class . get_instrument_plugin ( :failbot )
132+ expect ( failbot ) . to be_a ( Hooks ::Plugins ::Instruments ::Failbot )
133+ end
134+
135+ it "raises error for unknown instrument type" do
136+ expect do
137+ described_class . get_instrument_plugin ( :unknown )
138+ end . to raise_error ( StandardError , "Instrument plugin 'unknown' not found" )
139+ end
139140 end
140- end
141141
142- describe ".load_default_instruments" do
143- it "loads default stats and failbot instances" do
144- described_class . send ( :load_default_instruments )
142+ describe ".load_default_instruments" do
143+ it "loads default stats and failbot instances" do
144+ described_class . send ( :load_default_instruments )
145145
146- expect ( described_class . instrument_plugins [ :stats ] ) . to be_a ( Hooks ::Plugins ::Instruments ::Stats )
147- expect ( described_class . instrument_plugins [ :failbot ] ) . to be_a ( Hooks ::Plugins ::Instruments ::Failbot )
148- end
146+ expect ( described_class . instrument_plugins [ :stats ] ) . to be_a ( Hooks ::Plugins ::Instruments ::Stats )
147+ expect ( described_class . instrument_plugins [ :failbot ] ) . to be_a ( Hooks ::Plugins ::Instruments ::Failbot )
148+ end
149149
150- it "doesn't override custom instruments if already loaded" do
151- # Create custom stats
152- custom_stats_content = <<~RUBY
150+ it "doesn't override custom instruments if already loaded" do
151+ # Create custom stats
152+ custom_stats_content = <<~RUBY
153153 class MyCustomStats < Hooks::Plugins::Instruments::StatsBase
154154 def record(metric_name, value, tags = {})
155155 # Custom implementation
156156 end
157157 end
158158 RUBY
159159
160- File . write ( File . join ( test_plugin_dir , "my_custom_stats.rb" ) , custom_stats_content )
161- described_class . send ( :load_custom_instrument_plugins , test_plugin_dir )
160+ File . write ( File . join ( test_plugin_dir , "my_custom_stats.rb" ) , custom_stats_content )
161+ described_class . send ( :load_custom_instrument_plugins , test_plugin_dir )
162162
163- # Load defaults
164- described_class . send ( :load_default_instruments )
163+ # Load defaults
164+ described_class . send ( :load_default_instruments )
165165
166- # Should still have custom stats, but default failbot
167- expect ( described_class . instrument_plugins [ :stats ] ) . to be_a ( MyCustomStats )
168- expect ( described_class . instrument_plugins [ :failbot ] ) . to be_a ( Hooks ::Plugins ::Instruments ::Failbot )
166+ # Should still have custom stats, but default failbot
167+ expect ( described_class . instrument_plugins [ :stats ] ) . to be_a ( MyCustomStats )
168+ expect ( described_class . instrument_plugins [ :failbot ] ) . to be_a ( Hooks ::Plugins ::Instruments ::Failbot )
169+ end
169170 end
170- end
171171
172- describe ".valid_instrument_class_name?" do
173- it "accepts valid class names" do
174- expect ( described_class . send ( :valid_instrument_class_name? , "CustomStats" ) ) . to be true
175- expect ( described_class . send ( :valid_instrument_class_name? , "MyCustomFailbot" ) ) . to be true
176- expect ( described_class . send ( :valid_instrument_class_name? , "DatadogStats" ) ) . to be true
172+ describe ".valid_instrument_class_name?" do
173+ it "accepts valid class names" do
174+ expect ( described_class . send ( :valid_instrument_class_name? , "CustomStats" ) ) . to be true
175+ expect ( described_class . send ( :valid_instrument_class_name? , "MyCustomFailbot" ) ) . to be true
176+ expect ( described_class . send ( :valid_instrument_class_name? , "DatadogStats" ) ) . to be true
177+ end
178+
179+ it "rejects invalid class names" do
180+ expect ( described_class . send ( :valid_instrument_class_name? , "" ) ) . to be false
181+ expect ( described_class . send ( :valid_instrument_class_name? , "lowercaseClass" ) ) . to be false
182+ expect ( described_class . send ( :valid_instrument_class_name? , "Class-With-Dashes" ) ) . to be false
183+ expect ( described_class . send ( :valid_instrument_class_name? , "File" ) ) . to be false
184+ end
177185 end
178-
179- it "rejects invalid class names" do
180- expect ( described_class . send ( :valid_instrument_class_name? , "" ) ) . to be false
181- expect ( described_class . send ( :valid_instrument_class_name? , "lowercaseClass" ) ) . to be false
182- expect ( described_class . send ( :valid_instrument_class_name? , "Class-With-Dashes" ) ) . to be false
183- expect ( described_class . send ( :valid_instrument_class_name? , "File" ) ) . to be false
184- end
185- end
186186 end
187- end
187+ end
0 commit comments