Skip to content

Setup the initial build for rspec-autotest #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.rvmrc
*.sw?
.DS_Store
coverage*
doc
rdoc
pkg
tmp
tags
rerun.txt
Gemfile.lock
.bundle
*.rbc
bin
.rbx
.yardoc
vendor
Gemfile-custom
.idea
bundle
.rspec-local
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--default_path spec
--order rand
--warnings
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: ruby
script: "script/test_all 2>&1"
bundler_args: "--standalone --binstubs"
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- ree
- jruby-18mode
- jruby-19mode
- rbx-18mode
- rbx-19mode
- 2.0.0
24 changes: 24 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
source "https://rubygems.org"

gemspec

%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
library_path = File.expand_path("../../#{lib}", __FILE__)
if File.exist?(library_path)
gem lib, :path => library_path
else
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => '2-99-maintenance'
end
end

### deps for rdoc.info
platforms :ruby do
gem 'yard', '0.8.6.1', :require => false
gem 'redcarpet', '2.1.1'
gem 'github-markup', '0.7.2'
end

### dep for ci/coverage
gem 'coveralls', :require => false

eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
24 changes: 24 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(The MIT License)

Copyright (c) 2009 Chad Humphries, David Chelimsky
Copyright (c) 2006 David Chelimsky, The RSpec Development Team
Copyright (c) 2005 Steven Baker

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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)

rspec-autotest provides integration between autotest and RSpec

## Usage

RSpec ships with a specialized subclass of Autotest. To use it, just add a
`.rspec` file to your project's root directory, and run the `autotest` command
as normal:

$ autotest

## Bundler

The `autotest` command generates a shell command that runs your specs. If you
are using Bundler, and you want the shell command to include `bundle exec`,
require the Autotest bundler plugin in a `.autotest` file in the project's root
directory or your home directory:

# in .autotest
require "autotest/bundler"

## Upgrading from previous versions of rspec

Previous versions of RSpec used a different mechanism for telling autotest to
invoke RSpec's Autotest extension: it generated an `autotest/discover.rb` file
in the project's root directory. This is no longer necessary with the new
approach of RSpec looking for a `.rspec` file, so feel free to delete the
`autotest/discover.rb` file in the project root if you have one.

## Gotchas

### Invalid Option: --tty

The `--tty` option was [added in rspec-core-2.2.1](changelog), and is used
internally by RSpec. If you see an error citing it as an invalid option, you'll
probably see there are two or more versions of rspec-core in the backtrace: one
< 2.2.1 and one >= 2.2.1.

This usually happens because you have a newer rspec-core installed, and an
older rspec-core specified in a Bundler Gemfile. If this is the case, you can:

1. specify the newer version in the Gemfile (recommended)
2. prefix the `autotest` command with `bundle exec`


## Installation

Add this line to your application's Gemfile:

gem 'rspec-autotest'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-autotest

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "bundler/gem_tasks"
require "rake"

require "rspec/core/rake_task"
require "rspec/core/version"

desc "Run all examples"
RSpec::Core::RakeTask.new(:spec) do |t|
t.ruby_opts = %w[-w]
end

task :default => :spec
1 change: 1 addition & 0 deletions lib/autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Autotest.add_discovery { "rspec2" } if File.exist?("./.rspec")
1 change: 1 addition & 0 deletions lib/autotest/rspec2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'rspec/autotest'
75 changes: 75 additions & 0 deletions lib/rspec/autotest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'rspec/autotest/version'
require 'autotest'

module RSpec
module Autotest
end
end

# Derived from the `Autotest` class, extends the `autotest` command to work
# with RSpec.
#
class Autotest::Rspec2 < ::Autotest

def initialize
super()
clear_mappings
setup_rspec_project_mappings

# Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
# Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?(?:\e\[\d*m)?)+$/m
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end

# Adds conventional spec-to-file mappings to Autotest configuration.
def setup_rspec_project_mappings
add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
filename
}
add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
["spec/#{m[1]}_spec.rb"]
}
add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
files_matching %r%^spec/.*_spec\.rb$%
}
end

# Overrides Autotest's implementation to read rspec output
def consolidate_failures(failed)
filters = new_hash_of_arrays
failed.each do |spec, trace|
if trace =~ /(.*spec\.rb)/
filters[$1] << spec
end
end
return filters
end

# Overrides Autotest's implementation to generate the rspec command to run
def make_test_cmd(files_to_test)
files_to_test.empty? ? '' :
%|#{prefix}"#{ruby}"#{suffix} -S "#{RSpec::Core.path_to_executable}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
end

# Generates a map of filenames to Arrays for Autotest
def normalize(files_to_test)
files_to_test.keys.inject({}) do |result, filename|
result.merge!(File.expand_path(filename) => [])
end
end

private

def suffix
using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
end

def using_bundler?
prefix =~ /bundle exec/
end

def gemfile?
File.exist?('./Gemfile')
end
end
5 changes: 5 additions & 0 deletions lib/rspec/autotest/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module RSpec
module Autotest
VERSION = "1.0.0"
end
end
32 changes: 32 additions & 0 deletions rspec-autotest.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rspec/autotest/version'

Gem::Specification.new do |spec|
spec.name = "rspec-autotest"
spec.version = RSpec::Autotest::VERSION
spec.authors = ["Steven Baker", "David Chelimsky", "Chad Humphries"]
spec.email = "[email protected]"
spec.homepage = "https://github.com/rspec/rspec-autotest"
spec.summary = "rspec-autotest-#{RSpec::Autotest::VERSION}"
spec.description = "RSpec Autotest integration"
spec.license = "MIT"

spec.rubyforge_project = "rspec"

spec.files = `git ls-files`.split($/)
spec.test_files = spec.files.grep(%r{^(spec|features)/})
spec.rdoc_options = ["--charset=UTF-8"]
spec.require_paths = ["lib"]

spec.required_ruby_version = '>= 1.8.7'

spec.add_dependency "rspec-core", ">= 2.99.0.pre"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake", "~> 10.0.0"
spec.add_development_dependency "aruba", "~> 0.5"
spec.add_development_dependency "ZenTest", "~> 4.6"

end
39 changes: 39 additions & 0 deletions script/test_all
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e -x

function is_jruby() {
if ruby -e 'exit RUBY_PLATFORM == "java"'; then
return 0
else
return 1
fi
}

# Needed by Bundler 1.3: https://github.com/carlhuda/bundler/issues/2382
export RUBYOPT='-rrbconfig'

# idea taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
export JRUBY_OPTS='-X-C' # disable JIT since these processes are so short lived

# force jRuby to use client mode JVM or a compilation mode thats as close as possible,
# idea taken from https://github.com/jruby/jruby/wiki/Improving-startup-time
export JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1'

echo "Bundling Standalone so we can run the specs w/o bundler loaded"
bundle install --standalone --binstubs

echo "Running all..."
bin/rspec spec -b --format progress

echo
echo "--------------------------------------------------------------------"
echo

if is_jruby; then
echo "Skipping one-by-one spec runs due to expensive JVM load time"
else
for file in `find spec -iname '*_spec.rb'`; do
NO_COVERALLS=1 bin/rspec $file -b --format progress
done
fi
19 changes: 19 additions & 0 deletions spec/autotest/discover_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "spec_helper"

describe "autotest/discover.rb" do
context "with ./.rspec present" do
it "adds 'rspec2' to the list of discoveries" do
File.stub(:exist?).with("./.rspec") { true }
Autotest.should_receive(:add_discovery)
load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
end
end

context "with ./.rspec absent" do
it "does not add 'rspec2' to the list of discoveries" do
File.stub(:exist?) { false }
Autotest.should_not_receive(:add_discovery)
load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
end
end
end
45 changes: 45 additions & 0 deletions spec/autotest/failed_results_re_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "spec_helper"

describe "failed_results_re for autotest" do
def run_example
group = RSpec::Core::ExampleGroup.describe("group")
group.example("example") { yield }
io = StringIO.new
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(io)
reporter = RSpec::Core::Reporter.new(formatter)

group.run(reporter)
reporter.report(1, nil) {}
io.string
end

shared_examples "autotest failed_results_re" do
it "matches a failure" do
output = run_example { fail }
expect(output).to match(Autotest::Rspec2.new.failed_results_re)
expect(output).to include(__FILE__.sub(File.expand_path('.'),'.'))
end

it "does not match when there are no failures" do
output = run_example { } # pass
expect(output).not_to match(Autotest::Rspec2.new.failed_results_re)
expect(output).not_to include(__FILE__.sub(File.expand_path('.'),'.'))
end
end

context "with color enabled" do
before do
RSpec.configuration.stub(:color_enabled? => true)
end

include_examples "autotest failed_results_re"
end

context "with color disabled " do
before do
RSpec.configuration.stub(:color_enabled? => false)
end

include_examples "autotest failed_results_re"
end
end
Loading