rspec_power 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +7 -2
- data/lib/rspec_power/env.rb +5 -1
- data/lib/rspec_power/logging.rb +6 -4
- data/lib/rspec_power/performance.rb +2 -1
- data/lib/rspec_power/sql.rb +36 -28
- data/lib/rspec_power/time.rb +7 -3
- data/lib/rspec_power/version.rb +1 -1
- data/lib/rspec_power.rb +3 -1
- metadata +8 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a77f18032d0c06a36ad09d86f39dfcc0361009599b465ba6c53be1c9b4b2028f
|
|
4
|
+
data.tar.gz: e629475ed4f514239754b305a74e86ff36127de526b7e7d9fa6a6383bb645f93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac21e5391546fbf07d05d54a19dd1b01bb718a8318c78a62559aa1e47cf8f4ea2e3b4c937bca6a64da638d896de881350b863ea82400d879e7f476cdd205f385
|
|
7
|
+
data.tar.gz: 67fa15caba966ae8afa38ca9643a8c74af05f903ff1a9d17a324657e3a8733d85ed692b28f853f1fdf476f694729a9c582267172f33457b845c7891b453db5f6
|
data/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Add this line to your application's Gemfile:
|
|
|
28
28
|
|
|
29
29
|
```ruby
|
|
30
30
|
group :test do
|
|
31
|
-
gem "rspec_power"
|
|
31
|
+
gem "rspec_power"
|
|
32
32
|
end
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -38,6 +38,11 @@ And then execute:
|
|
|
38
38
|
bundle install
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
If you are using the "timecop" gem, you need to
|
|
42
|
+
|
|
43
|
+
- add to Gemfile as `gem "rspec_power", require: false`
|
|
44
|
+
- add `require "rspec_power"` before `require "timecop"` in `rails_helper.rb`.
|
|
45
|
+
|
|
41
46
|
## 🚀 Quick Start
|
|
42
47
|
|
|
43
48
|
The gem automatically configures itself when required. Just add it to your Gemfile.
|
|
@@ -46,7 +51,7 @@ The gem automatically configures itself when required. Just add it to your Gemfi
|
|
|
46
51
|
|
|
47
52
|
### 🔍 Enhanced Logging
|
|
48
53
|
|
|
49
|
-
Capture all Rails logs during specific tests:
|
|
54
|
+
Capture all Rails logs during specific tests, copied from [test-prof](https://github.com/test-prof/test-prof) gem with a small enhancement:
|
|
50
55
|
|
|
51
56
|
```ruby
|
|
52
57
|
RSpec.describe User, :with_log do
|
data/lib/rspec_power/env.rb
CHANGED
|
@@ -25,6 +25,10 @@ end
|
|
|
25
25
|
RSpec.shared_context "rspec_power::env:override" do
|
|
26
26
|
around(:each) do |example|
|
|
27
27
|
overrides = example.metadata[:with_env] || {}
|
|
28
|
-
|
|
28
|
+
if overrides.any?
|
|
29
|
+
with_test_env(overrides) { example.run }
|
|
30
|
+
else
|
|
31
|
+
example.run
|
|
32
|
+
end
|
|
29
33
|
end
|
|
30
34
|
end
|
data/lib/rspec_power/logging.rb
CHANGED
|
@@ -75,17 +75,19 @@ module RSpecPower
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def with_logging
|
|
78
|
-
|
|
78
|
+
targets = LoggingHelpers.all_loggables
|
|
79
|
+
old_loggers = LoggingHelpers.swap_logger(targets)
|
|
79
80
|
yield
|
|
80
81
|
ensure
|
|
81
|
-
LoggingHelpers.restore_logger(
|
|
82
|
+
LoggingHelpers.restore_logger(old_loggers, targets)
|
|
82
83
|
end
|
|
83
84
|
|
|
84
85
|
def with_ar_logging
|
|
85
|
-
|
|
86
|
+
targets = LoggingHelpers.ar_loggables
|
|
87
|
+
old_loggers = LoggingHelpers.swap_logger(targets)
|
|
86
88
|
yield
|
|
87
89
|
ensure
|
|
88
|
-
LoggingHelpers.restore_logger(
|
|
90
|
+
LoggingHelpers.restore_logger(old_loggers, targets)
|
|
89
91
|
end
|
|
90
92
|
end
|
|
91
93
|
end
|
|
@@ -10,7 +10,8 @@ module RSpecPower
|
|
|
10
10
|
yield
|
|
11
11
|
ensure
|
|
12
12
|
elapsed_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000.0
|
|
13
|
-
|
|
13
|
+
# Do not override an existing exception
|
|
14
|
+
if $!.nil? && elapsed_ms > max_ms
|
|
14
15
|
formatted_elapsed = format("%.3f", elapsed_ms)
|
|
15
16
|
formatted_limit = format("%.3f", max_ms)
|
|
16
17
|
raise RSpec::Expectations::ExpectationNotMetError,
|
data/lib/rspec_power/sql.rb
CHANGED
|
@@ -58,48 +58,56 @@ end
|
|
|
58
58
|
|
|
59
59
|
RSpec.shared_context "rspec_power::sql:none" do
|
|
60
60
|
around(:each) do |example|
|
|
61
|
-
|
|
61
|
+
if example.metadata[:with_no_sql_queries] || example.metadata[:with_no_sql]
|
|
62
|
+
executed_sql = []
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
callback = lambda do |_name, _started, _finished, _unique_id, payload|
|
|
65
|
+
event_name = payload[:name].to_s
|
|
66
|
+
cached = payload[:cached]
|
|
67
|
+
next if cached
|
|
68
|
+
next if event_name == "SCHEMA" || event_name == "TRANSACTION"
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
executed_sql << payload[:sql]
|
|
71
|
+
end
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
|
|
74
|
+
example.run
|
|
75
|
+
end
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if executed_sql.any?
|
|
78
|
+
message = "Expected no SQL to be executed, but #{executed_sql.length} statement(s) were run.\n" \
|
|
79
|
+
+ executed_sql.map { |sql| " - #{sql}" }.join("\n")
|
|
80
|
+
raise RSpec::Expectations::ExpectationNotMetError, message
|
|
81
|
+
end
|
|
82
|
+
else
|
|
83
|
+
example.run
|
|
80
84
|
end
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
|
|
84
88
|
RSpec.shared_context "rspec_power::sql:must" do
|
|
85
89
|
around(:each) do |example|
|
|
86
|
-
|
|
90
|
+
if example.metadata[:with_sql_queries] || example.metadata[:with_sql]
|
|
91
|
+
executed_sql = []
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
callback = lambda do |_name, _started, _finished, _unique_id, payload|
|
|
94
|
+
event_name = payload[:name].to_s
|
|
95
|
+
cached = payload[:cached]
|
|
96
|
+
next if cached
|
|
97
|
+
next if event_name == "SCHEMA" || event_name == "TRANSACTION"
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
executed_sql << payload[:sql]
|
|
100
|
+
end
|
|
96
101
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
|
|
103
|
+
example.run
|
|
104
|
+
end
|
|
100
105
|
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
if executed_sql.empty?
|
|
107
|
+
raise RSpec::Expectations::ExpectationNotMetError, "Expected some SQL to be executed, but none was run"
|
|
108
|
+
end
|
|
109
|
+
else
|
|
110
|
+
example.run
|
|
103
111
|
end
|
|
104
112
|
end
|
|
105
113
|
end
|
data/lib/rspec_power/time.rb
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
require "active_support/testing/time_helpers"
|
|
2
1
|
require "time"
|
|
3
2
|
|
|
4
3
|
module RSpecPower
|
|
5
4
|
module TimeHelpers
|
|
6
|
-
include ActiveSupport::Testing::TimeHelpers
|
|
7
|
-
|
|
8
5
|
def with_time_zone(zone)
|
|
9
6
|
if defined?(ActiveSupport::TimeZone)
|
|
10
7
|
::Time.use_zone(zone) { yield }
|
|
@@ -18,6 +15,13 @@ end
|
|
|
18
15
|
RSpec.shared_context "rspec_power::time:freeze" do
|
|
19
16
|
around(:each) do |example|
|
|
20
17
|
if ts = example.metadata[:with_time_freeze]
|
|
18
|
+
# include ActiveSupport::Testing::TimeHelpers if not already included
|
|
19
|
+
if !@_rspec_power_time_helpers_included && !respond_to?(:travel_to)
|
|
20
|
+
RSpec.configure do |config|
|
|
21
|
+
config.include ActiveSupport::Testing::TimeHelpers
|
|
22
|
+
end
|
|
23
|
+
@_rspec_power_time_helpers_included = true
|
|
24
|
+
end
|
|
21
25
|
ts = Time.parse(ts) if ts.is_a?(String)
|
|
22
26
|
travel_to(ts) { example.run }
|
|
23
27
|
else
|
data/lib/rspec_power/version.rb
CHANGED
data/lib/rspec_power.rb
CHANGED
|
@@ -11,7 +11,8 @@ require "rspec_power/sql"
|
|
|
11
11
|
require "rspec_power/performance"
|
|
12
12
|
require "rspec_power/benchmark"
|
|
13
13
|
|
|
14
|
-
RSpec
|
|
14
|
+
if defined?(RSpec)
|
|
15
|
+
RSpec.configure do |config|
|
|
15
16
|
# Logging
|
|
16
17
|
config.include RSpecPower::LoggingHelpers
|
|
17
18
|
config.include_context "rspec_power::logging:verbose", with_log: true
|
|
@@ -58,4 +59,5 @@ RSpec.configure do |config|
|
|
|
58
59
|
# Prefer :with_dump_db_on_fail; keep :dump_db_on_fail for backward compatibility
|
|
59
60
|
config.include_context "rspec_power::db_dump:on_fail", :with_dump_db_on_fail
|
|
60
61
|
config.include_context "rspec_power::db_dump:on_fail", :dump_db_on_fail
|
|
62
|
+
end
|
|
61
63
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec_power
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Igor Kasyanchuk
|
|
@@ -79,7 +79,9 @@ dependencies:
|
|
|
79
79
|
- - ">="
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: '0'
|
|
82
|
-
description:
|
|
82
|
+
description: 'A collection of helpers and contexts to enhance Rails specs: logging,
|
|
83
|
+
env/I18n/time helpers, SQL guards, request/DB dumps, benchmarking, CI guards, and
|
|
84
|
+
performance limits.'
|
|
83
85
|
email:
|
|
84
86
|
- igorkasyanchuk@gmail.com
|
|
85
87
|
executables: []
|
|
@@ -107,6 +109,9 @@ licenses:
|
|
|
107
109
|
- MIT
|
|
108
110
|
metadata:
|
|
109
111
|
homepage_uri: https://github.com/igorkasyanchuk/rspec_power
|
|
112
|
+
source_code_uri: https://github.com/igorkasyanchuk/rspec_power
|
|
113
|
+
bug_tracker_uri: https://github.com/igorkasyanchuk/rspec_power/issues
|
|
114
|
+
documentation_uri: https://github.com/igorkasyanchuk/rspec_power#readme
|
|
110
115
|
rdoc_options: []
|
|
111
116
|
require_paths:
|
|
112
117
|
- lib
|
|
@@ -123,5 +128,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
128
|
requirements: []
|
|
124
129
|
rubygems_version: 3.6.9
|
|
125
130
|
specification_version: 4
|
|
126
|
-
summary: RSpec
|
|
131
|
+
summary: Powerful RSpec helpers for Rails testing
|
|
127
132
|
test_files: []
|