README.md in rails_sql_counter-0.1.1 vs README.md in rails_sql_counter-0.2.0
- old
+ new
@@ -27,25 +27,51 @@
### Methods
* **start**: starts to count sql queries
* **end**: ends to count sql queries
-* **counter**: returns number of sql quieries from start
+* **counter**: returns number of sql queries from start
+* **profile**: syntax sugar to facilitate start/end
## Usage
Test example:
-
```ruby
context '...' do
before { RailsSqlCounter.start }
after { RailsSqlCounter.end }
it 'returns results with only one query' do
get path
expect(RailsSqlCounter.counter).to eq(1)
end
+end
+
+# You could also use .profile
+context '...' do
+ it 'returns results with only one query' do
+ RailsSqlCounter.profile { get path }
+
+ expect(RailsSqlCounter.counter).to eq(1)
+ end
+end
+```
+You may want to wrap the tests as:
+
+```ruby
+config.around(:each, :max_queries) do |example|
+ RailsSqlCounter.profile { example.run }
+
+ if RailsSqlCounter.counter > example.metadata[:max_queries]
+ raise 'Maximum number of queries overpassed.'
+ end
+end
+
+(...)
+
+it 'returns results with only one query', max_queries: 1 do
+ get path
end
```
## Development