Class: Familia::Validation::TransactionExpectation
- Inherits:
-
Object
- Object
- Familia::Validation::TransactionExpectation
- Defined in:
- lib/familia/validation/expectations.rb
Overview
Transaction expectation block
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expected_commands ⇒ Object
readonly
Returns the value of attribute expected_commands.
Instance Method Summary collapse
-
#add_expectation(expectation) ⇒ Object
-
#initialize(options = {}) ⇒ TransactionExpectation
constructor
A new instance of TransactionExpectation.
-
#validate_transaction(transaction_block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TransactionExpectation
Returns a new instance of TransactionExpectation.
243 244 245 246 |
# File 'lib/familia/validation/expectations.rb', line 243 def initialize( = {}) @expected_commands = [] @options = end |
Instance Attribute Details
#expected_commands ⇒ Object (readonly)
Returns the value of attribute expected_commands.
241 242 243 |
# File 'lib/familia/validation/expectations.rb', line 241 def expected_commands @expected_commands end |
Instance Method Details
#add_expectation(expectation) ⇒ Object
248 249 250 251 |
# File 'lib/familia/validation/expectations.rb', line 248 def add_expectation(expectation) @expected_commands << expectation self end |
#validate_transaction(transaction_block) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/familia/validation/expectations.rb', line 264 def validate_transaction(transaction_block) return false unless transaction_block.valid? expected_count = @expected_commands.length actual_count = transaction_block.command_count return false if @options[:exact_match] && expected_count != actual_count return false if expected_count > actual_count if @options[:strict_order] validate_strict_order(transaction_block.commands) else validate_flexible_order(transaction_block.commands) end end |