my_scripts 0.0.17 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
1
+ 0.0.19
@@ -13,6 +13,11 @@ module MyScripts
13
13
 
14
14
  def puts *args
15
15
  @cli.stdout.puts *args
16
+ nil
17
+ end
18
+
19
+ def gets
20
+ @cli.stdin.gets
16
21
  end
17
22
 
18
23
  def usage examples, explanation = nil
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{my_scripts}
8
- s.version = "0.0.17"
8
+ s.version = "0.0.19"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["arvicco"]
@@ -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 = options[:stdout] || mock('stdout').as_null_object
9
- @stdin = options[:stdin] || mock('stdin')
10
- @stdin.stub(:gets).and_return(*options[:input]) if options[:input]
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 'executing pre-defined scripts' do
39
- MyScripts.module_eval "
40
- # Stub script that just puts 'OK' to stdout
41
- class Scriptest < Script
42
- def run
43
- puts 'OK'
44
- 1
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 without args' do
54
+ it 'cli.run executes pre-defined script' do
49
55
  cli = create_cli
50
- stdout_should_receive('OK')
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 'executes pre-defined script with args' do
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
- stdout_should_receive('OK')
57
- cli.run :scriptest, [1, 2, 3, :four, 'five']
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 'returns return value of Script#run() when running pre-defined script' do
102
+ it 'script receives given arguments in @argv' do
61
103
  cli = create_cli
62
- cli.run( :scriptest, []).should == 1
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 'executing scripts with snake_case names' do
67
- MyScripts.module_eval "
68
- # Stub script that just puts 'OK' to stdout
69
- class SnakeScript < Script
70
- def run
71
- puts 'OK'
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 17
9
- version: 0.0.17
8
+ - 19
9
+ version: 0.0.19
10
10
  platform: ruby
11
11
  authors:
12
12
  - arvicco