Class: Autotest::Rspec2
Constant Summary collapse
- SPEC_PROGRAM =
File.('../../../bin/rspec', __FILE__)
Instance Attribute Summary collapse
-
#cl_args ⇒ Object
readonly
Returns the value of attribute cl_args.
-
#skip_bundler ⇒ Object
(also: #skip_bundler?)
readonly
Returns the value of attribute skip_bundler.
Instance Method Summary collapse
- #autotest_prefix ⇒ Object
- #autotest_wants_bundler? ⇒ Boolean
- #consolidate_failures(failed) ⇒ Object
- #gemfile? ⇒ Boolean
-
#initialize ⇒ Rspec2
constructor
A new instance of Rspec2.
- #make_test_cmd(files_to_test) ⇒ Object
- #normalize(files_to_test) ⇒ Object
- #prefix ⇒ Object
- #rspec_prefix ⇒ Object
- #rspec_wants_bundler? ⇒ Boolean
- #setup_rspec_project_mappings ⇒ Object
- #suffix ⇒ Object
- #using_bundler? ⇒ Boolean
- #warn_about_bundler ⇒ Object
Constructor Details
#initialize ⇒ Rspec2
Returns a new instance of Rspec2.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/autotest/rspec2.rb', line 13 def initialize super() @cl_args = ARGV.dup << "--tty" @skip_bundler = @cl_args.delete("--skip-bundler") 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 |
Instance Attribute Details
#cl_args ⇒ Object (readonly)
Returns the value of attribute cl_args.
8 9 10 |
# File 'lib/autotest/rspec2.rb', line 8 def cl_args @cl_args end |
#skip_bundler ⇒ Object (readonly) Also known as: skip_bundler?
Returns the value of attribute skip_bundler.
8 9 10 |
# File 'lib/autotest/rspec2.rb', line 8 def skip_bundler @skip_bundler end |
Instance Method Details
#autotest_prefix ⇒ Object
86 |
# File 'lib/autotest/rspec2.rb', line 86 alias_method :autotest_prefix, :prefix |
#autotest_wants_bundler? ⇒ Boolean
96 97 98 |
# File 'lib/autotest/rspec2.rb', line 96 def autotest_wants_bundler? autotest_prefix =~ /bundle exec/ end |
#consolidate_failures(failed) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/autotest/rspec2.rb', line 38 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 |
#gemfile? ⇒ Boolean
112 113 114 |
# File 'lib/autotest/rspec2.rb', line 112 def gemfile? File.exist?('./Gemfile') end |
#make_test_cmd(files_to_test) ⇒ Object
48 49 50 51 52 |
# File 'lib/autotest/rspec2.rb', line 48 def make_test_cmd(files_to_test) warn_about_bundler if rspec_wants_bundler? && !autotest_wants_bundler? files_to_test.empty? ? '' : "#{prefix}#{ruby}#{suffix} -S #{SPEC_PROGRAM} #{cl_args.join(' ')} #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}" end |
#normalize(files_to_test) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/autotest/rspec2.rb', line 54 def normalize(files_to_test) files_to_test.keys.inject({}) do |result, filename| result[File.(filename)] = [] result end end |
#prefix ⇒ Object
92 93 94 |
# File 'lib/autotest/rspec2.rb', line 92 def prefix skip_bundler? ? "#{rspec_prefix}#{autotest_prefix}".gsub("bundle exec","") : "#{rspec_prefix}#{autotest_prefix}" end |
#rspec_prefix ⇒ Object
88 89 90 |
# File 'lib/autotest/rspec2.rb', line 88 def rspec_prefix (rspec_wants_bundler? && !autotest_wants_bundler?) ? "bundle exec " : "" end |
#rspec_wants_bundler? ⇒ Boolean
104 105 106 |
# File 'lib/autotest/rspec2.rb', line 104 def rspec_wants_bundler? gemfile? && !skip_bundler? end |
#setup_rspec_project_mappings ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/autotest/rspec2.rb', line 26 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 |
#suffix ⇒ Object
100 101 102 |
# File 'lib/autotest/rspec2.rb', line 100 def suffix using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : "" end |
#using_bundler? ⇒ Boolean
108 109 110 |
# File 'lib/autotest/rspec2.rb', line 108 def using_bundler? rspec_wants_bundler? || autotest_wants_bundler? end |
#warn_about_bundler ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/autotest/rspec2.rb', line 61 def warn_about_bundler RSpec.warn_deprecation <<-WARNING **************************************************************************** DEPRECATION WARNING: you are using deprecated behaviour that will be removed from a future version of RSpec. RSpec's autotest extension is relying on the presence of a Gemfile in the project root directory to generate a command including 'bundle exec'. You have two options to suppress this message: If you want to include 'bundle exec' in the command, add a .autotest file to the project root with the following content: require 'autotest/bundler' If you want to _not_include 'bundle exec' in the command, pass --skip-bundler to autotest as an extra argument, like this: autotest -- --skip-bundler ***************************************************************** WARNING end |