[rspec-devel] protocol for patching rspec-tmbundle

George Anderson george at benevolentcode.com
Tue Oct 14 12:31:57 EDT 2008


I have installed the latest rspec-tmbundle (from
git://github.com/dchelimsky/rspec-tmbundle.git).  I was getting some
funky error with the "Alternate File" command when the target file
didn't exist.  It would just display a path-related error and not
prompt me to create the missing file.

I tracked the issue down to my having a space in
ENV['TM_SUPPORT_PATH'] which caused SwitchCommand#create? to choke.
Being a decent person, I wanted to BDD the fix, but I don't know how
best to spec system calls, and the existing specs seem to not cover
the code I needed to patch.  The fix was simple enough:

diff --git a/Support/lib/spec/mate/switch_command.rb
index 22868f0..7b8f8d8 100644
--- a/Support/lib/spec/mate/switch_command.rb
+++ b/Support/lib/spec/mate/switch_command.rb
@@ -69,7 +69,7 @@ module Spec

       def create?(relative_twin, file_type)
-        answer = `#{ ENV['TM_SUPPORT_PATH']
}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog yesno-msgbox
--no-cancel --icon document --informative-text "#{relative_twin}"
--text "Create missing #{file_type}?"`
+        answer = `'#{ ENV['TM_SUPPORT_PATH']
}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog' yesno-msgbox
--no-cancel --icon document --informative-text "#{relative_twin}"
--text "Create missing #{file_type}?"`
         answer.to_s.chomp == "1"

which just wraps:

#{ ENV['TM_SUPPORT_PATH'] }/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog

in single quotes.  With this patch, the "Alternate File" command was
working as expected.

However, when it created the new file, it did so outside of the
context of my TextMate project.  So I patched
SwitchCommand#write_and_open.  Once again, I'm at a loss for creating
specs for the code I was touching and existing specs didn't cover it.
It is a very simple fix:

diff --git a/Support/lib/spec/mate/switch_command.rb
index 7b8f8d8..7ada2fa 100644
--- a/Support/lib/spec/mate/switch_command.rb
+++ b/Support/lib/spec/mate/switch_command.rb
@@ -123,8 +123,7 @@ SPEC
       def write_and_open(path, content)
         `mkdir -p "#{File.dirname(path)}"`
         `touch "#{path}"`
-        `osascript &>/dev/null -e 'tell app "SystemUIServer" to
activate' -e 'tell app "TextMate" to activate'`
-        `"$TM_SUPPORT_PATH/bin/mate" "#{path}"`
+        `osascript &>/dev/null -e 'tell app "SystemUIServer" to
activate' -e 'tell app "TextMate" to activate' -e 'tell app "TextMate"
to open #{path}'`
         escaped_content =
         `osascript &>/dev/null -e "tell app \\"TextMate\\" to insert
\\"#{escaped_content}\\" as snippet true"`

With this patch, the new file will be created within the context of
the open TextMate project.

How do I go about getting these patches accepted?  Admittedly I have
no specs to prove my changes, which poses a significant barrier to
acceptance, I assume.  Should I open a Lighthouse ticket and attach
the patches?  Can someone guide me on how to create specs for my

Any advice would be greatly appreciated.




George Anderson

BenevolentCode LLC
O: (410) 461-7553
C: (410) 218-5185

george at benevolentcode.com

More information about the rspec-devel mailing list