sql_matchers 0.0.1 → 1.0.0.pre.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -60
  3. data/lib/sql_matchers/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f1773fdab03f1f4a89f6b58bcdaeb0833ab5666836cd7536acd4627f65e9618
4
- data.tar.gz: ba267a8def94f0e7579e9d0be92dead4504ec0c2a8f02f5d92cc3991adf9f840
3
+ metadata.gz: 9f5583348852121bc9ee574e0e49d9de9dc236775b4cf1866add7764441daa43
4
+ data.tar.gz: 919504f62d430ce28d581b46d85db5dc1343f1183dc3bf2f8a61ef720ecb6106
5
5
  SHA512:
6
- metadata.gz: adf3277acce82bff99919c98242e3aa8dd83145fd3db5349bfc3ee34e07bb1fae2815cb68f0edc33342b0758a64a2d346ede745a21f7f97e1f1e4241e0c16365
7
- data.tar.gz: 35980c31136c6b60c3f462376fc502f752dbf692de108ce38cde0ef9f3d8e56d5618caaad54f861a7b026403784a5a6820d0531f5ad3afb06c815f7fa0e382e0
6
+ metadata.gz: 4fc9a5fcf7dbcd8f781d2ec262c5794356f44731f8196c9cbddad3678c614cd739dd2c5b8055b3487c8626dc038fd5d27d13d536e052e345a4ddd8aae9ddd23d
7
+ data.tar.gz: 622ef54ecd313324d49c1e10ecf95fafcb81382d8006a205f1657cb499e4619b21fd1e2cc122ec353e26f30df028fbd62c7c338b3fea8bfa7668a440597a19a8
data/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  [![CI](https://github.com/keygen-sh/sql_matchers/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/sql_matchers/actions)
4
4
  [![Gem Version](https://badge.fury.io/rb/sql_matchers.svg)](https://badge.fury.io/rb/sql_matchers)
5
5
 
6
- Use `sql_matchers` to create temporary tables and models in RSpec specs,
7
- rather than create and maintain a dummy Rails application or messy block-level
8
- constants.
6
+ Use `sql_matchers` to assert number of queries as well as SQL-level assertions
7
+ in RSpec.
9
8
 
10
9
  This gem was extracted from [Keygen](https://keygen.sh).
11
10
 
@@ -41,68 +40,28 @@ $ gem install sql_matchers
41
40
 
42
41
  ## Usage
43
42
 
44
- ### `temporary_table`
45
-
46
- To define a temporary table:
47
-
48
43
  ```ruby
49
- describe Example do
50
- temporary_table :user do |t|
51
- t.string :email
52
- t.string :first_name
53
- t.string :last_name
54
- t.index :email, unique: true
55
- end
56
-
57
- it 'should define a table' do
58
- expect(ActiveRecord::Base.connection.table_exists?(:user)).to be true
59
- end
44
+ it 'should assert query count' do
45
+ expect { User.count }.to match_query(count: 1)
60
46
  end
61
- ```
62
-
63
- The full Active Record schema API is available.
64
47
 
65
- ### `temporary_model`
66
-
67
- To define an Active Record:
68
-
69
- ```ruby
70
- describe Example do
71
- temporary_model :user do
72
- has_many :posts
73
- end
74
-
75
- it 'should define a record' do
76
- expect(const_defined?(:User)).to be true
77
- end
48
+ it 'should assert query matches' do
49
+ expect { 3.times { User.find_by(id: _1 + 1) } }.to(
50
+ match_queries(count: 3) do |queries|
51
+ first, second, third, *rest = queries
52
+
53
+ expect(first).to eq %(SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1)
54
+ expect(second).to eq %(SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1)
55
+ expect(third).to eq %(SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1)
56
+ expect(rest).to be_empty
57
+ end
58
+ )
78
59
  end
79
- ```
80
60
 
81
- To define an Active Model:
82
-
83
- ```ruby
84
- describe Example do
85
- temporary_model :guest_user, table_name: nil, base_class: nil do
86
- include ActiveModel::Model
87
- end
88
-
89
- it 'should define a model' do
90
- expect(const_defined?(:GuestUser)).to be true
91
- end
92
- end
93
- ```
94
-
95
- To define a PORO:
96
-
97
- ```ruby
98
- describe Example do
99
- temporary_model :null_user, table_name: nil, base_class: nil do
100
- # ...
101
- end
102
-
103
- it 'should define a PORO' do
104
- expect(const_defined?(:NullUser)).to be true
105
- end
61
+ it 'should assert SQL matches' do
62
+ expect(User.where(id: 42).to_sql).to match_sql <<~SQL.squish
63
+ SELECT "users".* FROM "users" WHERE "users"."id" = 42
64
+ SQL
106
65
  end
107
66
  ```
108
67
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SqlMatchers
4
- VERSION = '0.0.1'
4
+ VERSION = '1.0.0-rc.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse
@@ -101,9 +101,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  version: '3.1'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
104
+ - - ">"
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: 1.3.1
107
107
  requirements: []
108
108
  rubygems_version: 3.4.13
109
109
  signing_key: