rspec-activerecord-expectations 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +21 -12
- data/lib/rspec/activerecord/expectations/matchers/query_count.rb +54 -4
- data/rspec-activerecord-expectations.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ed8bce8c2576663b3d187efc7ae064c239c9ab8f3e6dacae592563ea4c484fb
|
4
|
+
data.tar.gz: 9e67c875fd8dcab13a8e0ed56b34f842519f1af4f0037f5c8955970cc82f2850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea389afd2110fbaca8c2215507874e1fed2ad1e1f5dae167baaf532d56f91bcfa3f7458a88a71e6ce2de341160ba0fe3f3a25c786641204ebda1f3fe2db707c
|
7
|
+
data.tar.gz: 9ace14690c79ee0ca1e5c9a3841a9769d58b315685e811b253d393c2a5858294153cf1b0e88471b584112391b351173163cd4d6326920654e35d3aac83c6cf77
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -93,9 +93,20 @@ performance regression.
|
|
93
93
|
|
94
94
|
## Supported Matchers
|
95
95
|
|
96
|
+
Listed along with their aliases.
|
97
|
+
|
96
98
|
```ruby
|
99
|
+
expect {}.to execute.less_than(20).queries
|
97
100
|
expect {}.to execute.fewer_than(20).queries
|
98
|
-
|
101
|
+
|
102
|
+
expect {}.to execute.less_than_or_equal_to(20).queries
|
103
|
+
expect {}.to execute.at_most(20).queries
|
104
|
+
|
105
|
+
expect {}.to execute.greater_than(20).queries
|
106
|
+
expect {}.to execute.more_than(20).queries
|
107
|
+
|
108
|
+
expect {}.to execute.greater_than_or_equal_to(20).queries
|
109
|
+
expect {}.to execute.at_least(20).queries
|
99
110
|
```
|
100
111
|
|
101
112
|
## Future Planned Functionality
|
@@ -103,17 +114,16 @@ expect {}.to execute.less_than(20).queries # alias for fewer_than
|
|
103
114
|
This gem still has lots of future functionality. See below.
|
104
115
|
|
105
116
|
```ruby
|
106
|
-
expect {}.to execute.more_than(20).activerecord_queries
|
107
|
-
expect {}.to execute.fewer_than(20).insert_queries
|
108
117
|
expect {}.to execute.exactly(5).queries
|
109
|
-
expect {}.to execute.at_least(5).handrolled_queries
|
110
118
|
|
111
|
-
expect {}.to execute.
|
112
|
-
expect {}.to execute.
|
113
|
-
expect {}.to execute.
|
114
|
-
expect {}.to execute.
|
115
|
-
expect {}.to execute.
|
116
|
-
expect {}.to execute.
|
119
|
+
expect {}.to execute.at_least(2).activerecord_queries
|
120
|
+
expect {}.to execute.at_least(2).insert_queries
|
121
|
+
expect {}.to execute.at_least(2).delete_queries
|
122
|
+
expect {}.to execute.at_least(2).load_queries
|
123
|
+
expect {}.to execute.at_least(2).schema_queries
|
124
|
+
expect {}.to execute.at_least(2).exists_queries
|
125
|
+
expect {}.to execute.at_least(2).queries_of_type("Audited::Audit Load")
|
126
|
+
expect {}.to execute.at_least(2).hand_rolled_queries
|
117
127
|
|
118
128
|
expect {}.not_to rollback_transaction.exactly(5).times
|
119
129
|
expect {}.not_to commit_transaction.once
|
@@ -126,8 +136,7 @@ expect {}.to delete.exactly(2).of_any_type
|
|
126
136
|
|
127
137
|
expect {}.not_to repeatedly_load(Audited::Audit)
|
128
138
|
|
129
|
-
|
130
|
-
exactly(1) => once?
|
139
|
+
expect {}.to execute.at_least(1).query
|
131
140
|
```
|
132
141
|
|
133
142
|
- ignore transactionals (begin / rollback)
|
@@ -26,12 +26,33 @@ module RSpec::ActiveRecord::Expectations
|
|
26
26
|
|
27
27
|
# COMPARISON TYPES
|
28
28
|
|
29
|
-
def
|
29
|
+
def less_than(n)
|
30
30
|
@comparison = n
|
31
|
-
@match_method = method(:
|
31
|
+
@match_method = method(:compare_less_than)
|
32
32
|
self
|
33
33
|
end
|
34
|
-
alias_method :
|
34
|
+
alias_method :fewer_than, :less_than
|
35
|
+
|
36
|
+
def less_than_or_equal_to(n)
|
37
|
+
@comparison = n
|
38
|
+
@match_method = method(:compare_less_than_or_equal_to)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
alias_method :at_most, :less_than_or_equal_to
|
42
|
+
|
43
|
+
def greater_than(n)
|
44
|
+
@comparison = n
|
45
|
+
@match_method = method(:compare_greater_than)
|
46
|
+
self
|
47
|
+
end
|
48
|
+
alias_method :more_than, :greater_than
|
49
|
+
|
50
|
+
def greater_than_or_equal_to(n)
|
51
|
+
@comparison = n
|
52
|
+
@match_method = method(:compare_greater_than_or_equal_to)
|
53
|
+
self
|
54
|
+
end
|
55
|
+
alias_method :at_least, :greater_than_or_equal_to
|
35
56
|
|
36
57
|
# TARGET QUERY TYPES
|
37
58
|
|
@@ -44,7 +65,7 @@ module RSpec::ActiveRecord::Expectations
|
|
44
65
|
|
45
66
|
# MATCHERS
|
46
67
|
|
47
|
-
def
|
68
|
+
def compare_less_than
|
48
69
|
count = @collector.queries_of_type(@query_type)
|
49
70
|
|
50
71
|
@failure_message = "expected block to execute fewer than #{@comparison} queries, but it executed #{count}"
|
@@ -52,6 +73,35 @@ module RSpec::ActiveRecord::Expectations
|
|
52
73
|
|
53
74
|
count < @comparison
|
54
75
|
end
|
76
|
+
|
77
|
+
def compare_less_than_or_equal_to
|
78
|
+
count = @collector.queries_of_type(@query_type)
|
79
|
+
|
80
|
+
# boy this negated operator is confusing. don't use that plz.
|
81
|
+
@failure_message = "expected block to execute at most #{@comparison} queries, but it executed #{count}"
|
82
|
+
@failure_message_when_negated = "expected block not to execute any less than #{@comparison} queries, but it executed #{count}"
|
83
|
+
|
84
|
+
count <= @comparison
|
85
|
+
end
|
86
|
+
|
87
|
+
def compare_greater_than
|
88
|
+
count = @collector.queries_of_type(@query_type)
|
89
|
+
|
90
|
+
@failure_message = "expected block to execute greater than #{@comparison} queries, but it executed #{count}"
|
91
|
+
@failure_message_when_negated = "expected block not to execute greater than #{@comparison} queries, but it executed #{count}"
|
92
|
+
|
93
|
+
count > @comparison
|
94
|
+
end
|
95
|
+
|
96
|
+
def compare_greater_than_or_equal_to
|
97
|
+
count = @collector.queries_of_type(@query_type)
|
98
|
+
|
99
|
+
# see above, negating this matcher is so confusing.
|
100
|
+
@failure_message = "expected block to execute at least #{@comparison} queries, but it executed #{count}"
|
101
|
+
@failure_message_when_negated = "expected block not to execute any more than #{@comparison} queries, but it executed #{count}"
|
102
|
+
|
103
|
+
count >= @comparison
|
104
|
+
end
|
55
105
|
end
|
56
106
|
end
|
57
107
|
end
|