Skip to content
Browse files

When saving a _spec.rb example file, it is remembered, and 'Run last …

…example file' command (Alt+Cmd+R) in any normal Ruby file will execute it like the other 'Run examples' commands
  • Loading branch information...
1 parent a02391e commit a8a1ad3ea0c4bcfc82424f09debdb7a0620ed57f @drnic drnic committed with dchelimsky Nov 8, 2008
View
32 Commands/Run Last Examples file.tmCommand
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>saveActiveFile</string>
+ <key>command</key>
+ <string>#!/usr/bin/env sh
+cat &lt;&lt;'RUBYEOF' &gt; /tmp/textmate-command-$$.rb
+
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
+Spec::Mate::Runner.new.run_last_remembered_file STDOUT
+
+RUBYEOF
+
+${TM_RUBY:-ruby} /tmp/textmate-command-$$.rb; exit_status=$?; rm /tmp/textmate-command-$$.rb; exit $exit_status</string>
+ <key>fallbackInput</key>
+ <string>document</string>
+ <key>input</key>
+ <string>none</string>
+ <key>keyEquivalent</key>
+ <string>~@r</string>
+ <key>name</key>
+ <string>Run Last Examples file</string>
+ <key>output</key>
+ <string>showAsHTML</string>
+ <key>scope</key>
+ <string>source.ruby</string>
+ <key>uuid</key>
+ <string>1C172C2C-8785-40FC-B03E-7FF56AC0B265</string>
+</dict>
+</plist>
View
29 Commands/Save spec and remember.tmCommand
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>saveActiveFile</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
+
+# Remembers the last _spec.rb file so that 'Run last spec' command
+# can be activated from any Ruby source file
+
+Spec::Mate::Runner.new.save_as_last_remembered_file ENV['TM_FILEPATH']
+</string>
+ <key>input</key>
+ <string>none</string>
+ <key>keyEquivalent</key>
+ <string>@s</string>
+ <key>name</key>
+ <string>Save Example file and remember</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>scope</key>
+ <string>source.ruby.rspec</string>
+ <key>uuid</key>
+ <string>AC7FD3DD-A904-4B5B-8B02-4D6F04CD8ED4</string>
+</dict>
+</plist>
View
20 Support/lib/spec/mate/runner.rb
@@ -13,6 +13,11 @@ def run_file(stdout, options={})
options.merge!({:files => [single_file]})
run(stdout, options)
end
+
+ def run_last_remembered_file(stdout, options={})
+ options.merge!({:files => [last_remembered_single_file]})
+ run(stdout, options)
+ end
def run_focussed(stdout, options={})
options.merge!({:files => [single_file], :line => ENV['TM_LINE_NUMBER']})
@@ -32,12 +37,27 @@ def run(stdout, options)
::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(argv, STDERR, stdout))
end
end
+
+ def save_as_last_remembered_file(file)
+ File.open(last_remembered_file_cache, "w") do |f|
+ f << file
+ end
+ end
+ def last_remembered_file_cache
+ "/tmp/textmate_rspec_last_remembered_file_cache.txt"
+ end
+
protected
def single_file
File.expand_path(ENV['TM_FILEPATH'])
end
+ def last_remembered_single_file
+ file = File.read(last_remembered_file_cache).strip
+ File.expand_path(file) if file.size > 0
+ end
+
def project_directory
File.expand_path(ENV['TM_PROJECT_DIRECTORY'])
end
View
13 Support/spec/spec/mate/runner_spec.rb
@@ -57,6 +57,19 @@
end
end
+describe "Spec::Mate::Runner#run_last_remembered_file" do
+ include RunnerSpecHelper
+
+ it "should run all selected files" do
+ @spec_mate.save_as_last_remembered_file "#{@fixtures_path}/example_failing_spec.rb"
+ @spec_mate.run_last_remembered_file(@test_runner_io)
+ @test_runner_io.rewind
+ html = @test_runner_io.read
+
+ html.should =~ @first_failing_spec
+ end
+end
+
describe "Spec::Mate::Runner#run_focused" do
include RunnerSpecHelper
View
4 info.plist
@@ -276,8 +276,12 @@
<string>E79DAF3F-8960-47C1-A34C-3D0E4B0AF926</string>
<string>96F0A193-32F1-4A75-9093-5D20E36593EC</string>
<string>647C94D6-42FE-40F0-8618-73F7725BF59E</string>
+ <string>73A67D49-CA5B-4B8A-9B62-003506276CDD</string>
+ <string>FCB3248F-0AFD-4CB5-BF4F-1B7CDB807981</string>
+ <string>AC7FD3DD-A904-4B5B-8B02-4D6F04CD8ED4</string>
<string>240FDD9D-CD49-4917-9003-80A3E1DADFBA</string>
<string>B5906021-8E54-4863-A13B-EA46333DB5F1</string>
+ <string>1C172C2C-8785-40FC-B03E-7FF56AC0B265</string>
<string>67E726E0-63E2-4840-B8BB-37F665CD34B8</string>
<string>0C96C910-0A83-4AFE-AEF7-1F4882A00232</string>
<string>923F0A10-96B9-4792-99A4-94FEF66E0B8C</string>

0 comments on commit a8a1ad3

Please sign in to comment.
Something went wrong with that request. Please try again.