rspec_timer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/lib/rspec_timer/version.rb +1 -1
- data/lib/rspec_timer.rb +11 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 760b8f522ec25043cbe8085967e90db73cfba7b9
|
4
|
+
data.tar.gz: 3fe0f3b156634a4d84a1a0f697e6aeec0b963044
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc43db6bac66e229357e7dff9390cd84ced6589c2b7b8139879160e65a631807a88c3a27a9157db261c21c6ee860ad1d3799b3aad69890fabe0daa7c978cc5e4
|
7
|
+
data.tar.gz: 764ed9ac2aaf80c0c77bb7f650ece2f1664b2a2bbb13871f47e2020862334dcee92b862f2d2efe0cbc2eef39f5763fb814e8594cb1c4be1156122d847ffefe58
|
data/README.md
CHANGED
@@ -28,8 +28,11 @@ In your spec_helper.rb file, set up your "around" and "after" hooks like so:
|
|
28
28
|
RSpec.configure do |config|
|
29
29
|
|
30
30
|
config.before(:suite) do
|
31
|
+
# Set the log file's path (optional - if not set, defaults to a 'rspec-metrics.yml' file in your current folder)
|
32
|
+
RspecTimer.log_file_path = 'rspec_metrics.yml'
|
33
|
+
|
31
34
|
# Completely wipes any metrics from the log (optional)
|
32
|
-
RspecTimer.reset_metrics_log_file
|
35
|
+
RspecTimer.reset_metrics_log_file
|
33
36
|
end
|
34
37
|
|
35
38
|
config.around(:each) do |example|
|
@@ -40,7 +43,7 @@ RSpec.configure do |config|
|
|
40
43
|
# Stores any metrics from this test run into the YAML log file
|
41
44
|
# Adds/updates metrics according to unique signatures which are generated
|
42
45
|
# using each individual test's line number and source code.
|
43
|
-
RspecTimer.update_metrics_log_file
|
46
|
+
RspecTimer.update_metrics_log_file
|
44
47
|
end
|
45
48
|
|
46
49
|
end
|
data/lib/rspec_timer/version.rb
CHANGED
data/lib/rspec_timer.rb
CHANGED
@@ -7,11 +7,11 @@ class RspecTimer
|
|
7
7
|
include Singleton
|
8
8
|
extend SingleForwardable
|
9
9
|
|
10
|
-
def_delegators :instance, :reset_metrics, :
|
10
|
+
def_delegators :instance, :reset_metrics, :log_file_path, :start_measurement, :end_measurement, :metrics,
|
11
11
|
:run_and_measure, :reset_metrics_log_file, :update_metrics_log_file, :signature_for
|
12
12
|
|
13
13
|
attr_reader :metrics
|
14
|
-
|
14
|
+
attr_writer :log_file_path
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
reset_metrics
|
@@ -21,6 +21,10 @@ class RspecTimer
|
|
21
21
|
@metrics = {}
|
22
22
|
end
|
23
23
|
|
24
|
+
def log_file_path
|
25
|
+
@log_file_path ||= 'rspec_metrics.yml'
|
26
|
+
end
|
27
|
+
|
24
28
|
def start_measurement(example)
|
25
29
|
current_metrics = metrics_for(example)
|
26
30
|
current_metrics[:path] = example_path(example)
|
@@ -41,18 +45,18 @@ class RspecTimer
|
|
41
45
|
end_measurement(example)
|
42
46
|
end
|
43
47
|
|
44
|
-
def reset_metrics_log_file
|
45
|
-
File.write(
|
48
|
+
def reset_metrics_log_file
|
49
|
+
File.write(log_file_path, YAML.dump({}))
|
46
50
|
end
|
47
51
|
|
48
|
-
def update_metrics_log_file
|
52
|
+
def update_metrics_log_file
|
49
53
|
updated_metrics = {}
|
50
54
|
# Load any existing metrics
|
51
|
-
updated_metrics = YAML.load_file(
|
55
|
+
updated_metrics = YAML.load_file(log_file_path) if File.exists? (log_file_path)
|
52
56
|
# Merge in the new metrics, updating any existing ones
|
53
57
|
@metrics.keys.each { |key| updated_metrics[key] = @metrics[key] }
|
54
58
|
# Save metrics to the YAML log file
|
55
|
-
File.write(
|
59
|
+
File.write(log_file_path, YAML.dump(updated_metrics))
|
56
60
|
end
|
57
61
|
|
58
62
|
def signature_for(example)
|
@@ -61,10 +65,6 @@ class RspecTimer
|
|
61
65
|
|
62
66
|
private
|
63
67
|
|
64
|
-
def default_metrics_file_name
|
65
|
-
'rspec_metrics.yml'
|
66
|
-
end
|
67
|
-
|
68
68
|
def metrics_for(example)
|
69
69
|
@metrics[signature_for(example)] ||= {
|
70
70
|
path: nil,
|