Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add preliminary support for autotest

To use autotest with rspec2, add an autotest directory to
the root of your project, and then autotest/discover.rb with:

    Autotest.add_discovery { "rspec2" }

Closes #13.
  • Loading branch information...
commit c1d600cd4367fb24a333c3f27f3b27693745ad14 1 parent 72be374
@dchelimsky dchelimsky authored
View
2  autotest/discover.rb
@@ -0,0 +1,2 @@
+Autotest.add_discovery { "rspec2" }
+
View
54 lib/autotest/rspec2.rb
@@ -0,0 +1,54 @@
+require 'autotest'
+
+Autotest.add_hook :initialize do |at|
+ at.clear_mappings
+ # watch out for Ruby bug (1.8.6): %r(/) != /\//
+ at.add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
+ filename
+ }
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
+ ["spec/#{m[1]}_spec.rb"]
+ }
+ at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
+ at.files_matching %r%^spec/.*_spec\.rb$%
+ }
+end
+
+class RspecCommandError < StandardError; end
+
+class Autotest::Rspec2 < Autotest
+
+ SPEC_PROGRAM = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec'))
+
+ def initialize
+ super
+ self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n\n?(.*?(\n\n\(.*?)?)\n\n/m
+ self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
+ end
+
+ def consolidate_failures(failed)
+ filters = new_hash_of_arrays
+ failed.each do |spec, trace|
+ if trace =~ /\n(\.\/)?(.*spec\.rb):[\d]+:/
+ filters[$2] << spec
+ end
+ end
+ return filters
+ end
+
+ def make_test_cmd(files_to_test)
+ files_to_test.empty? ? '' :
+ "#{ruby} #{SPEC_PROGRAM} #{normalize(files_to_test).keys.flatten.join(' ')} #{add_options_if_present}"
+ end
+
+ def normalize(files_to_test)
+ files_to_test.keys.inject({}) do |result, filename|
+ result[File.expand_path(filename)] = []
+ result
+ end
+ end
+
+ def add_options_if_present # :nodoc:
+ File.exist?("spec/spec.opts") ? "-O #{File.join('spec','spec.opts')} " : ""
+ end
+end
View
3  rspec-core.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Chad Humphries", "David Chelimsky"]
- s.date = %q{2010-03-09}
+ s.date = %q{2010-03-14}
s.description = %q{Rspec runner and example group classes}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.executables = ["rspec", "spec"]
@@ -95,6 +95,7 @@ Gem::Specification.new do |s|
"features/subject/explicit_subject.feature",
"features/subject/implicit_subject.feature",
"features/support/env.rb",
+ "lib/autotest/rspec2.rb",
"lib/rspec/autorun.rb",
"lib/rspec/core.rb",
"lib/rspec/core/around_proxy.rb",
Please sign in to comment.
Something went wrong with that request. Please try again.