diff --git a/README.md b/README.md index c231ed1..45823dc 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ expect { User.last }.to query_database # Assert no database queries: expect { nil }.to_not query_database -# Assert exactly one query: +# Assert exact number of queries: expect { User.last }.to query_database 1 +expect { User.create }.to query_database 3.times # Assert specific queries: expect { User.last }.to query_database ["User Load"] diff --git a/lib/rspec/sql.rb b/lib/rspec/sql.rb index 5e7bbcc..b384bb6 100644 --- a/lib/rspec/sql.rb +++ b/lib/rspec/sql.rb @@ -14,6 +14,8 @@ module Sql; end !@queries.empty? elsif expected.is_a?(Integer) @queries.size == expected + elsif expected.is_a?(Enumerator) && expected.inspect.match?(/:times>$/) + @queries.size == expected.size elsif expected.is_a?(Array) query_names == expected else diff --git a/spec/lib/rspec/sql_spec.rb b/spec/lib/rspec/sql_spec.rb index d63f36c..7178458 100644 --- a/spec/lib/rspec/sql_spec.rb +++ b/spec/lib/rspec/sql_spec.rb @@ -30,6 +30,7 @@ it "expects a number of database queries" do expect { User.last }.to query_database 1 + expect { User.create! }.to query_database 3.times expect { expect { User.last }.to query_database 2