rspec-activerecord-expectations 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 202f92144b220ec281763d132152aa1bf3cced42d09273d3c050c8c41dab2018
4
- data.tar.gz: f4e4e5f4fce4c3db060c3ea1fcb6752d876fd8b41cc0337dc81308c6acfceb08
3
+ metadata.gz: 0ed8bce8c2576663b3d187efc7ae064c239c9ab8f3e6dacae592563ea4c484fb
4
+ data.tar.gz: 9e67c875fd8dcab13a8e0ed56b34f842519f1af4f0037f5c8955970cc82f2850
5
5
  SHA512:
6
- metadata.gz: fdbccf8e60640748b4eabc666355ac175455f0338a21a157d41eaee48f82361f45c4c921ec94ee2f3df5b9a274c72a1de868d4f7dfe5d3e2ff4480fbc08981ef
7
- data.tar.gz: d330ce04fee3e846d0591cd4f0c34599e3501715e291f7ad7956a226e7ca7d91638892a09e566f567e13daaf2287d7da95869e4c99e849043a459e7afcc599e0
6
+ metadata.gz: 0ea389afd2110fbaca8c2215507874e1fed2ad1e1f5dae167baaf532d56f91bcfa3f7458a88a71e6ce2de341160ba0fe3f3a25c786641204ebda1f3fe2db707c
7
+ data.tar.gz: 9ace14690c79ee0ca1e5c9a3841a9769d58b315685e811b253d393c2a5858294153cf1b0e88471b584112391b351173163cd4d6326920654e35d3aac83c6cf77
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0] - 2020-12-30
4
+ - Add matchers for less_than_or_equal_to, greater_than
5
+
3
6
  ## [1.0.1] - 2020-12-30
4
7
  - Pin all the dependencies to a proper working subset
5
8
  - Expand testing to many rails / ruby combinations
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
- expect {}.to execute.less_than(20).queries # alias for fewer_than
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.less_than(20).delete_queries
112
- expect {}.to execute.less_than(20).load_queries
113
- expect {}.to execute.less_than(20).schema_queries
114
- expect {}.to execute.less_than(20).exists_queries
115
- expect {}.to execute.less_than(20).queries
116
- expect {}.to execute.less_than(20).queries_of_type("Audited::Audit Load")
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
- at_least, more_than, at_most, less_than, lteq?
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 fewer_than(n)
29
+ def less_than(n)
30
30
  @comparison = n
31
- @match_method = method(:match_fewer_than)
31
+ @match_method = method(:compare_less_than)
32
32
  self
33
33
  end
34
- alias_method :less_than, :fewer_than
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 match_fewer_than
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rspec-activerecord-expectations"
3
- spec.version = '1.0.1'
3
+ spec.version = '1.1.0'
4
4
  spec.authors = ["Joseph Mastey"]
5
5
  spec.email = ["hello@joemastey.com"]
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-activerecord-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Mastey