my_scripts 0.1.0 → 0.1.3

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/HISTORY CHANGED
@@ -11,3 +11,15 @@
11
11
 
12
12
  * Bones dependency eliminated
13
13
  * Codebase cleaned up
14
+
15
+ == 0.1.1 / 2010-04-14
16
+
17
+ * Gitto: HISTORY message added
18
+
19
+ == 0.1.2 / 2010-04-14
20
+
21
+ * Gitto specs added
22
+
23
+ == 0.1.3 / 2010-04-14
24
+
25
+ * Gitto specs added
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.3
@@ -8,7 +8,7 @@ module MyScripts
8
8
  end
9
9
  end
10
10
 
11
- attr_accessor :stdout, :stdin
11
+ attr_accessor :stdout, :stdin, :kernel
12
12
 
13
13
  # Instantiates new CLI(command line interface) and runs script with given name (token)
14
14
  # and argv inside new CLI instance
@@ -17,9 +17,10 @@ module MyScripts
17
17
  end
18
18
 
19
19
  # Creates new command line interface
20
- def initialize( stdin=$stdin, stdout=$stdout )
20
+ def initialize( stdin=$stdin, stdout=$stdout, kernel = Kernel )
21
21
  @stdin = stdin
22
22
  @stdout = stdout
23
+ @kernel = kernel
23
24
  end
24
25
 
25
26
  # Runs a script with given name (token) and argv inside this CLI instance
@@ -20,6 +20,10 @@ module MyScripts
20
20
  def run
21
21
  end
22
22
 
23
+ def system( *args)
24
+ @cli.kernel.system *args
25
+ end
26
+
23
27
  def puts( *args )
24
28
  @cli.stdout.puts *args
25
29
  nil
@@ -11,7 +11,7 @@ module MyScripts
11
11
  name = @argv.shift
12
12
 
13
13
  # All the other args lumped into summary, or default summary
14
- summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
14
+ summary = @argv.empty? ? "New project #{name}" : @argv.join(' ')
15
15
 
16
16
  puts "Creating Bones project #{name} with summary: #{summary}"
17
17
 
@@ -8,16 +8,31 @@ module MyScripts
8
8
  usage "[0.1.2 - version, 100/10/1 - bump major/minor/patch, .patch - add patch] Commit message goes here" if @argv.empty?
9
9
 
10
10
  # First Arg may indicate version command if it matches pattern
11
- ver = @argv[0] =~ /^(\d+\.\d+\.\d+(?:\.(.*?))?|\.(.*?)|\d{1}0{0,2})$/ ? @argv.shift : nil
11
+ version_command = @argv[0] =~ /^(\d+\.\d+\.\d+(?:\.(.*?))?|\.(.*?)|\d{1}0{0,2})$/ ? @argv.shift : nil
12
12
 
13
13
  # All the other args lumped into message, or default message
14
- message = @argv.empty? ? "Commit #{Time.now.to_s[0..-6]}" : @argv.join(' ')
14
+ if @argv.empty?
15
+ commit_message = "Commit #{Time.now.to_s[0..-6]}"
16
+ history_message = nil
17
+ else
18
+ commit_message = history_message = @argv.join(' ')
19
+ end
15
20
 
16
- puts "Committing #{ ver ? "(version = #{ver}) " : ""}with message: #{message}"
21
+ # Updating version if version command set
22
+ if version_command
23
+ puts "Updating version with #{version_command}"
24
+ if history_message
25
+ system %Q{rake "version[#{version_command},#{history_message}]"}
26
+ else
27
+ system %Q{rake version[#{version_command}]}
28
+ end
29
+ end
17
30
 
18
- system %Q{rake version[#{ver}]} if ver
31
+ puts "Committing with message: #{commit_message}"
19
32
  system %Q{git add --all}
20
- system %Q{git commit -a -m "#{message}" --author arvicco}
33
+ system %Q{git commit -a -m "#{commit_message}" --author arvicco}
34
+
35
+ puts "Pushing to remote(s)"
21
36
  system %Q{git push}
22
37
  end
23
38
  end
@@ -7,14 +7,14 @@ module MyScripts
7
7
  usage "project_name Summary or description goes here" if @argv.empty?
8
8
 
9
9
  # First Arg should be project name
10
- project = @argv.shift
10
+ name = @argv.shift
11
11
 
12
12
  # All the other args lumped into summary, or default summary
13
- summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
13
+ summary = @argv.empty? ? "New project #{name}" : @argv.join(' ')
14
14
 
15
- puts "Creating Jeweler project #{project} with summary/description: #{summary}"
15
+ puts "Creating Jeweler project #{name} with summary/description: #{summary}"
16
16
 
17
- system %Q[jeweler --rspec --cucumber --create-repo --summary "#{summary}" --description "#{summary}" #{project}]
17
+ system %Q[jeweler --rspec --cucumber --create-repo --summary "#{summary}" --description "#{summary}" #{name}]
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'my_scripts/scripts/shared'
3
+
4
+ module MyScriptsTest
5
+ VERSION_COMMANDS = %W[1 10 100 1.2.3 1.2.3.beta2 0.0.1.patch .patch .b2a]
6
+
7
+ describe MyScripts::Gitto do
8
+ before(:each) do
9
+ create_cli(:system=> 'ok')
10
+ @name = 'gitto'
11
+ end
12
+
13
+ it_should_behave_like "script with args"
14
+
15
+ context 'No version command' do
16
+ it 'Commits with message, pushes to remote' do
17
+ message = 'This is bomb!'
18
+ stdout_should_receive "Committing with message: #{message}",
19
+ "Pushing to remote(s)"
20
+ system_should_receive "git add --all",
21
+ %Q{git commit -a -m "#{message}" --author arvicco},
22
+ "git push"
23
+ cli "#{@name} #{message}"
24
+ end
25
+
26
+ context 'With version command' do
27
+ it 'Commits with message if message given, pushes to remote' do
28
+ VERSION_COMMANDS.each do |command|
29
+ message = 'This is bomb!'
30
+
31
+ stdout_should_receive "Committing with message: #{message}",
32
+ "Pushing to remote(s)"
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}"
38
+ end
39
+ end
40
+
41
+ it 'Commits and pushes with default timestamped message if no message' do
42
+ VERSION_COMMANDS.each do |command|
43
+ stdout_should_receive "Committing with message: Commit #{Time.now.to_s[0..-6]}",
44
+ "Pushing to remote(s)"
45
+ system_should_receive "rake version[#{command}]",
46
+ "git add --all",
47
+ %Q{git commit -a -m "Commit #{Time.now.to_s[0..-6]}" --author arvicco},
48
+ "git push"
49
+ cli "#{@name} #{command}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ shared_examples_for "script with args" do
2
+
3
+ it 'displays usage and exits if no args given' do
4
+ stdout_should_receive :pattern, Regexp.new("Script #{@name} .* - Usage:")
5
+ expect{ cli "#{@name}" }.to raise_error SystemExit
6
+ end
7
+ end
@@ -2,35 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module MyScriptsTest
4
4
 
5
- # creates new CLI object with mock stdin and stdout,
6
- # stdin optionally preloaded with fake user input
7
- def create_cli( opts={} )
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
15
- @cli = MyScripts::CLI.new @stdin, @stdout
16
- end
17
-
18
- # sets expectation for stdout to receive strictly ordered sequence of exact messages
19
- def stdout_should_receive(*messages)
20
- messages.each do |message|
21
- @stdout.should_receive(:puts).with(message).once.ordered
22
- end
23
- end
24
-
25
- # sets expectation for stdout to receive message(s) containing all of the patterns (unordered)
26
- def stdout_should_include(*patterns)
27
- patterns.each do |pattern|
28
- re = Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern))
29
- @stdout.should_receive(:puts).with(re).at_least(:once)
30
- end
31
- end
32
-
33
- describe 'Script Execution' do
5
+ describe 'Script Execution (in general)' do
34
6
  MyScripts.module_eval do
35
7
  # Stub script that outputs @argv, prompts to stdout and echoes/returns what it gets from stdin
36
8
  class Scriptest < Script #one word for script name
@@ -63,6 +35,13 @@ module MyScriptsTest
63
35
  usage 'Blah'
64
36
  end
65
37
  end
38
+
39
+ # Stub script that calls system
40
+ class SystemScript < Script
41
+ def run
42
+ system 'Blah'
43
+ end
44
+ end
66
45
  end
67
46
 
68
47
  context 'trying to execute undefined script' do
@@ -128,7 +107,7 @@ module MyScriptsTest
128
107
  end
129
108
  end
130
109
 
131
- context 'prints usage' do
110
+ context 'printing usage' do
132
111
  context 'unversioned script' do
133
112
  it 'outputs script name, GEM version and usage note to stdout, then exits' do
134
113
  cli = create_cli
@@ -148,6 +127,14 @@ module MyScriptsTest
148
127
  end
149
128
  end
150
129
 
130
+ context 'scripts calling system' do
131
+ it 'calls system method on cli.kernel' do
132
+ cli = create_cli :system => 'OK'
133
+ system_should_receive('Blah')
134
+ cli.run(:system_script, []).should == 'OK'
135
+ end
136
+ end
137
+
151
138
  context 'scripts with snake_case names' do
152
139
  it 'executes scripts with snake_case name' do
153
140
  cli = create_cli
data/spec/spec_helper.rb CHANGED
@@ -4,3 +4,56 @@ require 'spec/autorun'
4
4
 
5
5
  Spec::Runner.configure do |config|
6
6
  end
7
+
8
+ module MyScriptsTest
9
+
10
+ def create_cli(opts={})
11
+ @stdout = opts[:stdout] || mock('stdout').as_null_object
12
+ @stdin = opts[:stdin] || mock('stdin')
13
+ if opts[:input]
14
+ @stdin.stub(:gets).and_return(*opts[:input])
15
+ else
16
+ @stdin.stub(:gets).and_return('')
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)
24
+ end
25
+
26
+ def cli(command_line)
27
+ raise "Command line should be non-empty String" unless command_line.respond_to?(:split) && command_line != ''
28
+ argv = command_line.split(' ')
29
+ @cli.run argv.shift.to_sym, argv
30
+ end
31
+
32
+ # Sets expectation for Kernel to receive system call with specific messages/patterns
33
+ def system_should_receive(*messages)
34
+ entity_should_receive(@kernel, :system, *messages)
35
+ end
36
+
37
+ # Sets expectation for stdout to receive puts with specific messages/patterns
38
+ def stdout_should_receive(*messages)
39
+ entity_should_receive(@stdout, :puts, *messages)
40
+ end
41
+
42
+ # Sets expectation for entity to receive either:
43
+ # :message(s) - strictly ordered sequence of exact messages
44
+ # :pattern(s) - specific patterns (unordered)
45
+ #
46
+ def entity_should_receive(entity, method, *messages)
47
+ # If symbol is coming after method, it must be message type
48
+ type = messages.first.is_a?(Symbol) ? messages.shift : :message
49
+ messages.each do |message|
50
+ if type.to_s =~ /message/
51
+ entity.should_receive(method).with(message).once.ordered
52
+ elsif type.to_s =~ /(pattern|regex)/
53
+ re = Regexp === message ? message : Regexp.new(Regexp.escape(message))
54
+ entity.should_receive(method).with(re).at_least(:once)
55
+ end
56
+ end
57
+ end
58
+
59
+ end
data/tasks/gem.rake CHANGED
@@ -1,6 +1,9 @@
1
1
  desc "Alias to gem:release"
2
2
  task :release => 'gem:release'
3
3
 
4
+ desc "Alias to gem:install"
5
+ task :install => 'gem:install'
6
+
4
7
  desc "Alias to gem:build"
5
8
  task :gem => 'gem:build'
6
9
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - arvicco
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-13 00:00:00 +04:00
17
+ date: 2010-04-14 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,8 @@ files:
76
76
  - lib/my_scripts/scripts/wake.rb
77
77
  - lib/my_scripts.rb
78
78
  - spec/my_scripts/extensions_spec.rb
79
+ - spec/my_scripts/scripts/gitto_spec.rb
80
+ - spec/my_scripts/scripts/shared.rb
79
81
  - spec/my_scripts_spec.rb
80
82
  - spec/spec.opts
81
83
  - spec/spec_helper.rb
@@ -132,6 +134,8 @@ specification_version: 3
132
134
  summary: Describe package my_scripts
133
135
  test_files:
134
136
  - spec/my_scripts/extensions_spec.rb
137
+ - spec/my_scripts/scripts/gitto_spec.rb
138
+ - spec/my_scripts/scripts/shared.rb
135
139
  - spec/my_scripts_spec.rb
136
140
  - spec/spec.opts
137
141
  - spec/spec_helper.rb