<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -86,11 +86,37 @@ module Spec
         case file_type
           when /spec$/ then
             spec(relative_path)
+          when &quot;controller&quot;
+            &lt;&lt;-CONTROLLER
+class #{class_from_path(relative_path)} &lt; ApplicationController
+end
+CONTROLLER
+          when &quot;model&quot;
+            &lt;&lt;-MODEL
+class #{class_from_path(relative_path)} &lt; ActiveRecord::Base
+end
+MODEL
+          when &quot;helper&quot;
+            &lt;&lt;-HELPER
+module #{class_from_path(relative_path)}
+end
+HELPER
+          when &quot;view&quot;
+            &quot;&quot;
           else
             klass(relative_path)
         end
       end
       
+      def class_from_path(path)
+        underscored = path.split('/').last.split('.rb').first
+        parts = underscored.split('_')
+        parts.inject(&quot;&quot;) do |word, part|
+          word &lt;&lt; part.capitalize
+          word
+        end
+      end
+      
       # Extracts the snippet text
       def snippet(snippet_name)
         snippet_file = File.expand_path(File.dirname(__FILE__) + &quot;/../../../../Snippets/#{snippet_name}&quot;)
@@ -99,19 +125,16 @@ module Spec
       end
       
       def spec(path)
-        depth = &quot;/..&quot; * (path.split('/').length - 2)
-        header = &quot;require File.dirname(__FILE__) + '#{depth}/spec_helper'&quot;
-        snippet_name = &quot;Describe_type.tmSnippet&quot;
         content = &lt;&lt;-SPEC
-#{header}
+require 'spec_helper'
 
-#{snippet(snippet_name)}
+#{snippet(&quot;Describe_type.tmSnippet&quot;)}
 SPEC
       end
 
-      def klass(relative_path)
+      def klass(relative_path, content=nil)
         parts = relative_path.split('/')
-        lib_index = parts.index('lib')
+        lib_index = parts.index('lib') || 0
         parts = parts[lib_index+1..-1]
         lines = Array.new(parts.length*2)
         parts.each_with_index do |part, n|
@@ -132,8 +155,8 @@ SPEC
       def write_and_open(path, content)
         `mkdir -p &quot;#{File.dirname(path)}&quot;`
         `touch &quot;#{path}&quot;`
-        `osascript &amp;&gt;/dev/null -e 'tell app &quot;SystemUIServer&quot; to activate' -e 'tell app &quot;TextMate&quot; to activate'`
         `&quot;$TM_SUPPORT_PATH/bin/mate&quot; &quot;#{path}&quot;`
+        `osascript &amp;&gt;/dev/null -e 'tell app &quot;SystemUIServer&quot; to activate' -e 'tell app &quot;TextMate&quot; to activate'`
         escaped_content = content.gsub(&quot;\n&quot;,&quot;\\n&quot;).gsub('$','\\$').gsub('&quot;','\\\\\\\\\\\\&quot;')
         `osascript &amp;&gt;/dev/null -e &quot;tell app \\&quot;TextMate\\&quot; to insert \\&quot;#{escaped_content}\\&quot; as snippet true&quot;`      
       end</diff>
      <filename>Support/lib/spec/mate/switch_command.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,15 +23,13 @@ module Spec
           end
         end
       end
-
-      def be_a(expected)
-        simple_matcher do |actual, matcher|
-          matcher.failure_message = &quot;expected #{actual.inspect} to be_a #{expected.inspect}, but it didn't&quot;
-          matcher.negative_failure_message = &quot;expected #{actual.inspect} not to be_a #{expected.inspect}, but it did&quot;
+      
+      Spec::Matchers.define :be_a do |expected|
+        match do |actual|
           SwitchCommand.new.file_type(actual) == expected
         end
       end
-    
+
       describe &quot;in a regular app&quot; do
         expect_twins [
           &quot;/Users/aslakhellesoy/scm/rspec/trunk/RSpec.tmbundle/Support/spec/spec/mate/switch_command_spec.rb&quot;,
@@ -48,7 +46,7 @@ module Spec
       
         it &quot;should create spec for spec files&quot; do
           regular_spec = &lt;&lt;-SPEC
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
 
 describe ${1:Type} do
   $0
@@ -196,7 +194,32 @@ EOF
 
         it &quot;should create spec that requires a helper&quot; do
           SwitchCommand.new.content_for('controller spec', &quot;spec/controllers/mooky_controller_spec.rb&quot;).split(&quot;\n&quot;)[0].should == 
-            &quot;require File.dirname(__FILE__) + '/../spec_helper'&quot;
+            &quot;require 'spec_helper'&quot;
+        end
+        
+        it &quot;creates a controller if twinned from a controller spec&quot; do
+          SwitchCommand.new.content_for('controller', &quot;spec/controllers/mooky_controller.rb&quot;).should == &lt;&lt;-EXPECTED
+class MookyController &lt; ApplicationController
+end
+EXPECTED
+        end
+        
+        it &quot;creates a model if twinned from a model spec&quot; do
+          SwitchCommand.new.content_for('model', &quot;spec/models/mooky.rb&quot;).should == &lt;&lt;-EXPECTED
+class Mooky &lt; ActiveRecord::Base
+end
+EXPECTED
+        end
+        
+        it &quot;creates a helper if twinned from a helper spec&quot; do
+          SwitchCommand.new.content_for('helper', &quot;spec/helpers/mooky_helper.rb&quot;).should == &lt;&lt;-EXPECTED
+module MookyHelper
+end
+EXPECTED
+        end
+        
+        it &quot;creates an empty view if twinned from a view spec&quot; do
+          SwitchCommand.new.content_for('view', &quot;spec/views/mookies/index.html.erb_spec.rb&quot;).should == &quot;&quot;
         end
       end
     end</diff>
      <filename>Support/spec/spec/mate/switch_command_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6ba765132149ed121099e3d8eff7292fa2d7b4ca</id>
    </parent>
    <parent>
      <id>b93a56c1f6b56c71e744d117e35c71552fddd172</id>
    </parent>
  </parents>
  <author>
    <name>Carlos Brando</name>
    <email>eduardobrando@gmail.com</email>
  </author>
  <url>http://github.com/carlosbrando/rspec-tmbundle/commit/8c6367a52a50dec4bcd5be9db69085e282d45334</url>
  <id>8c6367a52a50dec4bcd5be9db69085e282d45334</id>
  <committed-date>2009-09-30T05:54:33-07:00</committed-date>
  <authored-date>2009-09-30T05:54:33-07:00</authored-date>
  <message>Merge branch 'master' of git://github.com/dchelimsky/rspec-tmbundle into dchelimsky/master</message>
  <tree>e7b41a0a7b874051dda823c30290b6e73fe85fde</tree>
  <committer>
    <name>Carlos Brando</name>
    <email>eduardobrando@gmail.com</email>
  </committer>
</commit>
