Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change top-level namespace to RSpec and add some options

  • Loading branch information...
commit 4f47a9e307293f03f0f6e4f7431754d729a9688f 1 parent 3ac97c5
@dchelimsky dchelimsky authored
View
4 Commands/Alternate File.tmCommand
@@ -11,8 +11,8 @@
cat <<'RUBYEOF' > /tmp/textmate-command-$$.rb
-require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate/switch_command"
-Spec::Mate::SwitchCommand.new.go_to_twin(ENV['TM_PROJECT_DIRECTORY'], ENV['TM_FILEPATH'])
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/rspec/mate/switch_command"
+RSpec::Mate::SwitchCommand.new.go_to_twin(ENV['TM_PROJECT_DIRECTORY'], ENV['TM_FILEPATH'])
RUBYEOF
View
4 Commands/Run Focussed Specification.tmCommand
@@ -11,8 +11,8 @@
cat <<'RUBYEOF' > /tmp/textmate-command-$$.rb
-require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
-Spec::Mate::Runner.new.run_focussed STDOUT
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/rspec/mate"
+RSpec::Mate::Runner.new.run_focussed STDOUT
RUBYEOF
View
4 Commands/Run Last Examples file.tmCommand
@@ -11,8 +11,8 @@
cat <<'RUBYEOF' > /tmp/textmate-command-$$.rb
-require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
-Spec::Mate::Runner.new.run_last_remembered_file STDOUT
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/rspec/mate"
+RSpec::Mate::Runner.new.run_last_remembered_file STDOUT
RUBYEOF
View
4 Commands/Run Specifications - Normal.tmCommand
@@ -11,8 +11,8 @@
cat <<'RUBYEOF' > /tmp/textmate-command-$$.rb
-require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
-Spec::Mate::Runner.new.run_file STDOUT
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/rspec/mate"
+RSpec::Mate::Runner.new.run_file STDOUT
RUBYEOF
View
4 Commands/Run Specifications in selected files or directories.tmCommand
@@ -11,8 +11,8 @@
cat <<'RUBYEOF' > /tmp/textmate-command-$$.rb
-require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
-Spec::Mate::Runner.new.run_files STDOUT
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/rspec/mate"
+RSpec::Mate::Runner.new.run_files STDOUT
RUBYEOF
View
4 Commands/Save spec and remember.tmCommand
@@ -11,11 +11,11 @@
cat <<'RUBYEOF' > /tmp/textmate-command-$$.rb
-require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate"
+require ENV['TM_BUNDLE_SUPPORT'] + "/lib/rspec/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']
+RSpec::Mate::Runner.new.save_as_last_remembered_file ENV['TM_FILEPATH']
RUBYEOF
View
72 README.markdown
@@ -1,32 +1,64 @@
# RSpec TextMate Bundle
-## TextMate Bundle for RSpec-1 and RSpec-2
-
-This TMBundle works with both rspec-1 and rspec-2. Given that they work
-differently, the TMBundle tries its best to figure out which one you're using
-in each project.
-
-If you're using Bundler in your project, the TMBundle will always do the right
-thing based on the version of RSpec specified in your Gemfile.
-
-If you're not using Bundler, the TMBundle tries to do the right thing based the
-presence of assorted files and paths in your project. Obviously, everybody's
-environment is going to be a bit different, so let us know if this doesn't work
-for you by filing an issue at
-[http://github.com/rspec/rspec-tmbundle](http://github.com/rspec/rspec-tmbundle)
-and we'll do our best to resolve the situation.
-
## Installation
cd ~/Library/Application\ Support/TextMate/Bundles/
git clone git://github.com/rspec/rspec-tmbundle.git RSpec.tmbundle
osascript -e 'tell app "TextMate" to reload bundles'
-## Configuration
+## Support for both RSpec-1 and RSpec-2
+
+This RSpec.tmbundle works with both rspec-1 and rspec-2. Given that they work
+differently, the RSpec.tmbundle tries its best to figure out which one you're
+using in each project when you try to run RSpec examples. There are two
+separate parts to this process, and you have some control over how each one
+works.
+
+### Load Path
+
+The first thing that happens is that the RSpec.tmbundle prepares the Load Path
+as follows:
+
+If a Gemfile is present, it assumes you want to use Bundler to prepare the Load Path,
+so it requires 'bundler' and runs `Bundler.setup` (this can be overridden - see below).
+
+If not using Bundler, then it looks to see if rspec is in vendor/plugins or vendor/gems,
+in which cases it adds its lib directory to the Load Path.
+
+### RSpec-version
+
+Once the Load Path is prepared, the bundle tries to determine which version of
+RSpec to invoke as follows:
+
+First, it looks for a ./rspec-tm file in the project root directory. If this
+is present, it looks to see if it contains a setting for the RSpec version. To
+use this, just add `.rspec-tm` to the project root with:
+
+ --rspec-version 2.0.0
+
+or which ever version you are using. This is the one fool proof way to ensure
+that the right version is invoked, but you don't really need to do this in most
+cases.
+
+If the version is not configured, it then checks to see if rspec was found in
+vendor/gems or vendor/plugins. If so, it figures out which version to invoke
+based on files present in that rspec directory.
+
+If no version is configured, and no rspec directory is found in vendor, then
+it just tries to require 'rspec/core' (for RSpec-2) and then 'spec/autorun' (for
+RSpec-1).
+
+### Which approach should I use?
+
+The effectiveness of each approach is dependent, in part, upon how you manage
+your gem environment. The simplest approach to choosing is to first see if it
+just works, and if not, then configure the version you want in the .rspec-tm file.
+
+## Rubygems
-The RSpec TextMate bundle does not `require "rubygems"` so that users who choose
-other packaging mechanisms can still use it. If you _are_ using Rubygems as your package
-manager, then the simplest thing to do is
+The RSpec TextMate bundle does not `require "rubygems"` so that users who
+choose other packaging mechanisms can still use it. If you _are_ using Rubygems
+as your package manager, then the simplest thing to do is
* open up TextMate Preferences
* go to the Advanced tab
View
2  Snippets/Matcher (DSL).tmSnippet
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>content</key>
- <string>Spec::Matchers.define :${1:name} do |${2:expected}|
+ <string>RSpec::Matchers.define :${1:name} do |${2:expected}|
match do |${3:actual}|
$3.$1?($2)
end
View
2  Snippets/configure.tmSnippet
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>content</key>
- <string>Spec::Runner.configure do |config|
+ <string>RSpec.configure do |config|
config.$0
end</string>
<key>name</key>
View
2  Snippets/mock_with.tmSnippet
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>content</key>
- <string>Spec::Runner.configure do |config|
+ <string>RSpec::Runner.configure do |config|
config.mock_with :${0:mocha|flexmock|rr}
end</string>
<key>name</key>
View
4 Support/Guardfile
@@ -3,6 +3,6 @@
guard 'rspec', :version => 2 do
watch('^spec/(.*)_spec.rb')
- watch('^lib/(.*)\.rb') { |m| "spec/lib/#{m[1]}_spec.rb" }
- watch('^spec/spec_helper.rb') { "spec" }
+ watch('^lib/(.*)\.rb') { "spec" }
+ watch('^spec/spec_helper.rb') { "spec" }
end
View
12 Support/Rakefile
@@ -1,12 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../../example_rails_app/vendor/plugins/rspec/lib')
-require 'rubygems'
-require 'spec/rake/spectask'
-
-task :default => :spec
-
-desc "Run all specs"
-Spec::Rake::SpecTask.new do |t|
- t.rcov = true
- t.spec_opts = ['--colour', '--diff']
- t.rcov_opts = ['--exclude', 'rspec\/plugins,rspec\/lib\/spec,spec\/spec,fixtures,bin\/spec']
-end
View
50 Support/lib/rspec/mate.rb
@@ -0,0 +1,50 @@
+# This is based on Florian Weber's TDDMate
+
+ENV['TM_PROJECT_DIRECTORY'] ||= File.dirname(ENV['TM_FILEPATH'])
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/..')
+require 'rspec/mate/runner'
+require 'rspec/mate/options'
+require 'rspec/mate/switch_command'
+
+rspec_lib = nil
+
+def gemfile?
+ File.exist?(File.join(ENV['TM_PROJECT_DIRECTORY'], 'Gemfile'))
+end
+
+if RSpec::Mate::Options['--bundler'] || (gemfile? && !RSpec::Mate::Options['--skip-bundler'])
+ require "rubygems"
+ require "bundler"
+ Bundler.setup
+else
+ candidate_rspec_lib_paths = Dir.glob(File.join(ENV['TM_PROJECT_DIRECTORY'],'vendor','{plugins,gems}','{rspec,rspec-core}{,-[0-9]*}', 'lib'))
+ candidate_rspec_lib_paths << File.join(ENV['TM_RSPEC_HOME'], 'lib') if ENV['TM_RSPEC_HOME']
+ rspec_lib = candidate_rspec_lib_paths.detect { |dir| File.exist?(dir) }
+
+ $LOAD_PATH.unshift(rspec_lib) if rspec_lib
+end
+
+if RSpec::Mate::Options['--rspec-version']
+ if RSpec::Mate::Options['--rspec-version'] =~ /^2/
+ require 'rspec/core'
+ else
+ require 'spec/autorun'
+ end
+elsif rspec_lib
+ if File.exist?(File.join(rspec_lib, 'rspec', 'core.rb'))
+ require 'rspec/core'
+ else
+ require 'spec/autorun'
+ end
+else
+ begin
+ require 'rspec/core'
+ rescue LoadError
+ require 'spec/autorun'
+ end
+end
+
+def rspec2?
+ defined?(RSpec::Core)
+end
+
View
46 Support/lib/rspec/mate/options.rb
@@ -0,0 +1,46 @@
+module RSpec
+ module Mate
+ module Options
+ def options
+ @options ||= begin
+ options = {}
+ rspec_tm_opts = File.join(ENV['TM_PROJECT_DIRECTORY'], '.rspec-tm')
+ if File.exist?(rspec_tm_opts)
+ raw_options = File.readlines(rspec_tm_opts).join(" ").split(/\s+/)
+ current_key = nil
+ raw_options.each do |opt|
+ if opt =~ /^-/
+ current_key = opt
+ options[current_key] = true
+ else
+ options[current_key] = transform(opt)
+ end
+ end
+ end
+ options
+ end
+ end
+
+ def []=(k,v)
+ options[k] = v
+ end
+
+ def [](k)
+ options[k]
+ end
+
+ def transform(val)
+ case val.downcase
+ when 'yes','true','on'
+ true
+ when 'no','false','off'
+ false
+ else
+ val
+ end
+ end
+
+ module_function :options, :[], :[]=, :transform
+ end
+ end
+end
View
2  Support/lib/spec/mate/runner.rb → Support/lib/rspec/mate/runner.rb
@@ -1,4 +1,4 @@
-module Spec
+module RSpec
module Mate
class Runner
def run_files(stdout, options={})
View
2  Support/lib/spec/mate/switch_command.rb → Support/lib/rspec/mate/switch_command.rb
@@ -1,4 +1,4 @@
-module Spec
+module RSpec
module Mate
# This is based on Ruy Asan's initial code:
# http://ruy.ca/posts/6-A-simple-switch-between-source-and-spec-file-command-for-textmate-with-auto-creation-
View
40 Support/lib/spec/mate.rb
@@ -1,40 +0,0 @@
-# This is based on Florian Weber's TDDMate
-
-ENV['TM_PROJECT_DIRECTORY'] ||= File.dirname(ENV['TM_FILEPATH'])
-
-def has_spec_autorun?(directory)
- File.exists?(File.join(directory, %w(spec autorun.rb)))
-end
-
-# Load spec/autorun
-if File.exist?(File.join(ENV['TM_PROJECT_DIRECTORY'], 'Gemfile'))
- require "rubygems"
- require "bundler"
- Bundler.setup
-else
- # Find it the old-fashioned way: in vendor/plugins, or in vendor/gems,
- # or at TM_RSPEC_HOME
- rspec_locs = Dir.glob(File.join(ENV['TM_PROJECT_DIRECTORY'],'vendor','{plugins,gems}','rspec{,-[0-9]*}', 'lib'))
- rspec_locs << File.join(ENV['TM_RSPEC_HOME'], 'lib') if ENV['TM_RSPEC_HOME']
- rspec_root = rspec_locs.reject { |dir| !has_spec_autorun?(dir) }.first
-
- if rspec_root
- $LOAD_PATH.unshift(rspec_root)
- elsif ENV['TM_RSPEC_HOME']
- raise "TM_RSPEC_HOME points to a bad location: #{ENV['TM_RSPEC_HOME']}" unless File.directory?(File.join(ENV['TM_RSPEC_HOME'], 'lib'))
- end
-end
-
-begin
- require 'rspec/core'
-rescue LoadError
- require 'spec/autorun'
-end
-
-def rspec2?
- defined?(RSpec)
-end
-
-$LOAD_PATH.unshift(File.dirname(__FILE__) + '/..')
-require 'spec/mate/runner'
-require 'spec/mate/switch_command'
View
37 Support/spec/rspec/mate/options_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe RSpec::Mate::Options do
+ let(:options) do
+ Class.new do
+ include RSpec::Mate::Options
+ end.new.send :options
+ end
+
+ def stub_file_with(lines)
+ File.stub(:exist?) { true }
+ File.stub(:readlines) { lines }
+ end
+
+ context "with no file" do
+ it "is empty" do
+ File.stub(:exist?) { false }
+ options.should be_empty
+ end
+ end
+
+ context "with a file" do
+ context "with --rspec-version" do
+ it "contains the rspec version" do
+ stub_file_with ['--rspec-version 1.3.1']
+ options['--rspec-version'].should eq('1.3.1')
+ end
+ end
+
+ context "with --bundler" do
+ it "contains bundler true" do
+ stub_file_with ['--bundler']
+ options['--bundler'].should be_true
+ end
+ end
+ end
+end
View
11 Support/spec/spec/mate/runner_spec.rb → Support/spec/rspec/mate/runner_spec.rb
@@ -1,8 +1,7 @@
require 'spec_helper'
-require File.expand_path('../../../../lib/spec/mate/runner', __FILE__)
require 'stringio'
-describe Spec::Mate::Runner do
+describe RSpec::Mate::Runner do
def set_env
root = File.expand_path('../../../../../../rspec-core', __FILE__)
ENV['TM_RSPEC_HOME'] = "#{root}"
@@ -18,8 +17,8 @@ def set_env
set_env
- load File.expand_path("#{File.dirname(__FILE__)}/../../../lib/spec/mate.rb")
- @spec_mate = Spec::Mate::Runner.new
+ load File.expand_path("#{File.dirname(__FILE__)}/../../../lib/rspec/mate.rb")
+ @spec_mate = RSpec::Mate::Runner.new
@test_runner_io = StringIO.new
end
@@ -100,14 +99,14 @@ def set_env
it "should raise exception when TM_PROJECT_DIRECTORY points to bad location" do
ENV['TM_PROJECT_DIRECTORY'] = __FILE__ # bad on purpose
lambda do
- load File.dirname(__FILE__) + '/../../../lib/spec/mate.rb'
+ load File.dirname(__FILE__) + '/../../../lib/rspec/mate.rb'
end.should_not raise_error
end
it "should raise exception when TM_RSPEC_HOME points to bad location" do
ENV['TM_RSPEC_HOME'] = __FILE__ # bad on purpose
lambda do
- load File.dirname(__FILE__) + '/../lib/spec_mate.rb'
+ load File.dirname(__FILE__) + '/../lib/rspec_mate.rb'
end.should raise_error
end
end
View
7 Support/spec/spec/mate/switch_command_spec.rb → Support/spec/rspec/mate/switch_command_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
-require File.dirname(__FILE__) + '/../../../lib/spec/mate/switch_command'
-module Spec
+module RSpec
module Mate
describe SwitchCommand do
class << self
@@ -31,8 +30,8 @@ def expect_twins(pair)
describe "in a regular app" do
expect_twins [
- "/Users/aslakhellesoy/scm/rspec/trunk/RSpec.tmbundle/Support/spec/spec/mate/switch_command_spec.rb",
- "/Users/aslakhellesoy/scm/rspec/trunk/RSpec.tmbundle/Support/lib/spec/mate/switch_command.rb"
+ "/Users/aslakhellesoy/scm/rspec/trunk/RSpec.tmbundle/Support/spec/rspec/mate/switch_command_spec.rb",
+ "/Users/aslakhellesoy/scm/rspec/trunk/RSpec.tmbundle/Support/lib/rspec/mate/switch_command.rb"
]
it "should suggest plain spec" do
View
5 Support/spec/spec_helper.rb
@@ -1,5 +1,8 @@
-require 'rspec/core'
+ENV['TM_PROJECT_DIRECTORY'] ||= '.'
+
require 'stringio'
+require 'rspec/mate'
+require 'rspec/core'
def sandboxed(&block)
begin
Please sign in to comment.
Something went wrong with that request. Please try again.