bond-spy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bond_reconcile.py +224 -134
  3. data/bond.gemspec +2 -1
  4. data/lib/bond.rb +53 -35
  5. data/lib/bond/targetable.rb +9 -3
  6. data/lib/bond/version.rb +1 -1
  7. data/spec/bond_spec.rb +16 -0
  8. data/spec/bond_targetable_spec.rb +13 -0
  9. data/spec/test_observations/bond_spec/Bond_with_agents_should_call_doers_before_returning_result.json +4 -4
  10. data/spec/test_observations/bond_spec/Bond_with_agents_should_call_the_function_passed_as_result_if_it_is_callable.json +9 -9
  11. data/spec/test_observations/bond_spec/Bond_with_agents_should_correctly_call_a_single_doer_if_filter_criteria_are_met.json +4 -4
  12. data/spec/test_observations/bond_spec/Bond_with_agents_should_correctly_call_multiple_doers.json +5 -5
  13. data/spec/test_observations/bond_spec/Bond_with_agents_should_not_call_doers_of_overriden_agents.json +2 -2
  14. data/spec/test_observations/bond_spec/Bond_with_agents_should_skip_saving_observations_when_specified.json +18 -0
  15. data/spec/test_observations/bond_spec/Bond_with_agents_should_throw_an_exception_if_specified_by_agent.json +3 -3
  16. data/spec/test_observations/bond_spec/Bond_with_agents_should_throw_the_result_of_the_value_passed_to_exception_if_callable.json +4 -4
  17. data/spec/test_observations/bond_spec/Bond_with_agents_should_work_with_multiple_agents_for_different_spy_points.json +9 -9
  18. data/spec/test_observations/bond_spec/Bond_with_agents_with_filters_should_respect_combinations_of_filters.json +19 -19
  19. data/spec/test_observations/bond_spec/Bond_with_agents_with_filters_should_respect_function_filters.json +6 -6
  20. data/spec/test_observations/bond_spec/Bond_with_agents_with_filters_should_respect_single_key_value_filters_of_all_types.json +51 -51
  21. data/spec/test_observations/bond_spec/Bond_without_any_agents_should_correctly_log_nested_hashes_and_arrays_with_hash_sorting.json +22 -22
  22. data/spec/test_observations/bond_spec/Bond_without_any_agents_should_correctly_log_some_normal_arguments_with_a_spy_point_name.json +6 -6
  23. data/spec/test_observations/bond_spec/Bond_without_any_agents_should_correctly_log_some_normal_arguments_without_a_spy_point_name.json +4 -4
  24. data/spec/test_observations/bond_targetable_spec/BondTargetable_correctly_continues_to_the_method_when_agent_result_continue_is_returned.json +4 -4
  25. data/spec/test_observations/bond_targetable_spec/BondTargetable_correctly_continues_to_the_method_when_agent_result_none_is_returned.json +6 -6
  26. data/spec/test_observations/bond_targetable_spec/BondTargetable_correctly_spies_private_methods.json +2 -2
  27. data/spec/test_observations/bond_targetable_spec/BondTargetable_correctly_spies_protected_methods.json +2 -2
  28. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_argument_types_correctly_spies_on_a_class_method.json +3 -3
  29. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_argument_types_correctly_spies_on_a_normal_method.json +3 -3
  30. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_argument_types_correctly_spies_on_all_optional_keyword_arguments.json +4 -4
  31. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_argument_types_correctly_spies_on_variable_keyword_arguments.json +12 -12
  32. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_spy_point_parameters_correctly_ignores_excluded_keys.json +4 -4
  33. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_spy_point_parameters_correctly_mocks_when_one_is_specified.json +4 -4
  34. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_different_spy_point_parameters_correctly_respects_mock_only.json +17 -0
  35. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_modules_correctly_spies_on_included_module_methods.json +2 -2
  36. data/spec/test_observations/bond_targetable_spec/BondTargetable_with_modules_correctly_spies_on_module_methods.json +3 -3
  37. data/tutorials/binary_search_tree/bst_spec.rb +1 -5
  38. data/tutorials/binary_search_tree/run_tests.sh +1 -1
  39. data/tutorials/heat_watcher/heat_watcher.rb +2 -2
  40. data/tutorials/heat_watcher/heat_watcher_spec.rb +8 -13
  41. data/tutorials/heat_watcher/test_observations/heat_watcher_spec/HeatWatcher_should_properly_report_critical_errors.json +7 -49
  42. data/tutorials/heat_watcher/test_observations/heat_watcher_spec/HeatWatcher_should_properly_report_warnings_and_switch_back_to_OK_status.json +9 -63
  43. metadata +20 -2
@@ -1,7 +1,7 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "TestClass#annotated_standard_method",
4
- "arg1": 1,
5
- "arg2": 2
3
+ "__spy_point__": "TestClass#annotated_standard_method",
4
+ "arg1": 1,
5
+ "arg2": 2
6
6
  }
7
7
  ]
@@ -1,10 +1,10 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "TestClass#annotated_method_kw_params_optional"
3
+ "__spy_point__": "TestClass#annotated_method_kw_params_optional"
4
4
  },
5
5
  {
6
- "__spy_point__": "TestClass#annotated_method_kw_params_optional",
7
- "arg1": "value1",
8
- "arg2": "value2"
6
+ "__spy_point__": "TestClass#annotated_method_kw_params_optional",
7
+ "arg1": "value1",
8
+ "arg2": "value2"
9
9
  }
10
10
  ]
@@ -1,22 +1,22 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "TestClass#annotated_method_variable_kw_args",
4
- "arg1": "value1"
3
+ "__spy_point__": "TestClass#annotated_method_variable_kw_args",
4
+ "arg1": "value1"
5
5
  },
6
6
  {
7
- "__spy_point__": "TestClass#annotated_method_variable_kw_args",
8
- "arg1": "value1",
9
- "arg2": "value2"
7
+ "__spy_point__": "TestClass#annotated_method_variable_kw_args",
8
+ "arg1": "value1",
9
+ "arg2": "value2"
10
10
  },
11
11
  {
12
- "__spy_point__": "TestClass#annotated_method_variable_kw_args",
13
- "arg1": "value1",
14
- "arg3": "value3"
12
+ "__spy_point__": "TestClass#annotated_method_variable_kw_args",
13
+ "arg1": "value1",
14
+ "arg3": "value3"
15
15
  },
16
16
  {
17
- "__spy_point__": "TestClass#annotated_method_variable_kw_args",
18
- "arg1": "value1",
19
- "arg3": "value3",
20
- "arg4": "value4"
17
+ "__spy_point__": "TestClass#annotated_method_variable_kw_args",
18
+ "arg1": "value1",
19
+ "arg3": "value3",
20
+ "arg4": "value4"
21
21
  }
22
22
  ]
@@ -1,10 +1,10 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "TestClass#annotated_method_single_exclude",
4
- "arg2": "value2"
3
+ "__spy_point__": "TestClass#annotated_method_single_exclude",
4
+ "arg2": "value2"
5
5
  },
6
6
  {
7
- "__spy_point__": "TestClass#annotated_method_multiple_exclude",
8
- "arg2": "value2"
7
+ "__spy_point__": "TestClass#annotated_method_multiple_exclude",
8
+ "arg2": "value2"
9
9
  }
10
10
  ]
@@ -1,10 +1,10 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "mock_required",
4
- "arg1": 5
3
+ "__spy_point__": "mock_required",
4
+ "arg1": 5
5
5
  },
6
6
  {
7
- "__spy_point__": "return_value",
8
- "return": "new return"
7
+ "__spy_point__": "return_value",
8
+ "return": "new return"
9
9
  }
10
10
  ]
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "__spy_point__": "unmocked_return",
4
+ "val": "return"
5
+ },
6
+ {
7
+ "__spy_point__": "mocked_return",
8
+ "val": "mocked return"
9
+ },
10
+ {
11
+ "__spy_point__": "mock_only"
12
+ },
13
+ {
14
+ "__spy_point__": "mocked_return",
15
+ "val": "mocked return"
16
+ }
17
+ ]
@@ -1,6 +1,6 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "TestModule#annotated_standard_method",
4
- "arg1": "value"
3
+ "__spy_point__": "TestModule#annotated_standard_method",
4
+ "arg1": "value"
5
5
  }
6
6
  ]
@@ -1,7 +1,7 @@
1
1
  [
2
2
  {
3
- "__spy_point__": "TestModule.annotated_class_method",
4
- "arg1": "value1",
5
- "arg2": "value2"
3
+ "__spy_point__": "TestModule.annotated_class_method",
4
+ "arg1": "value1",
5
+ "arg2": "value2"
6
6
  }
7
7
  ]
@@ -28,11 +28,7 @@ describe Node do
28
28
  end
29
29
 
30
30
  it 'should correctly delete nodes from the BST' do
31
- tree = Node.new(8)
32
- tree.insert(12)
33
- tree.insert(3)
34
- tree.insert(4)
35
- tree.insert(6)
31
+ tree = create_tree_1
36
32
 
37
33
  tree.delete(4)
38
34
 
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env bash
2
2
  this_dir=`dirname $0`
3
3
  this_dir=`cd $this_dir && pwd`
4
- BOND_MERGE=console RUBYLIB="$this_dir/../../lib" rspec bst_spec.rb
4
+ BOND_RECONCILE=console RUBYLIB="$this_dir/../../lib" rspec bst_spec.rb
@@ -67,7 +67,7 @@ class HeatWatcher
67
67
  end
68
68
 
69
69
  # Spy this function, want to spy the result
70
- bond.spy_point(spy_result: true)
70
+ bond.spy_point(spy_result: true, mock_only: true)
71
71
  # Read the temperature from a sensor
72
72
  def get_temperature
73
73
  resp_code, temp_data =
@@ -78,7 +78,7 @@ class HeatWatcher
78
78
  match[1].to_f
79
79
  end
80
80
 
81
- bond.spy_point
81
+ bond.spy_point(mock_only: true)
82
82
  # Read the current time
83
83
  def get_current_time
84
84
  Time.now.to_i
@@ -89,28 +89,23 @@ class TemperatureMocker
89
89
  def initialize(time_mocker:, temp_start:, temp_rates: [])
90
90
  @time_mocker = time_mocker
91
91
  @start_time = time_mocker.time
92
- @last_temp = temp_start # last temp read
93
- @last_temp_time = @start_time # last temp read time
92
+ @temp_start = temp_start
94
93
  @temp_rates = temp_rates
95
94
  end
96
95
 
97
96
  def temperature
98
97
  now = @time_mocker.time
99
98
  time_since_start = now - @start_time
100
- # See if we need to advance to the next temperature rate
101
- if @temp_rates.length > 1 && time_since_start >= @temp_rates[1][0]
102
99
 
103
- old_rate = @temp_rates.shift[1]
100
+ temp = @temp_start
101
+ last_time, last_rate = @temp_rates[0]
104
102
 
105
- old_rate_time = @temp_rates[0][0]
106
- @last_temp += (old_rate_time + @start_time - @last_temp_time) / 60.0 * old_rate
107
- @last_temp_time = old_rate_time + @start_time
103
+ @temp_rates[1..-1].each do |r_time, r_rate|
104
+ break if time_since_start <= r_time
105
+ temp += (r_time - last_time) * last_rate / 60.0
106
+ last_time, last_rate = r_time, r_rate
108
107
  end
109
108
 
110
- # The first pair is the one we use to get the rate
111
- rate = @temp_rates.length > 0 ? @temp_rates[0][1] : 0
112
- @last_temp += (now - @last_temp_time) / 60.0 * rate
113
- @last_temp_time = now
114
- @last_temp
109
+ temp + (time_since_start - last_time) * last_rate / 60.0
115
110
  end
116
111
  end
@@ -1,53 +1,35 @@
1
1
  [
2
- {
3
- "__spy_point__": "HeatWatcher#get_temperature"
4
- },
5
2
  {
6
3
  "__spy_point__": "HeatWatcher#make_request",
7
4
  "url": "http://system.server.com/temperature"
8
5
  },
9
6
  {
10
7
  "__spy_point__": "HeatWatcher#get_temperature.result",
11
- "result": 70.0
12
- },
13
- {
14
- "__spy_point__": "HeatWatcher#get_current_time"
8
+ "result": 70
15
9
  },
16
10
  {
17
11
  "__spy_point__": "HeatWatcher#sleep",
18
12
  "seconds": 60
19
13
  },
20
- {
21
- "__spy_point__": "HeatWatcher#get_temperature"
22
- },
23
14
  {
24
15
  "__spy_point__": "HeatWatcher#make_request",
25
16
  "url": "http://system.server.com/temperature"
26
17
  },
27
18
  {
28
19
  "__spy_point__": "HeatWatcher#get_temperature.result",
29
- "result": 70.5
30
- },
31
- {
32
- "__spy_point__": "HeatWatcher#get_current_time"
20
+ "result": 70.5000
33
21
  },
34
22
  {
35
23
  "__spy_point__": "HeatWatcher#sleep",
36
24
  "seconds": 60
37
25
  },
38
- {
39
- "__spy_point__": "HeatWatcher#get_temperature"
40
- },
41
26
  {
42
27
  "__spy_point__": "HeatWatcher#make_request",
43
28
  "url": "http://system.server.com/temperature"
44
29
  },
45
30
  {
46
31
  "__spy_point__": "HeatWatcher#get_temperature.result",
47
- "result": 73.0
48
- },
49
- {
50
- "__spy_point__": "HeatWatcher#get_current_time"
32
+ "result": 73
51
33
  },
52
34
  {
53
35
  "__spy_point__": "HeatWatcher#send_alert",
@@ -62,55 +44,37 @@
62
44
  "__spy_point__": "HeatWatcher#sleep",
63
45
  "seconds": 10
64
46
  },
65
- {
66
- "__spy_point__": "HeatWatcher#get_temperature"
67
- },
68
47
  {
69
48
  "__spy_point__": "HeatWatcher#make_request",
70
49
  "url": "http://system.server.com/temperature"
71
50
  },
72
51
  {
73
52
  "__spy_point__": "HeatWatcher#get_temperature.result",
74
- "result": 73.5
75
- },
76
- {
77
- "__spy_point__": "HeatWatcher#get_current_time"
53
+ "result": 73.5000
78
54
  },
79
55
  {
80
56
  "__spy_point__": "HeatWatcher#sleep",
81
57
  "seconds": 10
82
58
  },
83
- {
84
- "__spy_point__": "HeatWatcher#get_temperature"
85
- },
86
59
  {
87
60
  "__spy_point__": "HeatWatcher#make_request",
88
61
  "url": "http://system.server.com/temperature"
89
62
  },
90
63
  {
91
64
  "__spy_point__": "HeatWatcher#get_temperature.result",
92
- "result": 74.0
93
- },
94
- {
95
- "__spy_point__": "HeatWatcher#get_current_time"
65
+ "result": 74
96
66
  },
97
67
  {
98
68
  "__spy_point__": "HeatWatcher#sleep",
99
69
  "seconds": 10
100
70
  },
101
- {
102
- "__spy_point__": "HeatWatcher#get_temperature"
103
- },
104
71
  {
105
72
  "__spy_point__": "HeatWatcher#make_request",
106
73
  "url": "http://system.server.com/temperature"
107
74
  },
108
75
  {
109
76
  "__spy_point__": "HeatWatcher#get_temperature.result",
110
- "result": 74.08333333333333
111
- },
112
- {
113
- "__spy_point__": "HeatWatcher#get_current_time"
77
+ "result": 74.0833
114
78
  },
115
79
  {
116
80
  "__spy_point__": "HeatWatcher#send_alert",
@@ -125,18 +89,12 @@
125
89
  "__spy_point__": "HeatWatcher#sleep",
126
90
  "seconds": 60
127
91
  },
128
- {
129
- "__spy_point__": "HeatWatcher#get_temperature"
130
- },
131
92
  {
132
93
  "__spy_point__": "HeatWatcher#make_request",
133
94
  "url": "http://system.server.com/temperature"
134
95
  },
135
96
  {
136
97
  "__spy_point__": "HeatWatcher#get_temperature.result",
137
- "result": 74.58333333333333
138
- },
139
- {
140
- "__spy_point__": "HeatWatcher#get_current_time"
98
+ "result": 74.5833
141
99
  }
142
100
  ]
@@ -1,41 +1,23 @@
1
1
  [
2
- {
3
- "__spy_point__": "HeatWatcher#get_temperature"
4
- },
5
2
  {
6
3
  "__spy_point__": "HeatWatcher#get_temperature.result",
7
- "result": 70.0
8
- },
9
- {
10
- "__spy_point__": "HeatWatcher#get_current_time"
4
+ "result": 70
11
5
  },
12
6
  {
13
7
  "__spy_point__": "HeatWatcher#sleep",
14
8
  "seconds": 60
15
9
  },
16
- {
17
- "__spy_point__": "HeatWatcher#get_temperature"
18
- },
19
10
  {
20
11
  "__spy_point__": "HeatWatcher#get_temperature.result",
21
- "result": 70.5
22
- },
23
- {
24
- "__spy_point__": "HeatWatcher#get_current_time"
12
+ "result": 70.5000
25
13
  },
26
14
  {
27
15
  "__spy_point__": "HeatWatcher#sleep",
28
16
  "seconds": 60
29
17
  },
30
- {
31
- "__spy_point__": "HeatWatcher#get_temperature"
32
- },
33
18
  {
34
19
  "__spy_point__": "HeatWatcher#get_temperature.result",
35
- "result": 71.6
36
- },
37
- {
38
- "__spy_point__": "HeatWatcher#get_current_time"
20
+ "result": 71.6000
39
21
  },
40
22
  {
41
23
  "__spy_point__": "HeatWatcher#send_alert",
@@ -45,15 +27,9 @@
45
27
  "__spy_point__": "HeatWatcher#sleep",
46
28
  "seconds": 10
47
29
  },
48
- {
49
- "__spy_point__": "HeatWatcher#get_temperature"
50
- },
51
30
  {
52
31
  "__spy_point__": "HeatWatcher#get_temperature.result",
53
- "result": 71.61666666666666
54
- },
55
- {
56
- "__spy_point__": "HeatWatcher#get_current_time"
32
+ "result": 71.6167
57
33
  },
58
34
  {
59
35
  "__spy_point__": "HeatWatcher#send_alert",
@@ -63,70 +39,40 @@
63
39
  "__spy_point__": "HeatWatcher#sleep",
64
40
  "seconds": 60
65
41
  },
66
- {
67
- "__spy_point__": "HeatWatcher#get_temperature"
68
- },
69
42
  {
70
43
  "__spy_point__": "HeatWatcher#get_temperature.result",
71
- "result": 71.71666666666665
72
- },
73
- {
74
- "__spy_point__": "HeatWatcher#get_current_time"
44
+ "result": 71.7167
75
45
  },
76
46
  {
77
47
  "__spy_point__": "HeatWatcher#sleep",
78
48
  "seconds": 60
79
49
  },
80
- {
81
- "__spy_point__": "HeatWatcher#get_temperature"
82
- },
83
50
  {
84
51
  "__spy_point__": "HeatWatcher#get_temperature.result",
85
- "result": 71.81666666666665
86
- },
87
- {
88
- "__spy_point__": "HeatWatcher#get_current_time"
52
+ "result": 71.8167
89
53
  },
90
54
  {
91
55
  "__spy_point__": "HeatWatcher#sleep",
92
56
  "seconds": 60
93
57
  },
94
- {
95
- "__spy_point__": "HeatWatcher#get_temperature"
96
- },
97
58
  {
98
59
  "__spy_point__": "HeatWatcher#get_temperature.result",
99
- "result": 71.91666666666664
100
- },
101
- {
102
- "__spy_point__": "HeatWatcher#get_current_time"
60
+ "result": 71.9167
103
61
  },
104
62
  {
105
63
  "__spy_point__": "HeatWatcher#sleep",
106
64
  "seconds": 60
107
65
  },
108
- {
109
- "__spy_point__": "HeatWatcher#get_temperature"
110
- },
111
66
  {
112
67
  "__spy_point__": "HeatWatcher#get_temperature.result",
113
- "result": 72.01666666666664
114
- },
115
- {
116
- "__spy_point__": "HeatWatcher#get_current_time"
68
+ "result": 72.0167
117
69
  },
118
70
  {
119
71
  "__spy_point__": "HeatWatcher#sleep",
120
72
  "seconds": 60
121
73
  },
122
- {
123
- "__spy_point__": "HeatWatcher#get_temperature"
124
- },
125
74
  {
126
75
  "__spy_point__": "HeatWatcher#get_temperature.result",
127
- "result": 72.11666666666663
128
- },
129
- {
130
- "__spy_point__": "HeatWatcher#get_current_time"
76
+ "result": 72.1167
131
77
  }
132
78
  ]