MonkeyEngine 2.0.0 → 2.0.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/.rubocop.yml +192 -0
- data/CHANGELOG.md +9 -4
- data/Gemfile.lock +14 -15
- data/lib/Action/action.rb +0 -2
- data/lib/Monkey/monkey.rb +1 -2
- data/lib/MonkeyAction/monkey_action.rb +0 -2
- data/lib/MonkeyAction/monkey_action_dead.rb +1 -3
- data/lib/MonkeyAction/monkey_action_eat.rb +1 -3
- data/lib/MonkeyAction/monkey_action_pause.rb +1 -3
- data/lib/MonkeyAction/monkey_action_sleep.rb +1 -3
- data/lib/MonkeyAction/monkey_action_type.rb +5 -7
- data/lib/MonkeyAction/monkey_action_wake.rb +1 -3
- data/lib/MonkeyAction/monkey_timed_action.rb +2 -4
- data/lib/MonkeyEngine/action_rules.rb +1 -1
- data/lib/MonkeyEngine/monkey_engine.rb +2 -8
- data/lib/MonkeyEngine/version.rb +1 -1
- data/lib/MonkeyKeyboard/keyboard_char.rb +0 -1
- data/lib/MonkeyKeyboard/keyboard_key.rb +9 -9
- data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +1 -1
- data/lib/MonkeyKeyboard/monkey_keyboard_en_us.rb +2 -2
- data/lib/MonkeyManager/monkey_manager.rb +5 -5
- data/lib/tasks/engine.rb +11 -7
- data/monkeyengine.gemspec +5 -1
- data/spec/action_rules_spec.rb +8 -14
- data/spec/engine_spec.rb +10 -10
- data/spec/keyboard_char_spec.rb +1 -1
- data/spec/keyboard_key_spec.rb +5 -5
- data/spec/monkey_action_eat_spec.rb +8 -8
- data/spec/monkey_action_pause_spec.rb +9 -9
- data/spec/monkey_action_sleep_spec.rb +9 -9
- data/spec/monkey_action_type_spec.rb +7 -7
- data/spec/monkey_action_wake_spec.rb +5 -5
- data/spec/monkey_factory_spec.rb +3 -11
- data/spec/monkey_keyboard_en_us_spec.rb +4 -7
- data/spec/monkey_manager_spec.rb +1 -1
- data/spec/monkey_service_spec.rb +11 -11
- data/spec/monkey_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples.rb +9 -9
- metadata +6 -5
data/monkeyengine.gemspec
CHANGED
@@ -11,10 +11,14 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.version = MonkeyEngine::VERSION
|
12
12
|
spec.authors = ['Gene M. Angelo, Jr.']
|
13
13
|
spec.email = ['public.gma@gmail.com']
|
14
|
-
spec.description = "Have some fun! MonkeyEngine is a gem that allows virtual monkeys
|
14
|
+
spec.description = "Have some fun! MonkeyEngine is a gem that allows virtual monkeys " \
|
15
|
+
"to tap away on a virtual keyboard! Can any of them complete a sentence? " \
|
16
|
+
"write a book? The sky is the limit! Add your own AI! Publish the results! " \
|
17
|
+
"Go...BANANAS!"
|
15
18
|
spec.summary = 'The engine that drives my monkeys!'
|
16
19
|
spec.homepage = 'https://github.com/gangelo/monkeyengine'
|
17
20
|
spec.license = 'MIT'
|
21
|
+
spec.required_ruby_version = '>= 3.0.1'
|
18
22
|
|
19
23
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
20
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/spec/action_rules_spec.rb
CHANGED
@@ -8,14 +8,8 @@ require 'MonkeyActions'
|
|
8
8
|
require_relative '../lib/MonkeyKeyboard/keyboard_input'
|
9
9
|
|
10
10
|
describe 'ActionRules' do
|
11
|
-
before(:each) do
|
12
|
-
end
|
13
|
-
|
14
|
-
after(:all) do
|
15
|
-
end
|
16
|
-
|
17
11
|
context 'get_next_action' do
|
18
|
-
it '
|
12
|
+
it 'throws an exception if the action is not completed' do
|
19
13
|
monkey = MonkeyFactory.create :groucho
|
20
14
|
|
21
15
|
monkey.extend(SpecHelpers::SetMonkeyAction)
|
@@ -26,24 +20,24 @@ describe 'ActionRules' do
|
|
26
20
|
action = MonkeyActionType.new(monkey, keyboard_input)
|
27
21
|
action.action_completed = false
|
28
22
|
|
29
|
-
monkey.
|
23
|
+
monkey.force_action(action)
|
30
24
|
|
31
25
|
lambda {
|
32
26
|
ActionRules.instance.get_next_action monkey
|
33
27
|
}.should raise_error MonkeyEngine::Exceptions::InvalidOperationException
|
34
28
|
end
|
35
29
|
|
36
|
-
it '
|
30
|
+
it 'gets correct action if current action is nil?' do
|
37
31
|
monkey = MonkeyFactory.create :groucho
|
38
32
|
|
39
33
|
monkey.extend(SpecHelpers::SetMonkeyAction)
|
40
34
|
|
41
|
-
monkey.
|
35
|
+
monkey.force_action(nil)
|
42
36
|
|
43
|
-
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should
|
37
|
+
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should be true
|
44
38
|
end
|
45
39
|
|
46
|
-
it '
|
40
|
+
it 'gets correct action if current action is MonkeyActionSleep' do
|
47
41
|
monkey = MonkeyFactory.create :groucho
|
48
42
|
|
49
43
|
monkey.extend(SpecHelpers::SetMonkeyAction)
|
@@ -51,9 +45,9 @@ describe 'ActionRules' do
|
|
51
45
|
action = MonkeyActionSleep.new(monkey, 6 * 60)
|
52
46
|
action.action_completed = true
|
53
47
|
|
54
|
-
monkey.
|
48
|
+
monkey.force_action(action)
|
55
49
|
|
56
|
-
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should
|
50
|
+
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should be true
|
57
51
|
end
|
58
52
|
end
|
59
53
|
end
|
data/spec/engine_spec.rb
CHANGED
@@ -5,46 +5,46 @@ require 'MonkeyActions'
|
|
5
5
|
require 'MonkeyFactory'
|
6
6
|
|
7
7
|
describe 'Engine' do
|
8
|
-
before
|
8
|
+
before do
|
9
9
|
@engine = MonkeyEngine::Engine.instance
|
10
10
|
@monkey = MonkeyFactory.create :groucho
|
11
11
|
@monkey.extend(SpecHelpers::SetMonkeyAction)
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'action_eval!' do
|
15
|
-
it '
|
15
|
+
it 'returns action completed if the action is completed' do
|
16
16
|
action = MonkeyActionPause.new(@monkey, 10)
|
17
17
|
action.action_completed = false
|
18
18
|
action.action_time_of_completion = action.action_time
|
19
19
|
|
20
|
-
@monkey.
|
20
|
+
@monkey.force_action(action)
|
21
21
|
|
22
|
-
@engine.action_eval!(action).should
|
22
|
+
@engine.action_eval!(action).should be true
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
25
|
+
it 'returns action not completed if the action is not completed' do
|
26
26
|
action = MonkeyActionPause.new(@monkey, 60)
|
27
27
|
action.action_completed = false
|
28
28
|
|
29
|
-
@monkey.
|
29
|
+
@monkey.force_action(action)
|
30
30
|
|
31
|
-
@engine.action_eval!(action).should
|
31
|
+
@engine.action_eval!(action).should be false
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'action_new' do
|
36
|
-
it '
|
36
|
+
it 'returns a new action if a the current action is completed' do
|
37
37
|
action = MonkeyActionSleep.new(@monkey, 60 * 8)
|
38
38
|
action.action_completed = true
|
39
39
|
|
40
|
-
@monkey.
|
40
|
+
@monkey.force_action(action)
|
41
41
|
|
42
42
|
@engine.new_action(@monkey).is_a?(MonkeyActionSleep).should_not == true
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'do_action' do
|
47
|
-
it '
|
47
|
+
it 'does something' do
|
48
48
|
skip 'todo'
|
49
49
|
end
|
50
50
|
end
|
data/spec/keyboard_char_spec.rb
CHANGED
data/spec/keyboard_key_spec.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
require 'MonkeyKeyboardEnUs'
|
4
4
|
|
5
5
|
describe 'KeyboardKey' do
|
6
|
-
it '
|
6
|
+
it 'shoulds return correct properties' do
|
7
7
|
keyboard_key = KeyboardKey.new 'a', 'A', :left, 1
|
8
8
|
|
9
|
-
keyboard_key.keyboard_char.should
|
10
|
-
keyboard_key.keyboard_shift_char.should
|
11
|
-
keyboard_key.keyboard_key_section.should
|
12
|
-
keyboard_key.keyboard_key_weight.should
|
9
|
+
keyboard_key.keyboard_char.should eq 'a'
|
10
|
+
keyboard_key.keyboard_shift_char.should eq 'A'
|
11
|
+
keyboard_key.keyboard_key_section.should eq :left
|
12
|
+
keyboard_key.keyboard_key_weight.should eq 1
|
13
13
|
end
|
14
14
|
end
|
@@ -23,10 +23,10 @@ describe 'MonkeyActionEat' do
|
|
23
23
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it_behaves_like 'MonkeyAction'
|
27
27
|
|
28
28
|
it '@it should be the correct type' do
|
29
|
-
@it.is_a?(MonkeyActionEat).should
|
29
|
+
@it.is_a?(MonkeyActionEat).should be true
|
30
30
|
end
|
31
31
|
|
32
32
|
# Monkey
|
@@ -40,7 +40,7 @@ describe 'MonkeyActionEat' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it '@value should be is_a? Integer' do
|
43
|
-
@it.value.is_a?(Integer).should
|
43
|
+
@it.value.is_a?(Integer).should be true
|
44
44
|
end
|
45
45
|
|
46
46
|
# Weight
|
@@ -49,34 +49,34 @@ describe 'MonkeyActionEat' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# validate
|
52
|
-
it '
|
52
|
+
it 'does not raise an error if value is within acceptable range' do
|
53
53
|
monkey = MonkeyFactory.create(:eating_monkey2)
|
54
54
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
55
55
|
-> { MonkeyActionEat.new(monkey, 40) }.should_not raise_error
|
56
56
|
end
|
57
57
|
|
58
|
-
it '
|
58
|
+
it 'raises an error if value is the wrong type' do
|
59
59
|
monkey = MonkeyFactory.create(:eating_monkey3)
|
60
60
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
61
61
|
-> { MonkeyActionEat.new(monkey, :wrong_type) }.should \
|
62
62
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
63
63
|
end
|
64
64
|
|
65
|
-
it '
|
65
|
+
it 'raises an error if value is less than min acceptable range' do
|
66
66
|
monkey = MonkeyFactory.create(:eating_monkey4)
|
67
67
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
68
68
|
-> { MonkeyActionEat.new(monkey, 29) }.should \
|
69
69
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
70
70
|
end
|
71
71
|
|
72
|
-
it '
|
72
|
+
it 'raises an error if value is greater than max acceptable range' do
|
73
73
|
monkey = MonkeyFactory.create(:eating_monkey5)
|
74
74
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
75
75
|
-> { MonkeyActionEat.new(monkey, 61) }.should \
|
76
76
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
77
77
|
end
|
78
78
|
|
79
|
-
it '
|
79
|
+
it 'raises an error if value is nil' do
|
80
80
|
monkey = MonkeyFactory.create(:eating_monkey6)
|
81
81
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
82
82
|
-> { MonkeyActionEat.new(monkey, nil) }.should \
|
@@ -24,10 +24,10 @@ describe 'MonkeyActionPause' do
|
|
24
24
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
it_behaves_like 'MonkeyAction'
|
28
28
|
|
29
29
|
it '@it should be the correct type' do
|
30
|
-
@it.is_a?(MonkeyActionPause).should
|
30
|
+
@it.is_a?(MonkeyActionPause).should be true
|
31
31
|
end
|
32
32
|
|
33
33
|
# Monkey
|
@@ -41,11 +41,11 @@ describe 'MonkeyActionPause' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it '@value should be is_a? Integer' do
|
44
|
-
@it.value.is_a?(Integer).should
|
44
|
+
@it.value.is_a?(Integer).should be true
|
45
45
|
end
|
46
46
|
|
47
47
|
it '@value should >= 1' do
|
48
|
-
(@it.value >= 1).should
|
48
|
+
(@it.value >= 1).should be true
|
49
49
|
end
|
50
50
|
|
51
51
|
# Weight
|
@@ -54,34 +54,34 @@ describe 'MonkeyActionPause' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# validate
|
57
|
-
it '
|
57
|
+
it 'does not raise an error if value is within acceptable range' do
|
58
58
|
monkey = MonkeyFactory.create(:pausing_monkey2)
|
59
59
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
60
60
|
-> { MonkeyActionPause.new(monkey, 5) }.should_not raise_error
|
61
61
|
end
|
62
62
|
|
63
|
-
it '
|
63
|
+
it 'raises an error if value is the wrong type' do
|
64
64
|
monkey = MonkeyFactory.create(:pausing_monkey3)
|
65
65
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
66
66
|
-> { MonkeyActionPause.new(monkey, :wrong_type) }.should \
|
67
67
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
68
68
|
end
|
69
69
|
|
70
|
-
it '
|
70
|
+
it 'raises an error if value is less than min acceptable range' do
|
71
71
|
monkey = MonkeyFactory.create(:pausing_monkey4)
|
72
72
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
73
73
|
-> { MonkeyActionPause.new(monkey, -1) }.should \
|
74
74
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
75
75
|
end
|
76
76
|
|
77
|
-
it '
|
77
|
+
it 'raises an error if value is greater than max acceptable range' do
|
78
78
|
monkey = MonkeyFactory.create(:pausing_monkey5)
|
79
79
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
80
80
|
-> { MonkeyActionPause.new(monkey, 61) }.should \
|
81
81
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
82
82
|
end
|
83
83
|
|
84
|
-
it '
|
84
|
+
it 'raises an error if value is nil' do
|
85
85
|
monkey = MonkeyFactory.create(:pausing_monkey6)
|
86
86
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
87
87
|
-> { MonkeyActionPause.new(monkey, nil) }.should \
|
@@ -23,10 +23,10 @@ describe 'MonkeyActionSleep' do
|
|
23
23
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it_behaves_like 'MonkeyAction'
|
27
27
|
|
28
28
|
it '@it should be the correct type' do
|
29
|
-
@it.is_a?(MonkeyActionSleep).should
|
29
|
+
@it.is_a?(MonkeyActionSleep).should be true
|
30
30
|
end
|
31
31
|
|
32
32
|
# Monkey
|
@@ -40,11 +40,11 @@ describe 'MonkeyActionSleep' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it '@value should be is_a? Integer' do
|
43
|
-
@it.value.is_a?(Integer).should
|
43
|
+
@it.value.is_a?(Integer).should be true
|
44
44
|
end
|
45
45
|
|
46
46
|
it '@value should equal 60 * 8' do
|
47
|
-
(@it.value == 60 * 8).should
|
47
|
+
(@it.value == 60 * 8).should be true
|
48
48
|
end
|
49
49
|
|
50
50
|
# Weight
|
@@ -53,34 +53,34 @@ describe 'MonkeyActionSleep' do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# validate
|
56
|
-
it '
|
56
|
+
it 'does not raise an error if value is within acceptable range' do
|
57
57
|
monkey = MonkeyFactory.create(:sleeping_monkey2)
|
58
58
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
59
59
|
-> { MonkeyActionSleep.new(monkey, 60 * 8) }.should_not raise_error
|
60
60
|
end
|
61
61
|
|
62
|
-
it '
|
62
|
+
it 'raises an error if value is the wrong type' do
|
63
63
|
monkey = MonkeyFactory.create(:sleeping_monkey3)
|
64
64
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
65
65
|
-> { MonkeyActionSleep.new(monkey, :wrong_type) }.should \
|
66
66
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
67
67
|
end
|
68
68
|
|
69
|
-
it '
|
69
|
+
it 'raises an error if value is less than min acceptable range' do
|
70
70
|
monkey = MonkeyFactory.create(:sleeping_monkey4)
|
71
71
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
72
72
|
-> { MonkeyActionSleep.new(monkey, 60 * 5) }.should \
|
73
73
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
74
74
|
end
|
75
75
|
|
76
|
-
it '
|
76
|
+
it 'raises an error if value is greater than max acceptable range' do
|
77
77
|
monkey = MonkeyFactory.create(:sleeping_monkey5)
|
78
78
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
79
79
|
-> { MonkeyActionSleep.new(monkey, 60 * 9) }.should \
|
80
80
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
81
81
|
end
|
82
82
|
|
83
|
-
it '
|
83
|
+
it 'raises an error if value is nil' do
|
84
84
|
monkey = MonkeyFactory.create(:sleeping_monkey6)
|
85
85
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
86
86
|
-> { MonkeyActionSleep.new(monkey, nil) }.should \
|
@@ -28,10 +28,10 @@ describe 'MonkeyActionType' do
|
|
28
28
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
it_behaves_like 'MonkeyAction'
|
32
32
|
|
33
33
|
it '@it should be the correct type' do
|
34
|
-
@it.is_a?(MonkeyActionType).should
|
34
|
+
@it.is_a?(MonkeyActionType).should be true
|
35
35
|
end
|
36
36
|
|
37
37
|
# Monkey
|
@@ -45,7 +45,7 @@ describe 'MonkeyActionType' do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it '@value should be is_a? Array' do
|
48
|
-
@it.value.is_a?(Array).should
|
48
|
+
@it.value.is_a?(Array).should be true
|
49
49
|
end
|
50
50
|
|
51
51
|
it '@value should not be nil?' do
|
@@ -58,7 +58,7 @@ describe 'MonkeyActionType' do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
# validate
|
61
|
-
it '
|
61
|
+
it 'does not raise an error if value is valid' do
|
62
62
|
monkey = MonkeyFactory.create(:typing_monkey2)
|
63
63
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
64
64
|
|
@@ -68,14 +68,14 @@ describe 'MonkeyActionType' do
|
|
68
68
|
-> { MonkeyActionType.new(monkey, keyboard_input) }.should_not raise_error
|
69
69
|
end
|
70
70
|
|
71
|
-
it '
|
71
|
+
it 'raises an error if value is the wrong type' do
|
72
72
|
monkey = MonkeyFactory.create(:typing_monkey3)
|
73
73
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
74
74
|
-> { MonkeyActionType.new(monkey, :wrong_type) }.should \
|
75
75
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
76
76
|
end
|
77
77
|
|
78
|
-
it '
|
78
|
+
it 'raises an error if value is empty?' do
|
79
79
|
monkey = MonkeyFactory.create(:typing_monkey4)
|
80
80
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
81
81
|
|
@@ -86,7 +86,7 @@ describe 'MonkeyActionType' do
|
|
86
86
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
87
87
|
end
|
88
88
|
|
89
|
-
it '
|
89
|
+
it 'raises an error if value is nil' do
|
90
90
|
monkey = MonkeyFactory.create(:typing_monkey5)
|
91
91
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
92
92
|
-> { MonkeyActionType.new(monkey, nil) }.should \
|
@@ -23,10 +23,10 @@ describe 'MonkeyActionWake' do
|
|
23
23
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it_behaves_like 'MonkeyAction'
|
27
27
|
|
28
28
|
it '@it should be the correct type' do
|
29
|
-
@it.is_a?(MonkeyActionWake).should
|
29
|
+
@it.is_a?(MonkeyActionWake).should be true
|
30
30
|
end
|
31
31
|
|
32
32
|
# Monkey
|
@@ -36,11 +36,11 @@ describe 'MonkeyActionWake' do
|
|
36
36
|
|
37
37
|
# Value
|
38
38
|
it '@value should return the right value' do
|
39
|
-
@it.value.should
|
39
|
+
@it.value.should be true
|
40
40
|
end
|
41
41
|
|
42
42
|
it '@value should be is_a? TrueClass' do
|
43
|
-
@it.value.is_a?(TrueClass).should
|
43
|
+
@it.value.is_a?(TrueClass).should be true
|
44
44
|
end
|
45
45
|
|
46
46
|
# Weight
|
@@ -49,7 +49,7 @@ describe 'MonkeyActionWake' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# validate
|
52
|
-
it '
|
52
|
+
it 'does not raise an error if value is within acceptable range' do
|
53
53
|
monkey = MonkeyFactory.create(:waking_monkey2)
|
54
54
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
55
55
|
-> { MonkeyActionWake.new(monkey) }.should_not raise_error
|
data/spec/monkey_factory_spec.rb
CHANGED
@@ -3,20 +3,12 @@
|
|
3
3
|
require 'MonkeyFactory'
|
4
4
|
|
5
5
|
describe 'MonkeyFactory' do
|
6
|
-
before(:all) do
|
7
|
-
end
|
8
|
-
|
9
|
-
after(:all) do
|
10
|
-
end
|
11
|
-
|
12
6
|
context 'create' do
|
13
|
-
it '
|
14
|
-
|
15
|
-
monkey.nil?.should == false
|
16
|
-
monkey.is_a?(Monkey).should == true
|
7
|
+
it 'instantiates an object from the factory' do
|
8
|
+
MonkeyFactory.create(:harpo).is_a?(Monkey).should be true
|
17
9
|
end
|
18
10
|
|
19
|
-
it '
|
11
|
+
it 'does not instantiate an object without using the factory' do
|
20
12
|
-> { Monkey.new :groucho }.should raise_error NoMethodError
|
21
13
|
end
|
22
14
|
end
|
@@ -7,14 +7,11 @@ describe 'MonkeyKeyboardEnUs' do
|
|
7
7
|
@it = MonkeyEngine::MonkeyKeyboardEnUs.instance
|
8
8
|
end
|
9
9
|
|
10
|
-
context 'keys' do
|
11
|
-
end
|
12
|
-
|
13
10
|
context 'left_keys' do
|
14
|
-
it '
|
11
|
+
it 'has the correct amount of keyboard entries on the left side of the keyboard' do
|
15
12
|
key_count = 0
|
16
13
|
|
17
|
-
@it.keys.each do |key|
|
14
|
+
@it.keys.each do |key| # rubocop:disable Style/HashEachMethods
|
18
15
|
key_count += key.keyboard_key_weight if key.keyboard_key_section == :left
|
19
16
|
end
|
20
17
|
|
@@ -23,10 +20,10 @@ describe 'MonkeyKeyboardEnUs' do
|
|
23
20
|
end
|
24
21
|
|
25
22
|
context 'right_keys' do
|
26
|
-
it '
|
23
|
+
it 'has the correct amount of keyboard entries on the right side of the keyboard' do
|
27
24
|
key_count = 0
|
28
25
|
|
29
|
-
@it.keys.each do |key|
|
26
|
+
@it.keys.each do |key| # rubocop:disable Style/HashEachMethods
|
30
27
|
key_count += key.keyboard_key_weight if key.keyboard_key_section == :right
|
31
28
|
end
|
32
29
|
|
data/spec/monkey_manager_spec.rb
CHANGED
data/spec/monkey_service_spec.rb
CHANGED
@@ -24,26 +24,26 @@ describe 'MonkeyService' do
|
|
24
24
|
@it.join_all(10)
|
25
25
|
end
|
26
26
|
|
27
|
-
def update(time, action,
|
27
|
+
def update(time, action, _param)
|
28
28
|
# puts "Time: [#{time}], Action: [#{action}], Param: [#{param}]"
|
29
29
|
puts "Time: [#{time}], Action: [#{action}], Param: <not shown>"
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'initialization' do
|
33
|
-
it '
|
33
|
+
it 'has 3 monkeys' do
|
34
34
|
@it.count.should == 3
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
38
|
-
@it.exists?(:harpo).should
|
37
|
+
it 'has monkey harpo' do
|
38
|
+
@it.exists?(:harpo).should be true
|
39
39
|
end
|
40
40
|
|
41
|
-
it '
|
42
|
-
@it.exists?(:groucho).should
|
41
|
+
it 'has monkey groucho' do
|
42
|
+
@it.exists?(:groucho).should be true
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
46
|
-
@it.exists?(:chico).should
|
45
|
+
it 'has monkey chico' do
|
46
|
+
@it.exists?(:chico).should be true
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -59,7 +59,7 @@ describe 'MonkeyService' do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "'any_alive?' should return objects that are alive" do
|
62
|
-
@it.any_alive?.should
|
62
|
+
@it.any_alive?.should be true
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -71,7 +71,7 @@ describe 'MonkeyService' do
|
|
71
71
|
# Give them a little bit to finish.
|
72
72
|
@it.join_all(10)
|
73
73
|
|
74
|
-
@it.any_alive?.should
|
74
|
+
@it.any_alive?.should be false
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'kill_all! should return all monkeys killed' do
|
@@ -87,7 +87,7 @@ describe 'MonkeyService' do
|
|
87
87
|
|
88
88
|
monkey_service.join_all(10)
|
89
89
|
|
90
|
-
(monkeys == killed_monkeys).should
|
90
|
+
(monkeys == killed_monkeys).should be true
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
data/spec/monkey_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,27 +2,27 @@
|
|
2
2
|
|
3
3
|
# Shared for monkey action.
|
4
4
|
shared_examples_for 'MonkeyAction' do
|
5
|
-
it '
|
6
|
-
@it.respond_to?(:monkey).should
|
5
|
+
it 'has read access to monkey' do
|
6
|
+
@it.respond_to?(:monkey).should be true
|
7
7
|
end
|
8
8
|
|
9
|
-
it '
|
9
|
+
it 'does not have write access to monkey' do
|
10
10
|
@it.respond_to?(:monkey=).should_not == true
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
it_behaves_like 'Action'
|
14
14
|
end
|
15
15
|
|
16
16
|
# Action
|
17
17
|
shared_examples_for 'Action' do
|
18
|
-
it '
|
18
|
+
it 'respond_to?s :value' do
|
19
19
|
# "Value: #{@it.value}"
|
20
|
-
@it.respond_to?(:value).should
|
20
|
+
@it.respond_to?(:value).should be true
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'respond_to?s :weight' do
|
24
24
|
# "Weight: #{@it.weight}"
|
25
|
-
@it.respond_to?(:weight).should
|
25
|
+
@it.respond_to?(:weight).should be true
|
26
26
|
end
|
27
27
|
|
28
28
|
# value
|
@@ -36,6 +36,6 @@ shared_examples_for 'Action' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it '@weight should be is_a? Float' do
|
39
|
-
@it.weight.is_a?(Float).should
|
39
|
+
@it.weight.is_a?(Float).should be true
|
40
40
|
end
|
41
41
|
end
|