Skip to content

Commit bbeb1bd

Browse files
committed
Merge branch 'master' into move-textmate-formatter
Conflicts: Support/lib/rspec/mate/runner.rb
2 parents b26f2c7 + 84564da commit bbeb1bd

File tree

13 files changed

+413
-228
lines changed

13 files changed

+413
-228
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ Support/coverage
44
.emacs-project
55
*~
66
Support/Gemfile.lock
7+
.rvmrc
8+
.bundle

README.md

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,116 +9,144 @@
99

1010
## Support for both RSpec-1 and RSpec-2
1111

12-
This RSpec.tmbundle works with both rspec-1 and rspec-2. Given that they work
13-
differently, the RSpec.tmbundle tries its best to figure out which one you're
14-
using in each project when you try to run RSpec examples. There are two
15-
separate parts to this process, and you have some control over how each one
16-
works.
12+
This `RSpec.tmbundle` works with both rspec-1 and rspec-2. Given
13+
that they work differently, the `RSpec.tmbundle` tries its best to
14+
figure out which one you're using in each project when you try to
15+
run RSpec examples. There are two separate parts to this process,
16+
and you have some control over how each one works.
1717

18-
### Load Path
18+
### LOAD_PATH
1919

20-
The first thing that happens is that the RSpec.tmbundle prepares the Load Path
21-
as follows:
20+
The `RSpec.tmbundle` prepares the `LOAD_PATH` as follows:
2221

23-
If a Gemfile is present, it assumes you want to use Bundler to prepare the Load Path,
24-
so it requires 'bundler' and runs `Bundler.setup` (this can be overridden - see below).
22+
1. If a `Gemfile` is present, `Bundler` is used to prepare the
23+
Load Path with `requires 'bundler'` and then `Bundler.setup` is
24+
executed. (This can be overridden - see below).
2525

26-
If not using Bundler, then it looks to see if rspec is in vendor/plugins or vendor/gems,
27-
in which cases it adds its lib directory to the Load Path.
26+
2. If `Bundler` isn't being used, `vendor/plugins` and
27+
`vendor/gems` are searched for `rspec`. If `rspec` is found, then
28+
it's `lib` directory is added to `LOAD_PATH`.
2829

2930
### RSpec-version
3031

31-
Once the Load Path is prepared, the bundle tries to determine which version of
32-
RSpec to invoke as follows:
32+
Once the `LOAD_PATH` is prepared, `RSpec-tmbundle` tries to
33+
determine which version of RSpec to use as follows:
3334

34-
First, it looks for a ./rspec-tm file in the project root directory. If this
35-
is present, it looks to see if it contains a setting for the RSpec version. To
36-
use this, just add `.rspec-tm` to the project root with:
35+
1. `RSpec-tmbundle` checks for an `./rspec-tm` file in the
36+
project's root directory. If that file is exists, then
37+
`RSpec-tmbundle` attempts to set the RSpec version from the
38+
configuration found there.
39+
40+
To configure the version using this method add a file named
41+
`.rspec-tm` to the project's root directory containing:
3742

3843
--rspec-version 2.0.0
3944

40-
or which ever version you are using. This is the one fool proof way to ensure
41-
that the right version is invoked, but you don't really need to do this in most
42-
cases.
45+
or whichever version you are using.
46+
47+
This is the one foolproof way to ensure that the right version is
48+
invoked, but you don't really need to do this in most cases.
49+
50+
2. If no version is configured, `RSpec-tmbundle` searches for
51+
`rspec` in the `vendor/gems` and the `vendor/plugins` directories.
52+
If `rspec` is found, `RSpec-tmbundle` determines the version to
53+
use based on the files present there.
54+
55+
3. If no version is configured and no rspec directory could be
56+
found in vendor, then `RSpec-tmbundle` attempts to run rspec-2
57+
with:
4358

44-
If the version is not configured, it then checks to see if rspec was found in
45-
vendor/gems or vendor/plugins. If so, it figures out which version to invoke
46-
based on files present in that rspec directory.
59+
require 'rspec/core'
4760

48-
If no version is configured, and no rspec directory is found in vendor, then
49-
it just tries to require 'rspec/core' (for RSpec-2) and then 'spec/autorun' (for
50-
RSpec-1).
61+
If that raises an exception, `RSpec-tmbundle` makes a final
62+
attempt by trying to run rspec-1 with:
5163

52-
### Which approach should I use?
64+
require 'spec/autorun'
5365

54-
The effectiveness of each approach is dependent, in part, upon how you manage
55-
your gem environment. The simplest approach to choosing is to first see if it
56-
just works, and if not, then configure the version you want in the .rspec-tm file.
66+
### Which Approach Should I Use?
67+
68+
The effectiveness of each approach is partially dependent on how
69+
you manage your gem environment. The simplest (and suggested)
70+
approach is to first just see if it just works, and if not, then
71+
configure the version you want in the `.rspec-tm` file.
5772

5873
## Rubygems
5974

60-
The RSpec TextMate bundle does not `require "rubygems"` so that users who
61-
choose other packaging mechanisms can still use it. If you _are_ using Rubygems
62-
as your package manager, then the simplest thing to do is
75+
The RSpec TextMate bundle does not `require "rubygems"` so that
76+
users who choose other packaging mechanisms can still use it. If
77+
you _are_ using Rubygems as your package manager, then the
78+
simplest thing to do is
6379

64-
* open up TextMate Preferences
65-
* go to the Advanced tab
80+
* open the TextMate Preferences
81+
* go to the `Advanced` tab
6682
* add a variable named `RUBYOPT` with the value `rubygems`
6783

6884
## Options
6985

70-
You can set the following options in an .rspec-tm file in the root directory of
71-
your project:
86+
You can set the following options in an `.rspec-tm` file in the
87+
root directory of your project:
7288

7389
### --rspec-version
90+
7491
see RSpec-version, above.
7592

7693
### --bundler
77-
Tell the TMBundle to use Bundler, even if there is no Gemfile (in which case
78-
you should have the BUNDLER_GEMFILE environment variable set).
94+
95+
Use `Bundler`, even if there is no `Gemfile` (in which case you
96+
should have the `BUNDLER_GEMFILE` environment variable set).
7997

8098
### --skip-bundler
81-
Tell the TMBundle _not_ to use Bundler, even if there is a Gemfile.
99+
100+
Don't use `Bundler`, even if there is a `Gemfile`.
82101

83102
## TextMate shell variables
84103

85-
In addition to the standard TextMate shell variables, the RSpec TextMate bundle
86-
supports the following:
104+
In addition to the standard TextMate shell variables, the RSpec
105+
TextMate bundle supports the following:
87106

88107
### TM_RSPEC_FORMATTER
89-
Use to set a custom formatter other than RSpec's TextMate formatter. Use the
90-
full classname e.g. 'Spec::Core::Formatters::WebKit'
108+
109+
Set a custom formatter other than RSpec's TextMate formatter. Use
110+
the full classname, e.g. `'Spec::Core::Formatters::WebKit'`
91111

92112
### TM_RSPEC_OPTS
93-
Use this to set RSpec options just as you would in a .rspec file.
113+
114+
Use this to set RSpec options just as you would in an `.rspec`
115+
file.
94116

95117
### TM_RSPEC_HOME
96-
If you're hacking on rspec yourself, point this to the rspec-core project
97-
directory for rspec-2, or the rspec directory for rspec-1.
118+
119+
If you're hacking on rspec yourself, point this to the
120+
`rspec-core` project directory for rspec-2, or the `rspec`
121+
directory for rspec-1.
98122

99123
## RVM Integration
100124

101-
There are lots of ways to configure TextMate to work with rvm, but this is the
102-
one the we recommend:
125+
There are lots of ways to configure TextMate to work with `rvm`,
126+
but this is the one the we recommend:
103127

104-
First, copy the following into ~/.rvm/bin/textmate_ruby
128+
First, copy the following into` ~/.rvm/bin/textmate_ruby`
105129

106130
#!/usr/bin/env sh
107131
source ~/.rvm/scripts/rvm
108132
cd .
109133
exec ruby "$@"
110134

111-
Next, set up a `TM_RUBY` option in TextMate/Preferences/Advanced/Shell
112-
Variables that points to the textmate_ruby command.
135+
Next, set up a `TM_RUBY` option in
136+
`TextMate/Preferences/Advanced/Shell Variables` that points to the
137+
`textmate_ruby` command.
113138

114139
Learn more at:
115140

116141
* [http://beginrescueend.com/integration/textmate/](http://beginrescueend.com/integration/textmate/)
117142
* [http://groups.google.com/group/rubyversionmanager/browse_thread/thread/64b84bbcdf49e9b?fwc=1&pli=1](http://groups.google.com/group/rubyversionmanager/browse_thread/thread/64b84bbcdf49e9b?fwc=1&pli=1)
118143

119144
## History
120-
Parts of RSpec.tmbundle is based on Florian Weber's TDDMate.
145+
146+
Parts of `RSpec.tmbundle` are based on Florian Weber's TDDMate.
121147

122148
## License
123-
The license of RSpec.tmbundle is the same as [RSpec](http://github.com/rspec/rspec/blob/master/License.txt)'s.
149+
150+
The license of `RSpec.tmbundle` is the same as
151+
[RSpec](http://github.com/rspec/rspec/blob/master/License.txt)'s.
124152

Snippets/change.tmSnippet

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>content</key>
6+
<string>change { $1 }</string>
7+
<key>name</key>
8+
<string>change</string>
9+
<key>scope</key>
10+
<string>source.ruby.rspec</string>
11+
<key>tabTrigger</key>
12+
<string>ch</string>
13+
<key>uuid</key>
14+
<string>BAA8F11E-499B-4786-947F-603C1687E078</string>
15+
</dict>
16+
</plist>

Snippets/expect.tmSnippet

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>content</key>
6+
<string>expect(${1:target}).to</string>
7+
<key>name</key>
8+
<string>expect</string>
9+
<key>scope</key>
10+
<string>source.ruby.rspec</string>
11+
<key>tabTrigger</key>
12+
<string>exp</string>
13+
<key>uuid</key>
14+
<string>45959A25-330C-4CC0-93EC-075817C95ACC</string>
15+
</dict>
16+
</plist>

Snippets/expect_block.tmSnippet

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>content</key>
6+
<string>expect { ${1:target} }.to</string>
7+
<key>name</key>
8+
<string>expect with block</string>
9+
<key>scope</key>
10+
<string>source.ruby.rspec</string>
11+
<key>tabTrigger</key>
12+
<string>expb</string>
13+
<key>uuid</key>
14+
<string>A242D343-202A-44D2-B106-3E7EAF1926D2</string>
15+
</dict>
16+
</plist>

Support/Gemfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
source "http://rubygems.org"
22

3-
gem "rspec-core", :path => "../../rspec-core"
4-
gem "rspec-expectations", :path => "../../rspec-expectations"
5-
gem "rspec-mocks", :path => "../../rspec-mocks"
6-
7-
gem "ruby-debug"
8-
gem "guard-rspec"
3+
gem "guard-rspec", '~> 2.3.3'
4+
gem "rspec", '~> 2.12.0'
5+
gem "simplecov", '~> 0.7.1'

Support/lib/rspec/mate.rb

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,69 @@
11
# This is based on Florian Weber's TDDMate
22

33
ENV['TM_PROJECT_DIRECTORY'] ||= File.dirname(ENV['TM_FILEPATH'])
4+
45
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/..')
6+
57
require 'rspec/mate/runner'
68
require 'rspec/mate/options'
79
require 'rspec/mate/switch_command'
810
require 'rspec/mate/text_mate_formatter'
911

1012
rspec_lib = nil
1113

14+
# TODO: move to Options
15+
def bundler_option?
16+
RSpec::Mate::Options['--bundler']
17+
end
18+
19+
# TODO: move to Options
20+
def skip_bundler_option?
21+
RSpec::Mate::Options['--skip-bundler']
22+
end
23+
24+
def find_rspec_lib
25+
candidate_rspec_lib_paths = Dir.glob(
26+
File.join(
27+
ENV['TM_PROJECT_DIRECTORY'],
28+
'vendor',
29+
'{plugins,gems}',
30+
'{rspec,rspec-core}{,-[0-9]*}',
31+
'lib'
32+
)
33+
)
34+
35+
if ENV['TM_RSPEC_HOME']
36+
candidate_rspec_lib_paths << File.join(
37+
ENV['TM_RSPEC_HOME'],
38+
'lib'
39+
)
40+
end
41+
42+
rspec_lib = candidate_rspec_lib_paths.detect do |dir|
43+
File.exist?(dir)
44+
end
45+
end
46+
1247
def gemfile?
1348
File.exist?(File.join(ENV['TM_PROJECT_DIRECTORY'], 'Gemfile'))
1449
end
1550

16-
if RSpec::Mate::Options['--bundler'] || (gemfile? && !RSpec::Mate::Options['--skip-bundler'])
51+
def use_bundler?
52+
bundler_option? || (gemfile? && skip_bundler_option?)
53+
end
54+
55+
56+
if use_bundler?
1757
require "rubygems"
1858
require "bundler"
59+
1960
Bundler.setup
2061
else
21-
candidate_rspec_lib_paths = Dir.glob(File.join(ENV['TM_PROJECT_DIRECTORY'],'vendor','{plugins,gems}','{rspec,rspec-core}{,-[0-9]*}', 'lib'))
22-
candidate_rspec_lib_paths << File.join(ENV['TM_RSPEC_HOME'], 'lib') if ENV['TM_RSPEC_HOME']
23-
rspec_lib = candidate_rspec_lib_paths.detect { |dir| File.exist?(dir) }
62+
rspec_lib = find_rspec_lib
2463

25-
$LOAD_PATH.unshift(rspec_lib) if rspec_lib
64+
if rspec_lib
65+
$LOAD_PATH.unshift(rspec_lib)
66+
end
2667
end
2768

2869
if RSpec::Mate::Options['--rspec-version']
@@ -48,4 +89,3 @@ def gemfile?
4889
def rspec2?
4990
defined?(RSpec::Core)
5091
end
51-

0 commit comments

Comments
 (0)