Skip to content

Commit f4515e7

Browse files
committed
Merge pull request #1 from rspec/initial_build
Setup the initial build for rspec-autotest
2 parents 675ffab + c5ff1ff commit f4515e7

File tree

17 files changed

+540
-0
lines changed

17 files changed

+540
-0
lines changed

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--default_path spec
2+
--order rand
3+
--warnings

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: ruby
2+
script: "script/test_all 2>&1"
3+
bundler_args: "--standalone --binstubs"
4+
rvm:
5+
- 1.8.7
6+
- 1.9.2
7+
- 1.9.3
8+
- ree
9+
- jruby-18mode
10+
- jruby-19mode
11+
- rbx-18mode
12+
- rbx-19mode
13+
- 2.0.0

Gemfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
source "https://rubygems.org"
2+
3+
gemspec
4+
5+
%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
6+
library_path = File.expand_path("../../#{lib}", __FILE__)
7+
if File.exist?(library_path)
8+
gem lib, :path => library_path
9+
else
10+
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => '2-99-maintenance'
11+
end
12+
end
13+
14+
### deps for rdoc.info
15+
platforms :ruby do
16+
gem 'yard', '0.8.6.1', :require => false
17+
gem 'redcarpet', '2.1.1'
18+
gem 'github-markup', '0.7.2'
19+
end
20+
21+
### dep for ci/coverage
22+
gem 'coveralls', :require => false
23+
24+
eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')

License.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2009 Chad Humphries, David Chelimsky
4+
Copyright (c) 2006 David Chelimsky, The RSpec Development Team
5+
Copyright (c) 2005 Steven Baker
6+
7+
Permission is hereby granted, free of charge, to any person obtaining
8+
a copy of this software and associated documentation files (the
9+
"Software"), to deal in the Software without restriction, including
10+
without limitation the rights to use, copy, modify, merge, publish,
11+
distribute, sublicense, and/or sell copies of the Software, and to
12+
permit persons to whom the Software is furnished to do so, subject to
13+
the following conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# rspec-autotest [![Build Status](https://secure.travis-ci.org/rspec/rspec-autotest.png?branch=master)](http://travis-ci.org/rspec/rspec-autotest) [![Code Climate](https://codeclimate.com/github/rspec/rspec-autotest.png)](https://codeclimate.com/github/rspec/rspec-autotest) [![Coverage Status](https://coveralls.io/repos/rspec/rspec-autotest/badge.png?branch=master)](https://coveralls.io/r/rspec/rspec-autotest?branch=master)
2+
3+
rspec-autotest provides integration between autotest and RSpec
4+
5+
## Usage
6+
7+
RSpec ships with a specialized subclass of Autotest. To use it, just add a
8+
`.rspec` file to your project's root directory, and run the `autotest` command
9+
as normal:
10+
11+
$ autotest
12+
13+
## Bundler
14+
15+
The `autotest` command generates a shell command that runs your specs. If you
16+
are using Bundler, and you want the shell command to include `bundle exec`,
17+
require the Autotest bundler plugin in a `.autotest` file in the project's root
18+
directory or your home directory:
19+
20+
# in .autotest
21+
require "autotest/bundler"
22+
23+
## Upgrading from previous versions of rspec
24+
25+
Previous versions of RSpec used a different mechanism for telling autotest to
26+
invoke RSpec's Autotest extension: it generated an `autotest/discover.rb` file
27+
in the project's root directory. This is no longer necessary with the new
28+
approach of RSpec looking for a `.rspec` file, so feel free to delete the
29+
`autotest/discover.rb` file in the project root if you have one.
30+
31+
## Gotchas
32+
33+
### Invalid Option: --tty
34+
35+
The `--tty` option was [added in rspec-core-2.2.1](changelog), and is used
36+
internally by RSpec. If you see an error citing it as an invalid option, you'll
37+
probably see there are two or more versions of rspec-core in the backtrace: one
38+
< 2.2.1 and one >= 2.2.1.
39+
40+
This usually happens because you have a newer rspec-core installed, and an
41+
older rspec-core specified in a Bundler Gemfile. If this is the case, you can:
42+
43+
1. specify the newer version in the Gemfile (recommended)
44+
2. prefix the `autotest` command with `bundle exec`
45+
46+
47+
## Installation
48+
49+
Add this line to your application's Gemfile:
50+
51+
gem 'rspec-autotest'
52+
53+
And then execute:
54+
55+
$ bundle
56+
57+
Or install it yourself as:
58+
59+
$ gem install rspec-autotest
60+
61+
## Contributing
62+
63+
1. Fork it
64+
2. Create your feature branch (`git checkout -b my-new-feature`)
65+
3. Commit your changes (`git commit -am 'Add some feature'`)
66+
4. Push to the branch (`git push origin my-new-feature`)
67+
5. Create new Pull Request

Rakefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require "bundler/gem_tasks"
2+
require "rake"
3+
4+
require "rspec/core/rake_task"
5+
require "rspec/core/version"
6+
7+
desc "Run all examples"
8+
RSpec::Core::RakeTask.new(:spec) do |t|
9+
t.ruby_opts = %w[-w]
10+
end
11+
12+
task :default => :spec

lib/autotest/discover.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Autotest.add_discovery { "rspec2" } if File.exist?("./.rspec")

lib/autotest/rspec2.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'rspec/autotest'

lib/rspec/autotest.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
require 'rspec/autotest/version'
2+
require 'autotest'
3+
4+
module RSpec
5+
module Autotest
6+
end
7+
end
8+
9+
# Derived from the `Autotest` class, extends the `autotest` command to work
10+
# with RSpec.
11+
#
12+
class Autotest::Rspec2 < ::Autotest
13+
14+
def initialize
15+
super()
16+
clear_mappings
17+
setup_rspec_project_mappings
18+
19+
# Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
20+
# Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
21+
self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?(?:\e\[\d*m)?)+$/m
22+
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
23+
end
24+
25+
# Adds conventional spec-to-file mappings to Autotest configuration.
26+
def setup_rspec_project_mappings
27+
add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
28+
filename
29+
}
30+
add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
31+
["spec/#{m[1]}_spec.rb"]
32+
}
33+
add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
34+
files_matching %r%^spec/.*_spec\.rb$%
35+
}
36+
end
37+
38+
# Overrides Autotest's implementation to read rspec output
39+
def consolidate_failures(failed)
40+
filters = new_hash_of_arrays
41+
failed.each do |spec, trace|
42+
if trace =~ /(.*spec\.rb)/
43+
filters[$1] << spec
44+
end
45+
end
46+
return filters
47+
end
48+
49+
# Overrides Autotest's implementation to generate the rspec command to run
50+
def make_test_cmd(files_to_test)
51+
files_to_test.empty? ? '' :
52+
%|#{prefix}"#{ruby}"#{suffix} -S "#{RSpec::Core.path_to_executable}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
53+
end
54+
55+
# Generates a map of filenames to Arrays for Autotest
56+
def normalize(files_to_test)
57+
files_to_test.keys.inject({}) do |result, filename|
58+
result.merge!(File.expand_path(filename) => [])
59+
end
60+
end
61+
62+
private
63+
64+
def suffix
65+
using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
66+
end
67+
68+
def using_bundler?
69+
prefix =~ /bundle exec/
70+
end
71+
72+
def gemfile?
73+
File.exist?('./Gemfile')
74+
end
75+
end

lib/rspec/autotest/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module RSpec
2+
module Autotest
3+
VERSION = "1.0.0"
4+
end
5+
end

rspec-autotest.gemspec

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'rspec/autotest/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "rspec-autotest"
8+
spec.version = RSpec::Autotest::VERSION
9+
spec.authors = ["Steven Baker", "David Chelimsky", "Chad Humphries"]
10+
spec.email = "[email protected]"
11+
spec.homepage = "https://github.com/rspec/rspec-autotest"
12+
spec.summary = "rspec-autotest-#{RSpec::Autotest::VERSION}"
13+
spec.description = "RSpec Autotest integration"
14+
spec.license = "MIT"
15+
16+
spec.rubyforge_project = "rspec"
17+
18+
spec.files = `git ls-files`.split($/)
19+
spec.test_files = spec.files.grep(%r{^(spec|features)/})
20+
spec.rdoc_options = ["--charset=UTF-8"]
21+
spec.require_paths = ["lib"]
22+
23+
spec.required_ruby_version = '>= 1.8.7'
24+
25+
spec.add_dependency "rspec-core", ">= 2.99.0.pre"
26+
27+
spec.add_development_dependency "bundler", "~> 1.3"
28+
spec.add_development_dependency "rake", "~> 10.0.0"
29+
spec.add_development_dependency "aruba", "~> 0.5"
30+
spec.add_development_dependency "ZenTest", "~> 4.6"
31+
32+
end

script/test_all

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e -x
4+
5+
function is_jruby() {
6+
if ruby -e 'exit RUBY_PLATFORM == "java"'; then
7+
return 0
8+
else
9+
return 1
10+
fi
11+
}
12+
13+
# Needed by Bundler 1.3: https://github.com/carlhuda/bundler/issues/2382
14+
export RUBYOPT='-rrbconfig'
15+
16+
# idea taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
17+
export JRUBY_OPTS='-X-C' # disable JIT since these processes are so short lived
18+
19+
# force jRuby to use client mode JVM or a compilation mode thats as close as possible,
20+
# idea taken from https://github.com/jruby/jruby/wiki/Improving-startup-time
21+
export JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1'
22+
23+
echo "Bundling Standalone so we can run the specs w/o bundler loaded"
24+
bundle install --standalone --binstubs
25+
26+
echo "Running all..."
27+
bin/rspec spec -b --format progress
28+
29+
echo
30+
echo "--------------------------------------------------------------------"
31+
echo
32+
33+
if is_jruby; then
34+
echo "Skipping one-by-one spec runs due to expensive JVM load time"
35+
else
36+
for file in `find spec -iname '*_spec.rb'`; do
37+
NO_COVERALLS=1 bin/rspec $file -b --format progress
38+
done
39+
fi

spec/autotest/discover_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "spec_helper"
2+
3+
describe "autotest/discover.rb" do
4+
context "with ./.rspec present" do
5+
it "adds 'rspec2' to the list of discoveries" do
6+
File.stub(:exist?).with("./.rspec") { true }
7+
Autotest.should_receive(:add_discovery)
8+
load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
9+
end
10+
end
11+
12+
context "with ./.rspec absent" do
13+
it "does not add 'rspec2' to the list of discoveries" do
14+
File.stub(:exist?) { false }
15+
Autotest.should_not_receive(:add_discovery)
16+
load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
17+
end
18+
end
19+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require "spec_helper"
2+
3+
describe "failed_results_re for autotest" do
4+
def run_example
5+
group = RSpec::Core::ExampleGroup.describe("group")
6+
group.example("example") { yield }
7+
io = StringIO.new
8+
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(io)
9+
reporter = RSpec::Core::Reporter.new(formatter)
10+
11+
group.run(reporter)
12+
reporter.report(1, nil) {}
13+
io.string
14+
end
15+
16+
shared_examples "autotest failed_results_re" do
17+
it "matches a failure" do
18+
output = run_example { fail }
19+
expect(output).to match(Autotest::Rspec2.new.failed_results_re)
20+
expect(output).to include(__FILE__.sub(File.expand_path('.'),'.'))
21+
end
22+
23+
it "does not match when there are no failures" do
24+
output = run_example { } # pass
25+
expect(output).not_to match(Autotest::Rspec2.new.failed_results_re)
26+
expect(output).not_to include(__FILE__.sub(File.expand_path('.'),'.'))
27+
end
28+
end
29+
30+
context "with color enabled" do
31+
before do
32+
RSpec.configuration.stub(:color_enabled? => true)
33+
end
34+
35+
include_examples "autotest failed_results_re"
36+
end
37+
38+
context "with color disabled " do
39+
before do
40+
RSpec.configuration.stub(:color_enabled? => false)
41+
end
42+
43+
include_examples "autotest failed_results_re"
44+
end
45+
end

0 commit comments

Comments
 (0)