my_scripts 0.0.17 → 0.0.19
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.
- data/VERSION +1 -1
- data/lib/my_scripts/script.rb +5 -0
- data/lib/my_scripts/wake.rb +2 -2
- data/my_scripts.gemspec +1 -1
- data/spec/my_scripts_spec.rb +80 -25
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.19
|
data/lib/my_scripts/script.rb
CHANGED
data/lib/my_scripts/wake.rb
CHANGED
@@ -11,9 +11,9 @@ module MyScripts
|
|
11
11
|
|
12
12
|
require 'win/gui/input'
|
13
13
|
|
14
|
-
define_method :move_mouse_randomly do
|
14
|
+
self.class.define_method :move_mouse_randomly do
|
15
15
|
x, y = Win::Gui::Input::get_cursor_pos
|
16
|
-
x1, y1 = x+rand(3)-1, y+rand(3)-1
|
16
|
+
x1, y1 = x + rand(3) - 1, y + rand(3) - 1
|
17
17
|
Win::Gui::Input::mouse_event(Win::Gui::Input::MOUSEEVENTF_ABSOLUTE, x1, y1, 0, 0)
|
18
18
|
puts "Cursor positon set to #{x1}, #{y1}"
|
19
19
|
end
|
data/my_scripts.gemspec
CHANGED
data/spec/my_scripts_spec.rb
CHANGED
@@ -5,9 +5,13 @@ module MyScriptsTest
|
|
5
5
|
# creates new CLI object with mock stdin and stdout,
|
6
6
|
# stdin optionally preloaded with fake user input
|
7
7
|
def create_cli( opts={} )
|
8
|
-
@stdout =
|
9
|
-
@stdin =
|
10
|
-
|
8
|
+
@stdout = opts[:stdout] || mock('stdout').as_null_object
|
9
|
+
@stdin = opts[:stdin] || mock('stdin')
|
10
|
+
if opts[:input]
|
11
|
+
@stdin.stub(:gets).and_return(*opts[:input])
|
12
|
+
else
|
13
|
+
@stdin.stub(:gets).and_return('')
|
14
|
+
end
|
11
15
|
@cli = MyScripts::CLI.new @stdin, @stdout
|
12
16
|
end
|
13
17
|
|
@@ -35,42 +39,93 @@ module MyScriptsTest
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
context '
|
39
|
-
MyScripts.module_eval
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
context 'scripts without arguments' do
|
43
|
+
MyScripts.module_eval do
|
44
|
+
# Stub script that prompts to stdout and echoes/returns what it gets from stdin
|
45
|
+
class Scriptest < Script
|
46
|
+
def run
|
47
|
+
puts 'Say it:'
|
48
|
+
puts gotten = gets
|
49
|
+
gotten
|
50
|
+
end
|
45
51
|
end
|
46
|
-
end
|
52
|
+
end
|
47
53
|
|
48
|
-
it 'executes pre-defined script
|
54
|
+
it 'cli.run executes pre-defined script' do
|
49
55
|
cli = create_cli
|
50
|
-
|
56
|
+
expect{cli.run :scriptest, []}.to_not raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'script outputs to given stdout' do
|
60
|
+
cli = create_cli
|
61
|
+
stdout_should_receive('Say it:')
|
51
62
|
cli.run :scriptest, []
|
52
63
|
end
|
53
64
|
|
54
|
-
it '
|
65
|
+
it 'script gets value from given stdin' do
|
66
|
+
cli = create_cli :input => 'yes'
|
67
|
+
stdout_should_receive('yes')
|
68
|
+
cli.run( :scriptest, [])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'script returns last value of run() method' do
|
72
|
+
cli = create_cli :input => 'yes'
|
73
|
+
cli.run( :scriptest, []).should == 'yes'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'scripts with arguments' do
|
78
|
+
before(:each) {@given_args = [1, 2, 3, :four, 'five']}
|
79
|
+
MyScripts.module_eval do
|
80
|
+
# Stub script that prompts to stdout and echoes/returns what it gets from stdin
|
81
|
+
class Scriptest < Script
|
82
|
+
def run
|
83
|
+
puts @argv
|
84
|
+
puts 'Say it:'
|
85
|
+
puts gotten = gets
|
86
|
+
gotten
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'cli.run executes pre-defined script' do
|
55
92
|
cli = create_cli
|
56
|
-
|
57
|
-
|
93
|
+
expect{cli.run :scriptest, @given_args}.to_not raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'script outputs to given stdout' do
|
97
|
+
cli = create_cli
|
98
|
+
stdout_should_receive('Say it:')
|
99
|
+
cli.run :scriptest, @given_args
|
58
100
|
end
|
59
101
|
|
60
|
-
it '
|
102
|
+
it 'script receives given arguments in @argv' do
|
61
103
|
cli = create_cli
|
62
|
-
|
104
|
+
stdout_should_receive(@given_args)
|
105
|
+
cli.run :scriptest, @given_args
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'script gets value from given stdin' do
|
109
|
+
cli = create_cli :input => 'yes'
|
110
|
+
stdout_should_receive('yes')
|
111
|
+
cli.run( :scriptest, @given_args)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'script returns last value of run() method' do
|
115
|
+
cli = create_cli :input => 'yes'
|
116
|
+
cli.run( :scriptest, @given_args).should == 'yes'
|
63
117
|
end
|
64
118
|
end
|
65
119
|
|
66
|
-
context '
|
67
|
-
MyScripts.module_eval
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
120
|
+
context 'scripts with snake_case names' do
|
121
|
+
MyScripts.module_eval do
|
122
|
+
# Stub script that just puts 'OK' to stdout
|
123
|
+
class SnakeScript < Script
|
124
|
+
def run
|
125
|
+
puts 'OK'
|
126
|
+
end
|
72
127
|
end
|
73
|
-
end
|
128
|
+
end
|
74
129
|
|
75
130
|
it 'executes scripts with snake_case name' do
|
76
131
|
cli = create_cli
|