Module: RSpecPower::ActiveRecordHelpers
- Defined in:
- lib/rspec_power/sql.rb
Instance Method Summary collapse
-
#expect_no_sql ⇒ Object
Fails the example if any SQL is executed within the provided block.
-
#expect_sql ⇒ Object
Passes only if at least one SQL statement is executed within the block.
Instance Method Details
#expect_no_sql ⇒ Object
Fails the example if any SQL is executed within the provided block. Ignores cached, schema, and transaction events to avoid false positives.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rspec_power/sql.rb', line 5 def expect_no_sql raise ArgumentError, "expect_no_sql requires a block" unless block_given? executed_sql_statements = capture_executed_sql { yield } if executed_sql_statements.any? = "Expected no SQL to be executed, but #{executed_sql_statements.length} statement(s) were run.\n" \ + executed_sql_statements.map { |sql| " - #{sql}" }.join("\n") raise RSpec::Expectations::ExpectationNotMetError, end end |
#expect_sql ⇒ Object
Passes only if at least one SQL statement is executed within the block. Ignores cached, schema, and transaction events to avoid false positives.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rspec_power/sql.rb', line 19 def expect_sql raise ArgumentError, "expect_sql requires a block" unless block_given? executed_sql_statements = capture_executed_sql { yield } if executed_sql_statements.empty? raise RSpec::Expectations::ExpectationNotMetError, "Expected some SQL to be executed, but none was run" end end |