Class: Noiseless::TestCase
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- Noiseless::TestCase
- Includes:
- TestHelper
- Defined in:
- lib/noiseless/test_case.rb
Overview
The Ultimate Search Test Case
Automatically includes TestHelper and provides seamless VCR integration. Every test method automatically gets its own VCR cassette.
Usage:
class Search::ProductTest < Noiseless::TestCase
def test_searching_by_name
# Automatically uses cassette: search/product/searching_by_name
results = Search::Product.by_name("Ruby").execute
assert results.any?
end
def
# Override VCR options for this test
noiseless_cassette(record: :new_episodes) do
results = Search::Product.featured.execute
assert results.any?
end
end
end
Class Method Summary collapse
-
.method_added(method_name) ⇒ Object
🎭 Auto-wrap every test method with VCR cassette.
- .reset_test_indexes(*index_names) ⇒ Object
- .setup_test_data(index_name, records, adapter: :primary) ⇒ Object
Instance Method Summary collapse
-
#setup ⇒ Object
🏗️ Test setup and teardown.
- #teardown ⇒ Object
Methods included from TestHelper
included, #print_curl, #print_query, #reset_all_indexes!, #reset_index!, #seed_data!, setup_vcr_configuration, #with_search_instrumentation
Class Method Details
.method_added(method_name) ⇒ Object
🎭 Auto-wrap every test method with VCR cassette
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/noiseless/test_case.rb', line 34 def self.method_added(method_name) return unless method_name.to_s.start_with?("test_") return if @__noiseless_wrapped_methods&.include?(method_name) # Track wrapped methods to avoid infinite recursion @__noiseless_wrapped_methods ||= Set.new @__noiseless_wrapped_methods << method_name # Store original method original_method = instance_method(method_name) # Remove original method remove_method(method_name) # Define wrapped method define_method(method_name) do # Generate cassette name based on class and method cassette_name = generate_test_cassette_name(method_name) # Auto-wrap with VCR cassette, passing the actual test method name noiseless_cassette(cassette_name: cassette_name, test_method: method_name) do original_method.bind_call(self) end end super end |
.reset_test_indexes(*index_names) ⇒ Object
222 223 224 225 226 227 |
# File 'lib/noiseless/test_case.rb', line 222 def reset_test_indexes(*index_names) define_method :setup do super() index_names.each { |name| reset_index!(name) } unless under_vcr_playback? end end |
.setup_test_data(index_name, records, adapter: :primary) ⇒ Object
215 216 217 218 219 220 |
# File 'lib/noiseless/test_case.rb', line 215 def setup_test_data(index_name, records, adapter: :primary) define_method :setup do super() seed_data!(index_name, records, adapter: adapter) unless under_vcr_playback? end end |
Instance Method Details
#setup ⇒ Object
🏗️ Test setup and teardown
63 64 65 66 |
# File 'lib/noiseless/test_case.rb', line 63 def setup super setup_noiseless_test_environment end |
#teardown ⇒ Object
68 69 70 71 |
# File 'lib/noiseless/test_case.rb', line 68 def teardown cleanup_noiseless_test_environment super end |