lib/rspec/autotest.rb in rspec-autotest-1.0.0.rc1 vs lib/rspec/autotest.rb in rspec-autotest-1.0.0.rc2

- old
+ new

@@ -2,68 +2,67 @@ require 'autotest' # Derived from the `Autotest` class, extends the `autotest` command to work # with RSpec. # -class Autotest::Rspec < Autotest - def initialize - super() - clear_mappings - setup_rspec_project_mappings +class Autotest + class Rspec < self + 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 + # 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 + # 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 + # Overrides Autotest's implementation to read rspec output + def consolidate_failures(failed) + filters = new_hash_of_arrays + failed.each do |spec, trace| + filters[$1] << spec if trace =~ /(.*spec\.rb)/ end + filters 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 + # 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) => []) + # 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 - end - private + private - def suffix - using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : "" - end + def suffix + if !using_bundler? && defined?(:Gem) + return ' -rrubygems' + end + '' + end - def using_bundler? - prefix =~ /bundle exec/ - end - - def gemfile? - File.exist?('./Gemfile') + def using_bundler? + prefix =~ /bundle exec/ + end end end