Class: Familia::Validation::CommandExpectations
- Inherits:
-
Object
- Object
- Familia::Validation::CommandExpectations
- Defined in:
- lib/familia/validation/expectations.rb
Overview
Fluent DSL for defining expected Redis command sequences with support for transaction and pipeline validation. Provides a readable way to specify expected database operations and verify they execute correctly.
Instance Attribute Summary collapse
-
#expected_commands ⇒ Object
readonly
Returns the value of attribute expected_commands.
-
#pipeline_blocks ⇒ Object
readonly
Returns the value of attribute pipeline_blocks.
-
#transaction_blocks ⇒ Object
readonly
Returns the value of attribute transaction_blocks.
Instance Method Summary collapse
-
#allow_extra_commands(enabled = true) ⇒ Object
-
#any_number ⇒ Object
-
#any_string ⇒ Object
Helper methods for common patterns.
-
#any_value ⇒ Object
-
#command(cmd, *args) ⇒ Object
Generic command expectation.
-
#exact_match(enabled = true) ⇒ Object
-
#initialize ⇒ CommandExpectations
constructor
A new instance of CommandExpectations.
-
#match_pattern(pattern, description = nil) ⇒ Object
Pattern matching for flexible expectations.
-
#match_regex(pattern) ⇒ Object
-
#pipeline(&block) ⇒ Object
Pipeline block expectation.
-
#strict_order(enabled = true) ⇒ Object
Configuration methods.
-
#transaction(&block) ⇒ Object
Transaction block expectation.
-
#validate(command_sequence) ⇒ Object
Validate against actual recorded commands.
Constructor Details
#initialize ⇒ CommandExpectations
Returns a new instance of CommandExpectations.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/familia/validation/expectations.rb', line 34 def initialize @expected_commands = [] @transaction_blocks = [] @pipeline_blocks = [] @current_transaction = nil @current_pipeline = nil @options = { strict_order: true, exact_match: true, allow_extra_commands: false } end |
Instance Attribute Details
#expected_commands ⇒ Object (readonly)
Returns the value of attribute expected_commands.
32 33 34 |
# File 'lib/familia/validation/expectations.rb', line 32 def expected_commands @expected_commands end |
#pipeline_blocks ⇒ Object (readonly)
Returns the value of attribute pipeline_blocks.
32 33 34 |
# File 'lib/familia/validation/expectations.rb', line 32 def pipeline_blocks @pipeline_blocks end |
#transaction_blocks ⇒ Object (readonly)
Returns the value of attribute transaction_blocks.
32 33 34 |
# File 'lib/familia/validation/expectations.rb', line 32 def transaction_blocks @transaction_blocks end |
Instance Method Details
#allow_extra_commands(enabled = true) ⇒ Object
58 59 60 61 |
# File 'lib/familia/validation/expectations.rb', line 58 def allow_extra_commands(enabled = true) @options[:allow_extra_commands] = enabled self end |
#any_number ⇒ Object
124 125 126 |
# File 'lib/familia/validation/expectations.rb', line 124 def any_number ArgumentMatcher.new(:any_number) end |
#any_string ⇒ Object
Helper methods for common patterns
120 121 122 |
# File 'lib/familia/validation/expectations.rb', line 120 def any_string ArgumentMatcher.new(:any_string) end |
#any_value ⇒ Object
128 129 130 |
# File 'lib/familia/validation/expectations.rb', line 128 def any_value ArgumentMatcher.new(:any_value) end |
#command(cmd, *args) ⇒ Object
Generic command expectation
104 105 106 |
# File 'lib/familia/validation/expectations.rb', line 104 def command(cmd, *args) add_command_expectation(cmd.to_s.upcase, args) end |
#exact_match(enabled = true) ⇒ Object
53 54 55 56 |
# File 'lib/familia/validation/expectations.rb', line 53 def exact_match(enabled = true) @options[:exact_match] = enabled self end |
#match_pattern(pattern, description = nil) ⇒ Object
Pattern matching for flexible expectations
109 110 111 112 |
# File 'lib/familia/validation/expectations.rb', line 109 def match_pattern(pattern, description = nil) expectation = PatternExpectation.new(pattern, description) add_expectation(expectation) end |
#match_regex(pattern) ⇒ Object
132 133 134 |
# File 'lib/familia/validation/expectations.rb', line 132 def match_regex(pattern) ArgumentMatcher.new(:regex, pattern) end |
#pipeline(&block) ⇒ Object
Pipeline block expectation
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/familia/validation/expectations.rb', line 77 def pipeline(&block) @current_pipeline = PipelineExpectation.new(@options) @pipeline_blocks << @current_pipeline if block_given? block.call(@current_pipeline) @current_pipeline = nil end self end |
#strict_order(enabled = true) ⇒ Object
Configuration methods
48 49 50 51 |
# File 'lib/familia/validation/expectations.rb', line 48 def strict_order(enabled = true) @options[:strict_order] = enabled self end |
#transaction(&block) ⇒ Object
Transaction block expectation
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/familia/validation/expectations.rb', line 64 def transaction(&block) @current_transaction = TransactionExpectation.new(@options) @transaction_blocks << @current_transaction if block_given? block.call(@current_transaction) @current_transaction = nil end self end |
#validate(command_sequence) ⇒ Object
Validate against actual recorded commands
115 116 117 |
# File 'lib/familia/validation/expectations.rb', line 115 def validate(command_sequence) ValidationResult.new(self, command_sequence).validate end |