marsh_grass 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 94c562ed414ec9c4d7f9d7801f3e783d3e7f1d08
4
- data.tar.gz: 954768dee75685d72489a712810651e9ae6a66f3
3
+ metadata.gz: 75c25a9fd71d7bc9e868b9d82a590e6c98ec1d3b
4
+ data.tar.gz: 73e7f8bac791254293a91121b7f63850f438e440
5
5
  SHA512:
6
- metadata.gz: 44aeb6bb84714c4adb13ab9c1611e0692e75994efb662e4a9c21f133de8554001c2fcb69b7256d755daa299545b48c05b89a8c3c99a67f081907830ef51d4d61
7
- data.tar.gz: d83206174d904b9af43b49c7584ed7f7093b3c2ef467f81390cf28bfcb29c757d5e43eb6432c8dd9cb261086016415f07dbd0fe317423cc555f130a92f855a0e
6
+ metadata.gz: 746ab6c822be5085e6bde4152d27974ba55b9981ec8aee2fd24feef188b8f9744efdd6e7d290f888506c80f86a6b397ad62df49916bf5fcde19c81469dd1455a
7
+ data.tar.gz: a6ee7aae1fef25f098f76319047185c8760403c159500ff1496e0834eae2a3d681eae4786e59e8bb0d95a4094ff365d6cbedee1187aafc1812ec12b32de47105
@@ -10,7 +10,21 @@ RSpec.configure do |config|
10
10
  example.metadata.delete(tag)
11
11
  end
12
12
 
13
+ def run_example_or_duplicate(original_example, test_description)
14
+ if !original_example.executed?
15
+ # Let the original example be the first repetition that is printed
16
+ original_example.metadata[:description] = test_description
17
+ original_example.run
18
+ else
19
+ repetition = original_example.duplicate_with
20
+ repetition.metadata[:description] = test_description
21
+ original_example.example_group.context.add_example(repetition)
22
+ end
23
+ end
24
+
13
25
  config.around(time_of_day: true) do |original_example|
26
+ shared_description = original_example.metadata[:description]
27
+
14
28
  now = Time.now
15
29
  time_of_day = untag_example(original_example, :time_of_day)
16
30
  test_segments = time_of_day.is_a?(Array) ? time_of_day : [time_of_day]
@@ -19,27 +33,15 @@ RSpec.configure do |config|
19
33
  minutes_to_run = test_segments.include?(:minutes) ? (0..59) : [now.min]
20
34
  seconds_to_run = test_segments.include?(:seconds) ? (0..59) : [now.sec]
21
35
 
22
- total = hours_to_run.size * minutes_to_run.size * seconds_to_run.size
23
-
24
- def describe_time_of_day(test, hour, minute, second)
25
- test.metadata[:description] = "Run Time #{hour}:#{minute}:#{second}: #{test.metadata[:description]}"
26
- end
27
-
28
- run_count = 0
29
36
  hours_to_run.each do |hour|
30
37
  minutes_to_run.each do |minute|
31
38
  seconds_to_run.each do |second|
32
- run_count += 1
33
39
  # Freeze time at the specified hour, minute, and/or second.
34
40
  # We need to run the test within the Timecop.freeze block,
35
41
  # in order to actually be affected by Timecop.
36
42
  Timecop.freeze(now.year, now.month, now.day, hour, minute, second) do
37
- # Let the original example be the final repetition
38
- last_run = run_count == total
39
- example = last_run ? original_example : original_example.duplicate_with
40
- # Run example with a helpful description
41
- describe_time_of_day(example, hour, minute, second)
42
- example.run(original_example.example_group_instance, original_example.reporter)
43
+ test_description = "Run Time #{hour}:#{minute}:#{second}: #{shared_description}"
44
+ run_example_or_duplicate(original_example, test_description)
43
45
  end
44
46
  end
45
47
  end
@@ -47,6 +49,8 @@ RSpec.configure do |config|
47
49
  end
48
50
 
49
51
  config.around(surrounding_time: true) do |original_example|
52
+ shared_description = original_example.metadata[:description]
53
+
50
54
  now = Time.now
51
55
  surrounding_time = untag_example(original_example, :surrounding_time)
52
56
  hour = surrounding_time.fetch(:hour, now.hour)
@@ -55,10 +59,6 @@ RSpec.configure do |config|
55
59
  # 1000 milliseconds before & after the surrounding time
56
60
  test_time_float = Time.local(now.year, now.month, now.day, hour, minute, second).to_f
57
61
 
58
- def describe_exact_time(test, time)
59
- test.metadata[:description] = "Run Time #{time.strftime('%H:%M:%S:%L')}: #{test.metadata[:description]}"
60
- end
61
-
62
62
  (-1000..1000).each do |millisecond|
63
63
  # Travel to the specified hour, minute, second, and millisecond, allowing
64
64
  # for time to elapse.
@@ -66,84 +66,60 @@ RSpec.configure do |config|
66
66
  # in order to actually be affected by Timecop.
67
67
  test_time = Time.at(test_time_float + millisecond.to_f / 1000)
68
68
  Timecop.travel(test_time) do
69
- # Let the original example be the final repetition
70
- last_run = millisecond == 1000
71
- example = last_run ? original_example : original_example.duplicate_with
72
- # Run example with a helpful description
73
- describe_exact_time(example, test_time)
74
- example.run(original_example.example_group_instance, original_example.reporter)
69
+ test_description = "Run Time #{test_time.strftime('%H:%M:%S:%L')}: #{shared_description}"
70
+ run_example_or_duplicate(original_example, test_description)
75
71
  end
76
72
  end
77
73
  end
78
74
 
79
75
  config.around(elapsed_time: true) do |original_example|
80
- def describe_time_elapsed(test, scale)
81
- test.metadata[:description] = "Run Speed #{scale}x Slower: #{test.metadata[:description]}"
82
- end
76
+ shared_description = original_example.metadata[:description]
83
77
 
84
78
  # Freeze time at the specified hour, minute, and/or second.
85
79
  # We need to run the test within the Timecop.freeze block,
86
80
  # in order to actually be affected by Timecop.
87
81
  time_multipliers = untag_example(original_example, :elapsed_time)
88
82
  time_multipliers = (1..10) unless time_multipliers.respond_to?(:each)
83
+
89
84
  time_multipliers.each do |seconds_multiplier|
90
85
  Timecop.scale(seconds_multiplier) do
91
- # Let the original example be the final repetition
92
- last_run = seconds_multiplier == time_multipliers.last
93
- example = last_run ? original_example : original_example.duplicate_with
94
- # Run example with a helpful description
95
- describe_time_elapsed(example, seconds_multiplier)
96
- example.run(original_example.example_group_instance, original_example.reporter)
86
+ test_description = "Run Speed #{seconds_multiplier}x Slower: #{shared_description}"
87
+ run_example_or_duplicate(original_example, test_description)
97
88
  end
98
89
  end
99
90
  end
100
91
 
101
92
  config.around(time_zones: true) do |original_example|
93
+ shared_description = original_example.metadata[:description]
102
94
  untag_example(original_example, :time_zones)
103
95
 
104
96
  utc = Time.now.utc
105
97
  time_zone_hours = %w[-12 -11 -10 -09 -08 -07 -06 -05 -04 -03 -02 -01 +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +10 +11 +12 +13 +14]
106
98
  time_zone_minutes = %w[00 30]
107
99
 
108
- def describe_time_zone(test, time_zone_hour, time_zone_minute)
109
- test.metadata[:description] = "Time Zone Offset #{time_zone_hour}:#{time_zone_minute}: #{test.metadata[:description]}"
110
- end
111
-
112
- total = time_zone_hours.size * time_zone_minutes.size
113
-
114
- time_zone_hours.each.with_index do |time_zone_hour, hour_index|
115
- time_zone_minutes.each.with_index(1) do |time_zone_minute, minute_index|
116
- adjustment = "#{time_zone_hour}:#{time_zone_minute}"
117
- adjusted_time = Time.new(utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec, adjustment)
100
+ time_zone_hours.each do |time_zone_hour|
101
+ time_zone_minutes.each do |time_zone_minute|
118
102
  # We need to run the test within the Timecop.freeze block,
119
103
  # in order to actually be affected by Timecop.
104
+ adjustment = "#{time_zone_hour}:#{time_zone_minute}"
105
+ adjusted_time = Time.new(utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec, adjustment)
120
106
  Timecop.travel(adjusted_time) do
121
- # Let the original example be the final repetition
122
- last_run = (hour_index * 2) + minute_index == total
123
- example = last_run ? original_example : original_example.duplicate_with
124
- # Run example with a helpful description
125
- describe_time_zone(example, time_zone_hour, time_zone_minute)
126
- example.run(original_example.example_group_instance, original_example.reporter)
107
+ test_description = "Time Zone Offset #{time_zone_hour}:#{time_zone_minute}: #{shared_description}"
108
+ run_example_or_duplicate(original_example, test_description)
127
109
  end
128
110
  end
129
111
  end
130
112
  end
131
113
 
132
114
  config.around(repetitions: true) do |original_example|
115
+ shared_description = original_example.metadata[:description]
116
+
133
117
  repetitions = untag_example(original_example, :repetitions)
134
118
  total = repetitions.is_a?(Integer) ? repetitions : 1000
135
119
 
136
- def describe_repetition_count(test, count, total)
137
- test.metadata[:description] = "Repetition #{count} of #{total}: #{test.metadata[:description]}"
138
- end
139
-
140
120
  (1..total).each do |count|
141
- # Let the original example be the final repetition
142
- last_run = count == total
143
- example = last_run ? original_example : original_example.duplicate_with
144
- # Run example with a helpful description
145
- describe_repetition_count(example, count, total)
146
- example.run(original_example.example_group_instance, original_example.reporter)
121
+ test_description = "Repetition #{count} of #{total}: #{shared_description}"
122
+ run_example_or_duplicate(original_example, test_description)
147
123
  end
148
124
  end
149
125
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MarshGrass
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marsh_grass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wes Rich