timocratic-utility_belt 1.0.7.1

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.
Files changed (48) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +7 -0
  3. data/README +356 -0
  4. data/bin/amazon +16 -0
  5. data/bin/google +7 -0
  6. data/bin/pastie +7 -0
  7. data/html/andreas00.css +449 -0
  8. data/html/authorship.html +86 -0
  9. data/html/bg.gif +0 -0
  10. data/html/front.jpg +0 -0
  11. data/html/index.html +81 -0
  12. data/html/menubg.gif +0 -0
  13. data/html/menubg2.gif +0 -0
  14. data/html/test.jpg +0 -0
  15. data/html/usage.html +304 -0
  16. data/lib/utility_belt/amazon_upload_shortcut.rb +25 -0
  17. data/lib/utility_belt/clipboard.rb +52 -0
  18. data/lib/utility_belt/command_history.rb +110 -0
  19. data/lib/utility_belt/convertable_to_file.rb +34 -0
  20. data/lib/utility_belt/equipper.rb +71 -0
  21. data/lib/utility_belt/google.rb +33 -0
  22. data/lib/utility_belt/hash_math.rb +13 -0
  23. data/lib/utility_belt/interactive_editor.rb +78 -0
  24. data/lib/utility_belt/irb_options.rb +3 -0
  25. data/lib/utility_belt/irb_verbosity_control.rb +30 -0
  26. data/lib/utility_belt/is_an.rb +4 -0
  27. data/lib/utility_belt/language_greps.rb +28 -0
  28. data/lib/utility_belt/not.rb +15 -0
  29. data/lib/utility_belt/pastie.rb +34 -0
  30. data/lib/utility_belt/pipe.rb +24 -0
  31. data/lib/utility_belt/rails_finder_shortcut.rb +18 -0
  32. data/lib/utility_belt/rails_verbosity_control.rb +8 -0
  33. data/lib/utility_belt/string_to_proc.rb +72 -0
  34. data/lib/utility_belt/symbol_to_proc.rb +30 -0
  35. data/lib/utility_belt/wirble.rb +83 -0
  36. data/lib/utility_belt/with.rb +21 -0
  37. data/lib/utility_belt.rb +22 -0
  38. data/spec/convertable_to_file_spec.rb +31 -0
  39. data/spec/equipper_spec.rb +70 -0
  40. data/spec/hash_math_spec.rb +17 -0
  41. data/spec/interactive_editor_spec.rb +146 -0
  42. data/spec/language_greps_spec.rb +9 -0
  43. data/spec/pastie_spec.rb +92 -0
  44. data/spec/pipe_spec.rb +30 -0
  45. data/spec/spec_helper.rb +8 -0
  46. data/spec/string_to_proc_spec.rb +41 -0
  47. data/spec/utility_belt_spec.rb +4 -0
  48. metadata +141 -0
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "spec_helper")
3
+
4
+ require 'spec'
5
+ require 'irb'
6
+ require 'delegate'
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'interactive_editor')
8
+
9
+ # Using SimpleDelegator allows us to replace the constants without triggering a
10
+ # "constant redefined" warning.
11
+ module StubPlatform
12
+ ARCH = SimpleDelegator.new(:x86)
13
+ OS = SimpleDelegator.new(:unix)
14
+ IMPL = SimpleDelegator.new(:linux)
15
+ end
16
+
17
+ # Sneak a stub Platform class into InteractiveEditor so that we don't have to
18
+ # override constants on the real Platform module
19
+ #
20
+ # P.S. This ugliness is why libraries should always prefer to expose methods
21
+ # over constants.
22
+ class InteractiveEditor
23
+ Platform = StubPlatform
24
+ end
25
+
26
+ describe InteractiveEditor, "given no clues as to what editor to use" do
27
+ before :each do
28
+ ENV.delete("VISUAL")
29
+ ENV.delete("EDITOR")
30
+ Kernel.stub!(:test).and_return(false)
31
+ File.stub!(:executable?).and_return(false)
32
+ end
33
+
34
+ it "should complain" do
35
+ lambda do
36
+ InteractiveEditor.sensible_editor
37
+ end.should raise_error
38
+ end
39
+ end
40
+
41
+ describe InteractiveEditor,
42
+ "given a Mac OS X platform and no editor environment vars" do
43
+
44
+ before :each do
45
+ ENV.delete("VISUAL")
46
+ ENV.delete("EDITOR")
47
+ @old_impl = StubPlatform::IMPL.__getobj__
48
+ StubPlatform::IMPL.__setobj__(:macosx)
49
+ end
50
+
51
+ after :each do
52
+ StubPlatform::IMPL.__setobj__(@old_impl)
53
+ end
54
+
55
+ it "should use the OS X 'open' command as the default editor" do
56
+ InteractiveEditor.sensible_editor.should == "open"
57
+ end
58
+ end
59
+
60
+ # xdg-open is a facility from the freedesktop.org, available on some recent free
61
+ # desktop operating systems (like Ubuntu). It uses the desktop environments
62
+ # filetype associations to determine what program to open a file in.
63
+ describe InteractiveEditor,
64
+ "given a Linux OS and no environment vars" do
65
+
66
+ before :each do
67
+ ENV.delete("VISUAL")
68
+ ENV.delete("EDITOR")
69
+ @old_impl = StubPlatform::IMPL.__getobj__
70
+ StubPlatform::OS.__setobj__(:linux)
71
+ File.stub!(:executable?).and_return(true)
72
+ end
73
+
74
+ after :each do
75
+ StubPlatform::IMPL.__setobj__(@old_impl)
76
+ end
77
+
78
+ it "should attempt to use 'xdg-open' command as the default editor" do
79
+ File.should_receive(:executable?).
80
+ with("/usr/bin/xdg-open").
81
+ and_return(true)
82
+ InteractiveEditor.sensible_editor.should == "/usr/bin/xdg-open"
83
+ end
84
+ end
85
+
86
+ # /usr/bin/sensible-editor is a Debian-ism AFAIK
87
+ describe InteractiveEditor,
88
+ "given the existence of /usr/bin/sensible-editor and no xdg-open" do
89
+ it "should use /usr/bin/sensible-editor as the default editor" do
90
+ File.should_receive(:executable?).
91
+ with("/usr/bin/xdg-open").
92
+ and_return(false)
93
+ File.should_receive(:executable?).
94
+ with("/usr/bin/sensible-editor").
95
+ and_return(true)
96
+ InteractiveEditor.sensible_editor.should == "/usr/bin/sensible-editor"
97
+ end
98
+ end
99
+
100
+ describe InteractiveEditor, "given an EDITOR environment variable" do
101
+ before :each do
102
+ File.stub!(:executable?).and_return(true)
103
+ ENV["EDITOR"] = "MY_EDITOR"
104
+ end
105
+
106
+ after :each do
107
+ ENV.delete("EDITOR")
108
+ end
109
+
110
+ it "should use the EDITOR environment variable to determine a sensible editor" do
111
+ InteractiveEditor.sensible_editor.should == "MY_EDITOR"
112
+ end
113
+ end
114
+
115
+ describe InteractiveEditor, "given a VISUAL environment variable" do
116
+ before :each do
117
+ File.stub!(:executable?).and_return(true)
118
+ ENV["EDITOR"] = "MY_EDITOR"
119
+ ENV["VISUAL"] = "MY_VISUAL_EDITOR"
120
+ end
121
+
122
+ after :each do
123
+ ENV.delete("EDITOR")
124
+ ENV.delete("VISUAL")
125
+ end
126
+
127
+ it "should use the environment variable to determine a sensible editor" do
128
+ InteractiveEditor.sensible_editor.should == "MY_VISUAL_EDITOR"
129
+ end
130
+ end
131
+
132
+ describe InteractiveEditing, "(calling out to an external editor)" do
133
+ before :each do
134
+ @it = Object.new
135
+ @it.extend(InteractiveEditing)
136
+ @editor = stub("Editor", :edit_interactively => nil)
137
+ @editor_path = stub("Editor Path")
138
+ InteractiveEditor.stub!(:sensible_editor).and_return(@editor_path)
139
+ InteractiveEditor.stub!(:new).and_return(@editor)
140
+ end
141
+
142
+ it "should use InteractiveEditor to determine default editor" do
143
+ @it.edit_interactively
144
+ IRB.conf[:interactive_editors][@editor_path].should equal(@editor)
145
+ end
146
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ require "lib/utility_belt/language_greps"
3
+ describe "language greps" do
4
+
5
+ it "should handle String#blank?" do
6
+ "".should be_blank
7
+ end
8
+
9
+ end
@@ -0,0 +1,92 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ require 'rubygems'
3
+ gem 'rspec'
4
+ require 'spec'
5
+ Platform = Module.new unless Object.const_defined?('Platform')
6
+ Net = Module.new unless Object.const_defined?('Net')
7
+
8
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','lib/utility_belt'))
9
+ UtilityBelt.equip(:pastie)
10
+ include UtilityBelt::Pastie
11
+ Clipboard = UtilityBelt::Clipboard unless Object.const_defined?('Clipboard')
12
+
13
+ describe "pastie being called" do
14
+
15
+ before(:all) do
16
+ Net::HTTP = mock('HTTP') unless Net.const_defined?('HTTP')
17
+ URI = mock('URI') unless Object.const_defined?('URI')
18
+ Clipboard = mock('clipboard') unless Object.const_defined?('Clipboard')
19
+ end
20
+
21
+ before(:each) do
22
+ @page = mock('page')
23
+ @page.stub!(:body).and_return('href="foo"')
24
+ Net::HTTP.stub!(:post_form).and_return(@page)
25
+ URI.stub!(:parse)
26
+ Clipboard.stub!(:read)
27
+ Clipboard.stub!(:write)
28
+ Kernel.stub!(:system)
29
+ end
30
+
31
+ it "should be available in global namespace and not blow-up with default stub/mocking" do
32
+ pastie
33
+ end
34
+
35
+ it "should uri-parse the pastie uri" do
36
+ URI.should_receive(:parse).with("http://pastie.caboo.se/pastes/create")
37
+ pastie
38
+ end
39
+
40
+ it "should pass the uri-parsed result into the post" do
41
+ URI.should_receive(:parse).and_return('a_uri_object')
42
+ Net::HTTP.should_receive(:post_form).with('a_uri_object', anything()).and_return(@page)
43
+ pastie
44
+ end
45
+
46
+ it "should call system open on the pastie return" do
47
+ @page.should_receive(:body).and_return('href="returned_url"')
48
+ case Platform::IMPL
49
+ when :macosx
50
+ Kernel.should_receive(:system).with("open returned_url")
51
+ when :mswin
52
+ Kernel.should_receive(:system).with("start returned_url")
53
+ end
54
+ pastie
55
+ end
56
+
57
+ it "should write resulting url into the clipboard" do
58
+ @page.should_receive(:body).and_return('href="returned_url"')
59
+ Clipboard.should_receive(:write).with('returned_url')
60
+ pastie
61
+ end
62
+
63
+ describe "with no parameter it uses the clipboard" do
64
+ it "should read the clipboard" do
65
+ Clipboard.should_receive(:read)
66
+ pastie
67
+ end
68
+
69
+ it "should put the clipboard results in the post to pastie" do
70
+ Clipboard.should_receive(:read).and_return('bar')
71
+ Net::HTTP.should_receive(:post_form).with(anything(),{"paste_parser" => "ruby",
72
+ "paste[authorization]" => "burger",
73
+ "paste[body]" => 'bar'}).and_return(@page)
74
+ pastie
75
+ end
76
+ end
77
+
78
+ describe "with a parameter instead" do
79
+ #TODO: windows/linux safer now, since no clipboard functionality?
80
+ it "should not even read the clipboard" do
81
+ Clipboard.should_not_receive(:read)
82
+ pastie "baz"
83
+ end
84
+
85
+ it "should pass in the parameter instead" do
86
+ Net::HTTP.should_receive(:post_form).with(anything(),{"paste_parser" => "ruby",
87
+ "paste[authorization]" => "burger",
88
+ "paste[body]" => 'baz'}).and_return(@page)
89
+ pastie "baz"
90
+ end
91
+ end
92
+ end
data/spec/pipe_spec.rb ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "spec_helper")
3
+
4
+ require 'spec'
5
+ require 'irb'
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'pipe')
7
+
8
+ describe "String#|" do
9
+ before :each do
10
+ @pipe = stub(:pipe, :write => nil, :close_write => nil, :read => nil)
11
+ IO.stub!(:popen).and_yield(@pipe).and_return("RESULT")
12
+ end
13
+
14
+ it "should open a pipe" do
15
+ IO.should_receive(:popen).with("COMMAND", 'r+').and_return(@pipe)
16
+ "foo" | "COMMAND"
17
+ end
18
+
19
+ it "should write itself to the the pipe, close it, then read from it" do
20
+ @pipe.should_receive(:write).with("foo").ordered
21
+ @pipe.should_receive(:close_write).ordered
22
+ @pipe.should_receive(:read)
23
+
24
+ "foo" | "COMMAND"
25
+ end
26
+
27
+ it "should return the result of the IO.popen block" do
28
+ ("foo" | "COMMAND").should == "RESULT"
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ # Make sure Rubygems' mangling of the path is already done before we do our own
2
+ # mangling.
3
+ require 'rubygems'
4
+
5
+ # Ensure that when we require UtilityBelt libs they are from the files under
6
+ # test, NOT from the installed gem.
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), ".."))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ require "lib/utility_belt/string_to_proc"
3
+ describe "String to Proc" do
4
+
5
+ before(:all) do
6
+ @one2five = 1..5
7
+ end
8
+
9
+ it "should handle simple arrow notation" do
10
+ @one2five.map(&'x -> x + 1').should eql(@one2five.map { |x| x + 1 })
11
+ @one2five.map(&'x -> x*x').should eql(@one2five.map { |x| x*x })
12
+ @one2five.inject(&'x y -> x*y').should eql(@one2five.inject { |x,y| x*y })
13
+ 'x y -> x**y'.to_proc()[2,3].should eql(lambda { |x,y| x**y }[2,3])
14
+ 'y x -> x**y'.to_proc()[2,3].should eql(lambda { |y,x| x**y }[2,3])
15
+ end
16
+
17
+ it "should handle chained arrows" do
18
+ 'x -> y -> x**y'.to_proc()[2][3].should eql(lambda { |x| lambda { |y| x**y } }[2][3])
19
+ 'x -> y z -> y**(z-x)'.to_proc()[1][2,3].should eql(lambda { |x| lambda { |y,z| y**(z-x) } }[1][2,3])
20
+ end
21
+
22
+ it "should handle the default parameter" do
23
+ @one2five.map(&'2**_/2').should eql(@one2five.map { |x| 2**x/2 })
24
+ @one2five.select(&'_%2==0').should eql(@one2five.select { |x| x%2==0 })
25
+ end
26
+
27
+ it "should handle point-free notation" do
28
+ @one2five.inject(&'*').should eql(@one2five.inject { |mem, var| mem * var })
29
+ @one2five.select(&'>2').should eql(@one2five.select { |x| x>2 })
30
+ @one2five.select(&'2<').should eql(@one2five.select { |x| 2<x })
31
+ @one2five.map(&'2*').should eql(@one2five.map { |x| 2*x })
32
+ (-3..3).map(&'.abs').should eql((-3..3).map { |x| x.abs })
33
+ end
34
+
35
+ it "should handle implied parameters as best it can" do
36
+ @one2five.inject(&'x*y').should eql(@one2five.inject(&'*'))
37
+ 'x**y'.to_proc()[2,3].should eql(8)
38
+ 'y**x'.to_proc()[2,3].should eql(8)
39
+ end
40
+
41
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ # yeah, I know. I know! but you try to write specs for code which launches vi. most of this was
3
+ # already written by the time I started tasting the BDD Kool-Aid. HOWEVER! any new patches are
4
+ # very welcome, but MUST be accompanied by a spec or an absolutely airtight reason why not.
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timocratic-utility_belt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7.1
5
+ platform: ruby
6
+ authors:
7
+ - Giles Bowkett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-15 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: wirble
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.1.2
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: aws-s3
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.0
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: Platform
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.4.0
50
+ version:
51
+ description:
52
+ email: gilesb@gmail.com
53
+ executables:
54
+ - amazon
55
+ - google
56
+ - pastie
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - README
61
+ files:
62
+ - bin
63
+ - bin/amazon
64
+ - bin/google
65
+ - bin/pastie
66
+ - History.txt
67
+ - html
68
+ - html/andreas00.css
69
+ - html/authorship.html
70
+ - html/bg.gif
71
+ - html/front.jpg
72
+ - html/index.html
73
+ - html/menubg.gif
74
+ - html/menubg2.gif
75
+ - html/test.jpg
76
+ - html/usage.html
77
+ - lib
78
+ - lib/utility_belt
79
+ - lib/utility_belt/amazon_upload_shortcut.rb
80
+ - lib/utility_belt/clipboard.rb
81
+ - lib/utility_belt/command_history.rb
82
+ - lib/utility_belt/convertable_to_file.rb
83
+ - lib/utility_belt/equipper.rb
84
+ - lib/utility_belt/google.rb
85
+ - lib/utility_belt/hash_math.rb
86
+ - lib/utility_belt/interactive_editor.rb
87
+ - lib/utility_belt/irb_options.rb
88
+ - lib/utility_belt/irb_verbosity_control.rb
89
+ - lib/utility_belt/is_an.rb
90
+ - lib/utility_belt/language_greps.rb
91
+ - lib/utility_belt/not.rb
92
+ - lib/utility_belt/pastie.rb
93
+ - lib/utility_belt/pipe.rb
94
+ - lib/utility_belt/rails_finder_shortcut.rb
95
+ - lib/utility_belt/rails_verbosity_control.rb
96
+ - lib/utility_belt/string_to_proc.rb
97
+ - lib/utility_belt/symbol_to_proc.rb
98
+ - lib/utility_belt/wirble.rb
99
+ - lib/utility_belt/with.rb
100
+ - lib/utility_belt.rb
101
+ - Manifest.txt
102
+ - README
103
+ - spec
104
+ - spec/convertable_to_file_spec.rb
105
+ - spec/equipper_spec.rb
106
+ - spec/hash_math_spec.rb
107
+ - spec/interactive_editor_spec.rb
108
+ - spec/language_greps_spec.rb
109
+ - spec/pastie_spec.rb
110
+ - spec/pipe_spec.rb
111
+ - spec/spec_helper.rb
112
+ - spec/string_to_proc_spec.rb
113
+ - spec/utility_belt_spec.rb
114
+ has_rdoc: true
115
+ homepage: http://utilitybelt.rubyforge.org
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: "0"
126
+ version:
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: "0"
132
+ version:
133
+ requirements: []
134
+
135
+ rubyforge_project: utility_belt
136
+ rubygems_version: 1.2.0
137
+ signing_key:
138
+ specification_version: 2
139
+ summary: A grab-bag of IRB power user madness.
140
+ test_files:
141
+ - spec/utility_belt_spec.rb