my_scripts 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/Rakefile +2 -7
- data/VERSION +1 -1
- data/spec/my_scripts/extensions_spec.rb +40 -42
- data/spec/my_scripts/scripts/gitto_spec.rb +41 -44
- data/spec/my_scripts/scripts/msdn/msdn_helper_spec.rb +1 -1
- data/spec/my_scripts/scripts/msdn_spec.rb +19 -21
- data/spec/{my_scripts/scripts/shared.rb → shared.rb} +0 -0
- data/spec/spec_helper.rb +57 -61
- metadata +22 -8
- data/spec/spec.opts +0 -2
data/HISTORY
CHANGED
data/Rakefile
CHANGED
@@ -11,13 +11,8 @@ require NAME
|
|
11
11
|
CLASS_NAME = MyScripts
|
12
12
|
VERSION = CLASS_NAME::VERSION
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
rescue LoadError
|
17
|
-
require 'rubygems'
|
18
|
-
gem 'rake', '~> 0.8.3.1'
|
19
|
-
require 'rake'
|
20
|
-
end
|
14
|
+
gem 'rake', '~> 0.8.7'
|
15
|
+
require 'rake'
|
21
16
|
|
22
17
|
# Load rakefile tasks
|
23
18
|
Dir['tasks/*.rake'].sort.each { |file| load file }
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.14
|
@@ -2,60 +2,58 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
class
|
8
|
-
class C
|
9
|
-
end
|
5
|
+
module A
|
6
|
+
class B
|
7
|
+
class C
|
10
8
|
end
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'leaves snake_case strings intact' do
|
20
|
-
'keybd_event'.snake_case.should == 'keybd_event'
|
21
|
-
end
|
12
|
+
describe String do
|
13
|
+
context '#snake_case' do
|
14
|
+
it 'transforms CamelCase strings' do
|
15
|
+
'GetCharWidth32'.snake_case.should == 'get_char_width_32'
|
22
16
|
end
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
it 'leaves snake_case strings intact' do
|
19
|
+
'keybd_event'.snake_case.should == 'keybd_event'
|
20
|
+
end
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
context '#camel_case' do
|
24
|
+
it 'transforms underscore strings to CamelCase' do
|
25
|
+
'get_char_width_32'.camel_case.should == 'GetCharWidth32'
|
32
26
|
end
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
28
|
+
it 'leaves CamelCase strings intact' do
|
29
|
+
'GetCharWidth32'.camel_case.should == 'GetCharWidth32'
|
30
|
+
end
|
31
|
+
end
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
context '#to_class' do
|
34
|
+
it 'converts string into appropriate Class constant' do
|
35
|
+
"Fixnum".to_class.should == Fixnum
|
36
|
+
"A::B::C".to_class.should == A::B::C
|
37
|
+
end
|
45
38
|
|
46
|
-
|
47
|
-
|
48
|
-
|
39
|
+
it 'returns nil if string is not convertible into class' do
|
40
|
+
"Math".to_class.should == nil
|
41
|
+
"Math::PI".to_class.should == nil
|
42
|
+
"Something".to_class.should == nil
|
49
43
|
end
|
50
44
|
|
51
|
-
|
52
|
-
|
53
|
-
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства".translit!.
|
54
|
-
should == "SHirokaya elektrifikatsiya yuzhnykh gubernij dast moshchnyj tolchok pod\"emu sel'skogo khozyajstva"
|
55
|
-
"ШИРОКАЯ ЭЛЕКТРИФИКАЦИЯ ЮЖНЫХ ГУБЕРНИЙ ДАСТ МОЩНЫЙ ТОЛЧОК ПОДЪЁМУ СЕЛЬСКОГО ХОЗЯЙСТВА".translit!.
|
56
|
-
should == "SHIROKAYA ELEKTRIFIKATSIYA YUZHNYKH GUBERNIJ DAST MOSHCHNYJ TOLCHOK POD\"EMU SEL'SKOGO KHOZYAJSTVA"
|
57
|
-
end
|
45
|
+
it 'deals with leading colons' do
|
46
|
+
"::A::B::C".to_class.should == A::B::C
|
58
47
|
end
|
48
|
+
end
|
59
49
|
|
50
|
+
context '#translit!' do
|
51
|
+
it 'converts string from Cyrillic to Latin translit' do
|
52
|
+
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства".translit!.
|
53
|
+
should == "SHirokaya elektrifikatsiya yuzhnykh gubernij dast moshchnyj tolchok pod\"emu sel'skogo khozyajstva"
|
54
|
+
"ШИРОКАЯ ЭЛЕКТРИФИКАЦИЯ ЮЖНЫХ ГУБЕРНИЙ ДАСТ МОЩНЫЙ ТОЛЧОК ПОДЪЁМУ СЕЛЬСКОГО ХОЗЯЙСТВА".translit!.
|
55
|
+
should == "SHIROKAYA ELEKTRIFIKATSIYA YUZHNYKH GUBERNIJ DAST MOSHCHNYJ TOLCHOK POD\"EMU SEL'SKOGO KHOZYAJSTVA"
|
56
|
+
end
|
60
57
|
end
|
61
|
-
|
58
|
+
|
59
|
+
end
|
@@ -1,56 +1,53 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'my_scripts/scripts/shared'
|
3
2
|
|
4
|
-
|
5
|
-
VERSION_COMMANDS = %W[1 10 100 1.2.3 1.2.3.beta2 0.0.1.patch .patch .b2a]
|
3
|
+
VERSION_COMMANDS = %W[1 10 100 1.2.3 1.2.3.beta2 0.0.1.patch .patch .b2a]
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
describe MyScripts::Gitto do
|
6
|
+
before(:each) do
|
7
|
+
create_cli(:system=> 'ok')
|
8
|
+
@name = 'gitto'
|
9
|
+
end
|
12
10
|
|
13
|
-
|
11
|
+
it_should_behave_like "script with args"
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
context 'No version command' do
|
14
|
+
it 'Commits with message, pushes to remote' do
|
15
|
+
message = 'This is bomb!'
|
16
|
+
stdout_should_receive "Adding all the changes",
|
17
|
+
"Committing everything with message: #{message}",
|
18
|
+
"Pushing to (default) remote for branch: * master"
|
19
|
+
system_should_receive "git add --all",
|
20
|
+
%Q{git commit -a -m "#{message}" --author arvicco},
|
21
|
+
"git push"
|
22
|
+
cli "#{@name} #{message}"
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
context 'With version command' do
|
26
|
+
it 'Commits with message if message given, pushes to remote' do
|
27
|
+
VERSION_COMMANDS.each do |command|
|
28
|
+
message = 'This is bomb!'
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
30
|
+
stdout_should_receive "Adding all the changes",
|
31
|
+
"Committing everything with message: #{message}",
|
32
|
+
"Pushing to (default) remote for branch: * master"
|
33
|
+
system_should_receive %Q{rake "version[#{command},#{message}]"},
|
34
|
+
"git add --all",
|
35
|
+
%Q{git commit -a -m "#{message}" --author arvicco},
|
36
|
+
"git push"
|
37
|
+
cli "#{@name} #{command} #{message}"
|
41
38
|
end
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
41
|
+
it 'Commits and pushes with default timestamped message if no message' do
|
42
|
+
VERSION_COMMANDS.each do |command|
|
43
|
+
stdout_should_receive "Adding all the changes",
|
44
|
+
"Committing everything with message: Commit #{Time.now.to_s[0..-6]}",
|
45
|
+
"Pushing to (default) remote for branch: * master"
|
46
|
+
system_should_receive "rake version[#{command}]",
|
47
|
+
"git add --all",
|
48
|
+
%Q{git commit -a -m "Commit #{Time.now.to_s[0..-6]}" --author arvicco},
|
49
|
+
"git push"
|
50
|
+
cli "#{@name} #{command}"
|
54
51
|
end
|
55
52
|
end
|
56
53
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
# Delegation (for
|
1
|
+
# Delegation (for autotest)
|
2
2
|
require 'my_scripts/scripts/msdn_spec'
|
@@ -1,32 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'my_scripts/scripts/shared'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@name = 'msdn'
|
9
|
-
end
|
3
|
+
describe MyScripts::Msdn do
|
4
|
+
before(:each) do
|
5
|
+
@name = 'msdn'
|
6
|
+
end
|
10
7
|
|
11
|
-
|
8
|
+
context 'With explicit infile, no outfile' do
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
10
|
+
it 'reads from infile, writes to stdout' do
|
11
|
+
test_files(@name).each do |infile, outfile|
|
12
|
+
create_cli
|
13
|
+
stdout_should_receive outfile.readlines.map(&:chomp).join("\n") + "\n"
|
14
|
+
cli "#{@name} #{infile}", infile
|
19
15
|
end
|
20
16
|
end
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
lambda{@changed_text = `msdn /tmp/msdn_temp_file`}.should_not raise_error
|
28
|
-
# puts "\n\nResult: #{@changed_text}"
|
19
|
+
it 'reads from temp file' do
|
20
|
+
text = test_files(@name)[1].first.read
|
21
|
+
temp_file = File.expand_path('/tmp/msdn_temp_file')
|
22
|
+
File.open(temp_file, 'w') do |f|
|
23
|
+
f.write(text)
|
29
24
|
end
|
30
25
|
|
26
|
+
lambda { @changed_text = `msdn /tmp/msdn_temp_file` }.should_not raise_error
|
27
|
+
# puts "\n\nResult: #{@changed_text}"
|
31
28
|
end
|
29
|
+
|
32
30
|
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,75 +1,71 @@
|
|
1
1
|
require 'my_scripts'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'rspec'
|
3
|
+
require 'shared'
|
4
4
|
|
5
|
-
Spec::Runner.configure do |config|
|
6
|
-
end
|
7
|
-
|
8
|
-
module MyScriptsTest
|
5
|
+
#Spec::Runner.configure do |config|
|
6
|
+
#end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
@kernel = Kernel
|
19
|
-
if opts[:system]
|
20
|
-
@kernel = mock('Kernel')
|
21
|
-
@kernel.stub(:system).and_return(*opts[:system])
|
22
|
-
end
|
23
|
-
@cli = MyScripts::CLI.new(@stdin, @stdout, @kernel)
|
8
|
+
def create_cli(opts={})
|
9
|
+
@stdout = opts[:stdout] || mock('stdout').as_null_object
|
10
|
+
@stdin = opts[:stdin] || mock('stdin')
|
11
|
+
if opts[:input]
|
12
|
+
@stdin.stub(:gets).and_return(*opts[:input])
|
13
|
+
else
|
14
|
+
@stdin.stub(:gets).and_return('')
|
24
15
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@cli.run argv.shift.to_sym, argv, argf
|
16
|
+
@kernel = Kernel
|
17
|
+
if opts[:system]
|
18
|
+
@kernel = mock('Kernel')
|
19
|
+
@kernel.stub(:system).and_return(*opts[:system])
|
30
20
|
end
|
21
|
+
@cli = MyScripts::CLI.new(@stdin, @stdout, @kernel)
|
22
|
+
end
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
def cli(command_line, argf=ARGF)
|
25
|
+
raise "Command line should be non-empty String" unless command_line.respond_to?(:split) && command_line != ''
|
26
|
+
argv = command_line.split(' ')
|
27
|
+
@cli.run argv.shift.to_sym, argv, argf
|
28
|
+
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
# Sets expectation for Kernel to receive system call with specific messages/patterns
|
31
|
+
def system_should_receive(*messages)
|
32
|
+
entity_should_receive(@kernel, :system, *messages)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Sets expectation for stdout to receive puts with specific messages/patterns
|
36
|
+
def stdout_should_receive(*messages)
|
37
|
+
entity_should_receive(@stdout, :puts, *messages)
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
40
|
+
# Sets expectation for entity to receive either:
|
41
|
+
# :message(s) - strictly ordered sequence of exact messages
|
42
|
+
# :pattern(s) - specific patterns (unordered)
|
43
|
+
#
|
44
|
+
def entity_should_receive(entity, method, *messages)
|
45
|
+
# If symbol is coming after method, it must be message type
|
46
|
+
type = messages.first.is_a?(Symbol) ? messages.shift : :message
|
47
|
+
messages.each do |message|
|
48
|
+
if type.to_s =~ /message/
|
49
|
+
entity.should_receive(method).with(message).once.ordered
|
50
|
+
elsif type.to_s =~ /(pattern|regex)/
|
51
|
+
re = Regexp === message ? message : Regexp.new(Regexp.escape(message))
|
52
|
+
entity.should_receive(method).with(re).at_least(:once)
|
56
53
|
end
|
57
54
|
end
|
55
|
+
end
|
58
56
|
|
59
|
-
|
60
|
-
|
57
|
+
# Lists files of specific type
|
58
|
+
def test_files(dir)
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
files_dir = Pathname(__FILE__).dirname + 'files' + dir
|
61
|
+
infiles_glob = (files_dir + '*_in.txt').to_s
|
62
|
+
outfiles_glob = (files_dir + '*_out.txt').to_s
|
63
|
+
infiles = Pathname.glob(infiles_glob)
|
64
|
+
outfiles = Pathname.glob(outfiles_glob)
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
66
|
+
if infiles.size == outfiles.size
|
67
|
+
infiles.zip(outfiles)
|
68
|
+
else
|
69
|
+
nil
|
73
70
|
end
|
74
|
-
|
75
|
-
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_scripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 14
|
10
|
+
version: 0.1.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- arvicco
|
@@ -48,6 +48,22 @@ dependencies:
|
|
48
48
|
version: "0"
|
49
49
|
type: :development
|
50
50
|
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: bundler
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 13
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 2
|
63
|
+
- 9
|
64
|
+
version: 1.2.9
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
51
67
|
description: Simple scripting framework
|
52
68
|
email: arvitallian@gmail.com
|
53
69
|
executables:
|
@@ -99,9 +115,8 @@ files:
|
|
99
115
|
- spec/my_scripts/scripts/gitto_spec.rb
|
100
116
|
- spec/my_scripts/scripts/msdn/msdn_helper_spec.rb
|
101
117
|
- spec/my_scripts/scripts/msdn_spec.rb
|
102
|
-
- spec/my_scripts/scripts/shared.rb
|
103
118
|
- spec/my_scripts_spec.rb
|
104
|
-
- spec/
|
119
|
+
- spec/shared.rb
|
105
120
|
- spec/spec_helper.rb
|
106
121
|
- features/my_scripts.feature
|
107
122
|
- features/step_definitions/my_scripts_steps.rb
|
@@ -152,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
167
|
version: "0"
|
153
168
|
requirements: []
|
154
169
|
|
155
|
-
rubyforge_project:
|
170
|
+
rubyforge_project:
|
156
171
|
rubygems_version: 1.3.7
|
157
172
|
signing_key:
|
158
173
|
specification_version: 3
|
@@ -170,7 +185,6 @@ test_files:
|
|
170
185
|
- spec/my_scripts/scripts/gitto_spec.rb
|
171
186
|
- spec/my_scripts/scripts/msdn/msdn_helper_spec.rb
|
172
187
|
- spec/my_scripts/scripts/msdn_spec.rb
|
173
|
-
- spec/my_scripts/scripts/shared.rb
|
174
188
|
- spec/my_scripts_spec.rb
|
175
|
-
- spec/
|
189
|
+
- spec/shared.rb
|
176
190
|
- spec/spec_helper.rb
|
data/spec/spec.opts
DELETED