pik 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/History.txt +36 -0
  2. data/Manifest.txt +42 -0
  3. data/README.rdoc +174 -0
  4. data/Rakefile +37 -0
  5. data/bin/pik +33 -0
  6. data/lib/pik.rb +30 -0
  7. data/lib/pik/batch_file.rb +70 -0
  8. data/lib/pik/checkup.rb +11 -0
  9. data/lib/pik/commands.rb +35 -0
  10. data/lib/pik/commands/add_command.rb +65 -0
  11. data/lib/pik/commands/batch_file_editor.rb +62 -0
  12. data/lib/pik/commands/checkup_command.rb +67 -0
  13. data/lib/pik/commands/command.rb +166 -0
  14. data/lib/pik/commands/config_command.rb +28 -0
  15. data/lib/pik/commands/config_file_editor.rb +12 -0
  16. data/lib/pik/commands/default_command.rb +22 -0
  17. data/lib/pik/commands/gemsync_command.rb +69 -0
  18. data/lib/pik/commands/help_command.rb +44 -0
  19. data/lib/pik/commands/implode_command.rb +16 -0
  20. data/lib/pik/commands/list_command.rb +34 -0
  21. data/lib/pik/commands/remove_command.rb +29 -0
  22. data/lib/pik/commands/run_command.rb +37 -0
  23. data/lib/pik/commands/switch_command.rb +49 -0
  24. data/lib/pik/config_file.rb +21 -0
  25. data/lib/pik/core_ext/pathname.rb +15 -0
  26. data/lib/pik/options.rb +56 -0
  27. data/lib/pik/runner.rb +16 -0
  28. data/lib/pik/search_path.rb +51 -0
  29. data/lib/pik/windows_env.rb +64 -0
  30. data/spec/add_command_spec.rb +15 -0
  31. data/spec/batch_file_spec.rb +31 -0
  32. data/spec/command_spec.rb +34 -0
  33. data/spec/commands_spec.rb +44 -0
  34. data/spec/default_command_spec.rb +6 -0
  35. data/spec/gemsync_command_spec.rb +15 -0
  36. data/spec/help_command_spec.rb +30 -0
  37. data/spec/list_command_spec.rb +33 -0
  38. data/spec/remove_command_spec.rb +25 -0
  39. data/spec/run_command_spec.rb +36 -0
  40. data/spec/search_path_spec.rb +121 -0
  41. data/spec/spec.opts +3 -0
  42. data/spec/switch_command_spec.rb +44 -0
  43. metadata +143 -0
@@ -0,0 +1,15 @@
1
+
2
+ describe Pik::Add do
3
+
4
+ it "should have a summary" do
5
+ Pik::Add.summary.should eql("Adds another ruby location to pik.")
6
+ end
7
+
8
+ it "should have an interactive option" do
9
+ add = Pik::Add.new(['-i'])
10
+ add.interactive.should be_true
11
+ end
12
+
13
+ it "should exit with a message if nothing is found"
14
+
15
+ end
@@ -0,0 +1,31 @@
1
+
2
+ describe BatchFile do
3
+
4
+ before do
5
+ @bf = BatchFile.new('pik.bat')
6
+ end
7
+
8
+ it "should have a header" do
9
+ string = "@ECHO OFF\n\n"
10
+ string << ":: This batch file generated by Pik, the\n"
11
+ string << ":: Ruby Manager for Windows\n"
12
+ @bf.to_s.should == string
13
+ end
14
+
15
+ it "should generate an ftype command for ruby.exe and rubyw.exe" do
16
+ @bf.ftype.to_s.should match(/FTYPE rbfile\=ruby\.exe \"%1\" \%\*\n\nFTYPE rbwfile\=rubyw\.exe \"\%1\" \%\*/)
17
+ end
18
+
19
+ it "should generate a path command with the updated ruby path" do
20
+ @bf.set('PATH' => "C:\\ruby\\191\\bin").to_s.should match(/SET PATH\=C:\\ruby\\191\\bin/)
21
+ end
22
+
23
+ it "should echo a string given" do
24
+ @bf.echo("Hello World").to_s.should match(/ECHO Hello World/)
25
+ end
26
+
27
+ it "should call the command given" do
28
+ @bf.call('pik.bat').to_s.should match(/CALL pik\.bat/)
29
+ end
30
+
31
+ end
@@ -0,0 +1,34 @@
1
+ describe Pik::Command do
2
+
3
+ before(:each) do
4
+ @cmd = Pik::Command.new([])
5
+ end
6
+
7
+ describe "get_version" do
8
+ it "should create a version string" do
9
+ ver = `ruby -v`.chomp
10
+
11
+ cmd_ver = @cmd.get_version
12
+ cmd_ver.should include(ver)
13
+
14
+ ver =~ /ruby (\d)\.(\d)\.(\d)/
15
+ ver = $1 + $2 + $3
16
+ cmd_ver.should match(/^#{ver}:/)
17
+ end
18
+ end
19
+
20
+ describe "current_version?" do
21
+ it "should match the current version" do
22
+ ver = @cmd.get_version
23
+ @cmd.current_version?(ver.chomp).should be_true
24
+ end
25
+ end
26
+
27
+ describe "current_ruby_bin_path" do
28
+ it "should be a Pathname" do
29
+ @cmd.current_ruby_bin_path.should be_a(Pathname)
30
+ @cmd.current_ruby_bin_path.basename.to_s.should == "bin"
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,44 @@
1
+ module Pik
2
+ class Spec < Command
3
+ it 'is a command called spec'
4
+ aka :sp
5
+ end
6
+ end
7
+
8
+ describe Pik::Commands do
9
+
10
+ before do
11
+ Pik::Commands.clear
12
+ Pik::Commands.add(Pik::Spec)
13
+ end
14
+
15
+ describe 'description' do
16
+ it 'should list all commands' do
17
+ msg=<<-MSG
18
+ spec|sp is a command called spec
19
+
20
+ For help on a particular command, use 'pik help COMMAND'.
21
+ MSG
22
+ Pik::Commands.description.should eql(msg.chomp)
23
+ end
24
+ end
25
+
26
+ describe 'find' do
27
+ it 'should find a command class' do
28
+ Pik::Commands.find(:spec).should eql(Pik::Spec)
29
+ end
30
+
31
+ it "should return nil if the command doesn't exist" do
32
+ Pik::Commands.find(:nil).should be_nil
33
+ end
34
+
35
+ end
36
+
37
+ describe "list" do
38
+ it "should return an array of command names as symbols" do
39
+ Pik::Commands.list.should eql([:spec, :sp])
40
+ end
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,6 @@
1
+
2
+ describe Pik::Default do
3
+
4
+
5
+
6
+ end
@@ -0,0 +1,15 @@
1
+ describe Pik::GemSync do
2
+ it "should have a summary" do
3
+ summary = "Duplicates gems from the current version to the one specified."
4
+ Pik::GemSync.summary.should eql(summary)
5
+ end
6
+
7
+ describe "gem_install" do
8
+ it "should install gems via batch file" do
9
+ gemsync = Pik::GemSync.new([])
10
+ gemsync.gem_install(Pathname.new('c:/fake/file.gem'))
11
+ gemsync.batch.file_data.should include( "ECHO Installing file.gem" )
12
+ gemsync.batch.file_data.should include( "CALL gem install -q --no-rdoc --no-ri c:/fake/file.gem\n" )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+
2
+ describe Pik::Help do
3
+
4
+ before do
5
+ @cmd = 'bin\\pik.bat'
6
+ end
7
+
8
+ it "should have a summary" do
9
+ Pik::Help.summary.should eql("Displays help information.")
10
+ end
11
+
12
+ it "should display when no commands are given" do
13
+ cmd = `#{@cmd}`
14
+ msg = ["Usage: pik command [options]",
15
+ "To get help with a command",
16
+ " pik help (command)",
17
+ "To list all commands and descriptions:",
18
+ " pik help commands"].join("\n\n")
19
+
20
+ cmd.should include(msg)
21
+ end
22
+
23
+ it "should display all commands when 'help commands' is given " do
24
+ cmd = `#{@cmd} help commands`
25
+
26
+ cmd.should include(" help Displays help information.")
27
+ cmd.should include("For help on a particular command, use 'pik help COMMAND'")
28
+ end
29
+
30
+ end
@@ -0,0 +1,33 @@
1
+ describe Pik::List do
2
+
3
+ before do
4
+ @cmd = 'bin\\pik.bat'
5
+ Pik::Commands.clear
6
+ Pik::Commands.add(Pik::List)
7
+ #Pik::ConfigFile.stub!(:new).and_return({})
8
+ end
9
+
10
+ describe 'execute' do
11
+ it "should show config output" do
12
+ cmd = `#{@cmd} list`
13
+ cmd.should match(/186: ruby 1\.8\.6 \(2009\-03\-31 patchlevel 368\)/)
14
+ end
15
+
16
+ it "should have an alias of ls" do
17
+ Pik::List.names.should include(:ls)
18
+ end
19
+
20
+ it "should show current ruby version with an '*'" do
21
+ version = `ruby -v`.strip
22
+ cmd = `#{@cmd} list`
23
+ cmd.should match(/#{Regexp.escape(version)} \*/)
24
+ end
25
+
26
+ it "should have a verbose options" do
27
+ @ls = Pik::List.new(['-v'])
28
+ @ls.verbose.should be_true
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,25 @@
1
+ describe Pik::Remove do
2
+
3
+ it "should have a summary" do
4
+ Pik::Remove.summary.should eql("Removes a ruby location from pik.")
5
+ end
6
+
7
+ it "should have a 'quiet' option" do
8
+ cmd = Pik::Remove.new(['--quiet'])
9
+ cmd.quiet.should be_true
10
+
11
+ cmd = Pik::Remove.new(['-q'])
12
+ cmd.quiet.should be_true
13
+ end
14
+
15
+ it "should remove items from the config" do
16
+ cmd = Pik::Remove.new(['a', '-q'], {
17
+ 'a' => {:path => 'C:/ruby/bin', :gem_home => 'C:/users/rupert/.gems'},
18
+ 'b' => {:path => 'C:/Ruby19/bin'}
19
+ }
20
+ )
21
+ cmd.execute
22
+ cmd.config.should == ( {'b' => {:path => 'C:/Ruby19/bin'}} )
23
+ end
24
+
25
+ end
@@ -0,0 +1,36 @@
1
+
2
+ describe Pik::Run do
3
+ it "should have a summary" do
4
+ Pik::Run.summary.should eql("Runs command with all version of ruby that pik is aware of.")
5
+ end
6
+
7
+ it "should use a batch file to switch paths" do
8
+ cmd = Pik::Command.new([],nil)
9
+ current_version = cmd.get_version
10
+ current_path = cmd.current_ruby_bin_path
11
+ ENV['PATH']="C:\\Program Files\\Putty;#{Pathname.new(current_path).to_windows}"
12
+ cmd = Pik::Run.new(['rake -V'], {
13
+ current_version => {:path => current_path},
14
+ 'a' => {:path => 'C:/ruby/bin', :gem_home => 'C:/users/rupert/.gems'},
15
+ 'b' => {:path => 'C:/Ruby19/bin'}
16
+ }
17
+ )
18
+ cmd.execute
19
+ batch = cmd.instance_variable_get('@batch').file_data
20
+
21
+ batch[1].should eql("SET PATH=#{ENV['PATH']}")
22
+ batch[2].should eql("SET GEM_PATH=")
23
+ batch[3].should eql("SET GEM_HOME=")
24
+ batch[5].should eql("CALL rake -V\n")
25
+
26
+ batch[7].should eql("SET PATH=C:\\Program Files\\Putty;C:\\ruby\\bin;C:\\users\\rupert\\.gems\\bin")
27
+ batch[8].should eql("SET GEM_PATH=C:\\users\\rupert\\.gems")
28
+ batch[9].should eql("SET GEM_HOME=C:\\users\\rupert\\.gems")
29
+ batch[11].should eql("CALL rake -V\n")
30
+
31
+ batch[13].should eql("SET PATH=C:\\Program Files\\Putty;C:\\Ruby19\\bin")
32
+ batch[14].should eql("SET GEM_PATH=")
33
+ batch[15].should eql("SET GEM_HOME=")
34
+ batch[17].should eql("CALL rake -V\n")
35
+ end
36
+ end
@@ -0,0 +1,121 @@
1
+ require 'lib/pik/search_path'
2
+ require 'pathname'
3
+ require 'lib/pik/core_ext/pathname'
4
+
5
+ describe SearchPath do
6
+
7
+ before :each do
8
+ path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
9
+ path << 'C:\bin;'
10
+ path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
11
+ path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
12
+ path << 'C:\windows\system32;'
13
+ path << 'C:\windows\system;'
14
+ path << 'C:\Program Files\Subversion\bin;'
15
+ path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
16
+ path << 'C:\Program Files\Common Files\Lenovo;'
17
+ path << 'C:\Program Files\QuickTime\QTSystem\;'
18
+ path << 'C:\Program Files\Git\cmd;'
19
+ path << 'C:\Program Files\jEdit;'
20
+ path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
21
+ path << 'C:\ruby\186-mswin32\bin;'
22
+ path << 'C:\Program Files\Putty'
23
+ @path = SearchPath.new(path)
24
+ end
25
+
26
+ describe '#replace' do
27
+
28
+ it "should replace one element with another using a string" do
29
+ path = 'C:/ruby/191/bin'
30
+ new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
31
+ new_path << 'C:\bin;'
32
+ new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
33
+ new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
34
+ new_path << 'C:\windows\system32;'
35
+ new_path << 'C:\windows\system;'
36
+ new_path << 'C:\Program Files\Subversion\bin;'
37
+ new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
38
+ new_path << 'C:\Program Files\Common Files\Lenovo;'
39
+ new_path << 'C:\Program Files\QuickTime\QTSystem\;'
40
+ new_path << 'C:\Program Files\Git\cmd;'
41
+ new_path << 'C:\Program Files\jEdit;'
42
+ new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
43
+ new_path << 'C:\ruby\191\bin;'
44
+ new_path << 'C:\Program Files\Putty'
45
+ updated_path = @path.replace('C:/ruby/186-mswin32/bin', path).join
46
+ updated_path.should == new_path
47
+ end
48
+ end
49
+
50
+ describe '#add' do
51
+ it "should add an element to the end" do
52
+ path = 'C:/ruby/191/bin'
53
+ new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
54
+ new_path << 'C:\bin;'
55
+ new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
56
+ new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
57
+ new_path << 'C:\windows\system32;'
58
+ new_path << 'C:\windows\system;'
59
+ new_path << 'C:\Program Files\Subversion\bin;'
60
+ new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
61
+ new_path << 'C:\Program Files\Common Files\Lenovo;'
62
+ new_path << 'C:\Program Files\QuickTime\QTSystem\;'
63
+ new_path << 'C:\Program Files\Git\cmd;'
64
+ new_path << 'C:\Program Files\jEdit;'
65
+ new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
66
+ new_path << 'C:\ruby\186-mswin32\bin;'
67
+ new_path << 'C:\Program Files\Putty;'
68
+ new_path << 'C:\ruby\191\bin'
69
+ @path.add(path)
70
+ @path.join.should == new_path
71
+ end
72
+ end
73
+
74
+ describe '#replace_or_add' do
75
+
76
+ it "should replace one element with another using a string" do
77
+ path = 'C:/ruby/191/bin'
78
+ new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
79
+ new_path << 'C:\bin;'
80
+ new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
81
+ new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
82
+ new_path << 'C:\windows\system32;'
83
+ new_path << 'C:\windows\system;'
84
+ new_path << 'C:\Program Files\Subversion\bin;'
85
+ new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
86
+ new_path << 'C:\Program Files\Common Files\Lenovo;'
87
+ new_path << 'C:\Program Files\QuickTime\QTSystem\;'
88
+ new_path << 'C:\Program Files\Git\cmd;'
89
+ new_path << 'C:\Program Files\jEdit;'
90
+ new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
91
+ new_path << 'C:\ruby\191\bin;'
92
+ new_path << 'C:\Program Files\Putty'
93
+ @path.replace_or_add('C:/ruby/186-mswin32/bin', path)
94
+ @path.join.should == new_path
95
+ end
96
+
97
+ it "should add an element to the end if it doesn't already exist" do
98
+ path = 'C:/xray/yankee/zebra'
99
+ new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
100
+ new_path << 'C:\bin;'
101
+ new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
102
+ new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
103
+ new_path << 'C:\windows\system32;'
104
+ new_path << 'C:\windows\system;'
105
+ new_path << 'C:\Program Files\Subversion\bin;'
106
+ new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
107
+ new_path << 'C:\Program Files\Common Files\Lenovo;'
108
+ new_path << 'C:\Program Files\QuickTime\QTSystem\;'
109
+ new_path << 'C:\Program Files\Git\cmd;'
110
+ new_path << 'C:\Program Files\jEdit;'
111
+ new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
112
+ new_path << 'C:\ruby\186-mswin32\bin;'
113
+ new_path << 'C:\Program Files\Putty;'
114
+ new_path << 'C:\xray\yankee\zebra'
115
+ @path.replace_or_add('C:/xray/yankee/alpha', path)
116
+ @path.join.should == new_path
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --require=rubygems
3
+ --require=lib/pik
@@ -0,0 +1,44 @@
1
+ describe Pik::Switch do
2
+
3
+ it "should have a summary" do
4
+ Pik::Switch.summary.should eql("Switches ruby versions based on patterns.")
5
+ end
6
+
7
+ it "should have an alias of sw" do
8
+ Pik::Switch.names.should include(:sw)
9
+ end
10
+
11
+ it "should have an alias of use" do
12
+ Pik::Switch.names.should include(:use)
13
+ end
14
+
15
+ it "should have a global option" #do
16
+ # sw = Pik::Switch.new(['-g'])
17
+ # sw.global.should be_true
18
+ # end
19
+
20
+ it "should have a gem_home option" # do
21
+ # sw = Pik::Switch.new(['-m', 'test'])
22
+ # sw.gem_home.should eql("test")
23
+ # end
24
+
25
+ it "should use a batch file to switch paths" do
26
+ cmd = Pik::Switch.new(['spec'], {'spec' => {:path => 'C:/ruby/bin'}})
27
+ cmd.execute
28
+ batch = cmd.instance_variable_get('@batch').file_data
29
+ batch.should include("SET GEM_PATH=")
30
+ batch.should include("SET GEM_HOME=")
31
+ set_path = batch.grep(/set/i).first
32
+ set_path.should match(/SET PATH=.+C\:\\ruby\\bin.+/i)
33
+ end
34
+
35
+ it "should switch gem_home and gem_path if the config has a :gem_home" do
36
+ conf = {'spec' => {:path => 'C:/ruby/bin', :gem_home => 'C:/Users/martin_blanke/.gems'}}
37
+ cmd = Pik::Switch.new(['spec'], conf)
38
+ cmd.execute
39
+ batch = cmd.instance_variable_get('@batch').file_data
40
+ batch.should include("SET GEM_PATH=C:\\Users\\martin_blanke\\.gems")
41
+ batch.should include("SET GEM_HOME=C:\\Users\\martin_blanke\\.gems")
42
+ end
43
+
44
+ end