rr 1.1.0.rc1 → 1.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/rr/adapters.rb +64 -0
  4. data/lib/rr/autohook.rb +6 -13
  5. data/lib/rr/integrations.rb +7 -0
  6. data/lib/rr/{adapters → integrations}/minitest.rb +4 -4
  7. data/lib/rr/{adapters → integrations}/minitest_active_support.rb +4 -4
  8. data/lib/rr/{adapters → integrations}/none.rb +1 -1
  9. data/lib/rr/{adapters → integrations}/rspec/invocation_matcher.rb +9 -1
  10. data/lib/rr/{adapters → integrations}/rspec_1.rb +4 -4
  11. data/lib/rr/{adapters → integrations}/rspec_2.rb +3 -3
  12. data/lib/rr/{adapters → integrations}/test_unit_1.rb +4 -4
  13. data/lib/rr/{adapters → integrations}/test_unit_2.rb +1 -1
  14. data/lib/rr/{adapters → integrations}/test_unit_2_active_support.rb +3 -3
  15. data/lib/rr/without_autohook.rb +11 -9
  16. data/spec/suites/common/adapter_integration_tests.rb +88 -0
  17. data/spec/suites/common/rails_integration_test.rb +0 -51
  18. data/spec/suites/rspec_1/integration/rspec_1_spec.rb +59 -4
  19. data/spec/suites/rspec_1/integration/test_unit_1_rails_spec.rb +36 -1
  20. data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +45 -0
  21. data/spec/suites/rspec_1/integration/test_unit_2_rails_spec.rb +60 -3
  22. data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +64 -0
  23. data/spec/suites/rspec_2/integration/minitest_rails_spec.rb +56 -3
  24. data/spec/suites/rspec_2/integration/minitest_spec.rb +59 -0
  25. data/spec/suites/rspec_2/integration/rspec_2_spec.rb +109 -4
  26. data/spec/suites/rspec_2/integration/test_unit_rails_spec.rb +57 -3
  27. data/spec/suites/rspec_2/integration/test_unit_spec.rb +59 -0
  28. data/spec/suites/rspec_2/unit/{adapters → integrations}/rspec/invocation_matcher_spec.rb +1 -1
  29. data/spec/suites/rspec_2/unit/{adapters → integrations}/rspec_spec.rb +6 -6
  30. metadata +27 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef054bac4349c5c3f76cc2b3d338b04197427cb7
4
- data.tar.gz: b518e1419972353a82dabb2132cb75a0866320d4
3
+ metadata.gz: 5b496e2bd3931f611b957bea7bbc3f856fb0f821
4
+ data.tar.gz: 91f2a185b5ba1ebba0a63c3b30c9e370ea1e8058
5
5
  SHA512:
6
- metadata.gz: 427ec24ae2a285c7b2ba881d230c32d7ff0d99c2c3d8e4efe6295b1b368679869b5131ffb53e773c0b4546cf897adfcfd5de3b8423b21944244cdd74cc49a8be
7
- data.tar.gz: e743dc167bfcb5fbc315042f44ca6df094f9aba0bc0aecac9b1d8b6b0696544a40e1940aa3630bff10437f07b78a519fe5ca69bcc67c346e90ec9192b7b0c266
6
+ metadata.gz: ee6ad3bca380cde85a6244860645540366d29fa073adcc5b42f18df740d6057f6076b6d01b8438cd3faaf8064559eeef31d61b707b8d7710c8a1ffd216266221
7
+ data.tar.gz: 086ecee298ab54916ec6c0b6fcf7c70d102c2354d6738958708fca6a57b09fc298771f358d0020e3dbfa13e4387674a443c509122828c4a31547cca18a200df6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.rc1
1
+ 1.1.0.rc2
@@ -0,0 +1,64 @@
1
+ module RR
2
+ module Adapters
3
+ class << self
4
+ DEPRECATED_ADAPTERS = [
5
+ :MiniTest,
6
+ :TestUnit
7
+ ]
8
+
9
+ def const_missing(adapter_const_name)
10
+ unless DEPRECATED_ADAPTERS.include?(adapter_const_name)
11
+ super
12
+ return
13
+ end
14
+
15
+ show_warning_for(adapter_const_name)
16
+
17
+ adapter = shim_adapters[adapter_const_name] ||=
18
+ case adapter_const_name
19
+ when :TestUnit
20
+ find_applicable_adapter(:TestUnit1, :TestUnit2ActiveSupport, :TestUnit2)
21
+ when :MiniTest
22
+ find_applicable_adapter(:MiniTestActiveSupport, :MiniTest)
23
+ end
24
+
25
+ adapter
26
+ end
27
+
28
+ private
29
+
30
+ def shim_adapters
31
+ @shim_adapters ||= {}
32
+ end
33
+
34
+ def find_applicable_adapter(*adapter_const_names)
35
+ adapter = adapter_const_names.
36
+ map { |adapter_const_name| RR::Integrations.build(adapter_const_name) }.
37
+ find { |adapter| adapter.applies? }
38
+ if adapter
39
+ mod = Module.new
40
+ (class << mod; self; end).class_eval do
41
+ define_method(:included) do |base|
42
+ # Note: This assumes that the thing that is including this module
43
+ # is the same that the adapter detected and will hook into. In
44
+ # most cases this will be true; in cases such as
45
+ # ActiveSupport::TestCase, well, either stop doing this, or
46
+ # require 'rr/without_autohook'.
47
+ adapter.hook
48
+ end
49
+ end
50
+ mod
51
+ end
52
+ end
53
+
54
+ def show_warning_for(adapter_const_name)
55
+ warn <<EOT
56
+ --------------------------------------------------------------------------------
57
+ RR deprecation warning: RR now has an autohook system. You don't need to
58
+ `include RR::Adapters::*` in your test framework's base class anymore.
59
+ --------------------------------------------------------------------------------
60
+ EOT
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/rr/autohook.rb CHANGED
@@ -11,7 +11,7 @@ module RR
11
11
  ]
12
12
 
13
13
  def autohook
14
- find_applicable_adapters.each do |adapter|
14
+ applicable_adapters.each do |adapter|
15
15
  #puts "Using adapter: #{adapter.name}"
16
16
  adapter.hook
17
17
  end
@@ -21,21 +21,14 @@ module RR
21
21
 
22
22
  def adapters
23
23
  @adapters ||= ADAPTER_NAMES.map { |adapter_name|
24
- [adapter_name, RR::Adapters.const_get(adapter_name).new]
24
+ [adapter_name, RR::Integrations.build(adapter_name)]
25
25
  }
26
26
  end
27
27
 
28
- def find_applicable_adapters
29
- @applicable_adapters ||= begin
30
- applicable_adapters = adapters.inject([]) { |arr, (_, adapter)|
31
- arr << adapter if adapter.applies?
32
- arr
33
- }
34
- if applicable_adapters.empty?
35
- applicable_adapters << adapters.index(:None)
36
- end
37
- applicable_adapters
38
- end
28
+ def applicable_adapters
29
+ @applicable_adapters ||= adapters.
30
+ map { |_, adapter| adapter }.
31
+ select { |adapter| adapter.applies? }
39
32
  end
40
33
  end
41
34
  end
@@ -0,0 +1,7 @@
1
+ module RR
2
+ module Integrations
3
+ def self.build(name)
4
+ const_get(name).new
5
+ end
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class MiniTest
4
- module AdapterMethods
4
+ module Mixin
5
5
  def assert_received(subject, &block)
6
6
  block.call(received(subject)).call
7
7
  end
@@ -17,8 +17,8 @@ module RR
17
17
 
18
18
  def hook
19
19
  ::MiniTest::Unit::TestCase.class_eval do
20
- include RRMethods
21
- include AdapterMethods
20
+ include RR::Adapters::RRMethods
21
+ include Mixin
22
22
 
23
23
  unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
24
24
  alias_method :setup_without_rr, :setup
@@ -1,12 +1,12 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class MiniTestActiveSupport
4
4
  def initialize
5
5
  @mt_adapter = MiniTest.new
6
6
  end
7
7
 
8
8
  def name
9
- 'MiniTest w/ ActiveSupport'
9
+ 'MiniTest + ActiveSupport'
10
10
  end
11
11
 
12
12
  def applies?
@@ -15,8 +15,8 @@ module RR
15
15
 
16
16
  def hook
17
17
  ::ActiveSupport::TestCase.class_eval do
18
- include RRMethods
19
- include MiniTest::AdapterMethods
18
+ include RR::Adapters::RRMethods
19
+ include MiniTest::Mixin
20
20
 
21
21
  setup do
22
22
  RR.reset
@@ -1,5 +1,5 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class None
4
4
  def name
5
5
  'No adapter'
@@ -1,5 +1,5 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  module RSpec
4
4
  class InvocationMatcher < SpyVerificationProxy
5
5
  attr_reader :failure_message, :spy_verification_proxy
@@ -37,3 +37,11 @@ module RR
37
37
  end
38
38
  end
39
39
  end
40
+
41
+ module RR
42
+ module Adapters
43
+ module Rspec
44
+ InvocationMatcher = RR::Integrations::RSpec::InvocationMatcher
45
+ end
46
+ end
47
+ end
@@ -1,7 +1,7 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class RSpec1
4
- module AdapterMethods
4
+ module Mixin
5
5
  def setup_mocks_for_rspec
6
6
  RR.reset
7
7
  end
@@ -29,8 +29,8 @@ module RR
29
29
 
30
30
  def hook
31
31
  ::Spec::Runner.configure do |config|
32
- config.mock_with AdapterMethods
33
- config.include RRMethods
32
+ config.mock_with Mixin
33
+ config.include RR::Adapters::RRMethods
34
34
  end
35
35
  patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
36
36
  unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
@@ -1,5 +1,5 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class RSpec2 < RSpec1
4
4
  def name
5
5
  'RSpec 2'
@@ -11,8 +11,8 @@ module RR
11
11
 
12
12
  def hook
13
13
  ::RSpec.configure do |config|
14
- config.mock_with AdapterMethods
15
- config.include RRMethods
14
+ config.mock_with Mixin
15
+ config.include RR::Adapters::RRMethods
16
16
  end
17
17
  patterns = ::RSpec.configuration.backtrace_clean_patterns
18
18
  unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
@@ -1,7 +1,7 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class TestUnit1
4
- module AdapterMethods
4
+ module Mixin
5
5
  def assert_received(subject, &block)
6
6
  block.call(received(subject)).call
7
7
  end
@@ -17,8 +17,8 @@ module RR
17
17
 
18
18
  def hook(test_case_class = ::Test::Unit::TestCase)
19
19
  test_case_class.class_eval do
20
- include RRMethods
21
- include AdapterMethods
20
+ include RR::Adapters::RRMethods
21
+ include Mixin
22
22
 
23
23
  unless instance_methods.detect {|method_name| method_name.to_sym == :setup_with_rr }
24
24
  alias_method :setup_without_rr, :setup
@@ -1,5 +1,5 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class TestUnit2 < TestUnit1
4
4
  def name
5
5
  'Test::Unit 2'
@@ -1,5 +1,5 @@
1
1
  module RR
2
- module Adapters
2
+ module Integrations
3
3
  class TestUnit2ActiveSupport
4
4
  def initialize
5
5
  @tu2_adapter = TestUnit2.new
@@ -18,8 +18,8 @@ module RR
18
18
  RR.overridden_error_class = ::Test::Unit::AssertionFailedError
19
19
 
20
20
  ::ActiveSupport::TestCase.class_eval do
21
- include RRMethods
22
- include TestUnit1::AdapterMethods
21
+ include RR::Adapters::RRMethods
22
+ include TestUnit1::Mixin
23
23
 
24
24
  setup do
25
25
  RR.reset
@@ -85,15 +85,17 @@ require 'rr/times_called_matchers/at_most_matcher'
85
85
  require 'rr/spy_verification_proxy'
86
86
  require 'rr/spy_verification'
87
87
 
88
- require 'rr/adapters/rspec/invocation_matcher'
89
- require 'rr/adapters/rspec_1'
90
- require 'rr/adapters/rspec_2'
91
- require 'rr/adapters/test_unit_1'
92
- require 'rr/adapters/test_unit_2'
93
- require 'rr/adapters/test_unit_2_active_support'
94
- require 'rr/adapters/minitest'
95
- require 'rr/adapters/minitest_active_support'
96
- require 'rr/adapters/none'
88
+ require 'rr/adapters'
89
+ require 'rr/integrations'
90
+ require 'rr/integrations/rspec/invocation_matcher'
91
+ require 'rr/integrations/rspec_1'
92
+ require 'rr/integrations/rspec_2'
93
+ require 'rr/integrations/test_unit_1'
94
+ require 'rr/integrations/test_unit_2'
95
+ require 'rr/integrations/test_unit_2_active_support'
96
+ require 'rr/integrations/minitest'
97
+ require 'rr/integrations/minitest_active_support'
98
+ require 'rr/integrations/none'
97
99
 
98
100
  require 'rr/version'
99
101
 
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'session'
3
+ require 'tempfile'
4
+
5
+ module AdapterIntegrationTests
6
+ def debug?
7
+ ENV['RR_DEBUG'] == '1'
8
+ end
9
+
10
+ def run_fixture_tests(content)
11
+ output = nil
12
+ f = Tempfile.new('rr_test_fixture')
13
+ puts content if debug?
14
+ f.write(content)
15
+ f.close
16
+ bash = Session::Bash.new
17
+ cmd = "ruby -I #{lib_path} #{f.path} 2>&1"
18
+ puts cmd if debug?
19
+ stdout, stderr = bash.execute(cmd)
20
+ success = !!(bash.exit_status == 0 || stdout =~ /Finished/)
21
+ if debug? or !success
22
+ puts stdout
23
+ puts stderr
24
+ end
25
+ success.should be_true
26
+ stdout
27
+ ensure
28
+ f.unlink
29
+ end
30
+
31
+ def lib_path
32
+ File.expand_path('../../../../lib', __FILE__)
33
+ end
34
+
35
+ def test_helper_path
36
+ File.expand_path('../../../global_helper', __FILE__)
37
+ end
38
+
39
+ def ruby_18?
40
+ RUBY_VERSION =~ /^1\.8/
41
+ end
42
+
43
+ def bootstrap(opts={})
44
+ str = ""
45
+ str << "require 'rubygems'\n"
46
+ str << "require 'rr'\n" if opts[:include_rr_before]
47
+ str << <<-EOT
48
+ require '#{test_framework_path}'
49
+ #{additional_bootstrap}
50
+ EOT
51
+ str << "require 'rr'\n" unless opts[:include_rr_before]
52
+ str
53
+ end
54
+
55
+ def additional_bootstrap
56
+ ""
57
+ end
58
+
59
+ def all_tests_should_pass(output)
60
+ if output =~ /(\d+) failure/
61
+ $1.should be == '0'
62
+ end
63
+ if output =~ /(\d+) error/
64
+ $1.should be == '0'
65
+ end
66
+ end
67
+
68
+ def self.included(base)
69
+ base.class_eval do
70
+ specify "when RR raises an error it raises a failure not an exception" do
71
+ output = run_fixture_tests(error_test)
72
+ output.should match /1 failure/
73
+ end
74
+
75
+ specify "it is still possible to include the adapter into the test framework manually" do
76
+ output = run_fixture_tests(include_adapter_test)
77
+ all_tests_should_pass(output)
78
+ end
79
+
80
+ if method_defined?(:include_adapter_where_rr_included_before_test_framework_test)
81
+ specify "it is still possible to include the adapter into the test framework manually when RR is included before the test framework" do
82
+ output = run_fixture_tests(include_adapter_where_rr_included_before_test_framework_test)
83
+ all_tests_should_pass(output)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,6 +1,3 @@
1
- require 'rubygems'
2
- require 'session'
3
- require 'tempfile'
4
1
  $is_java = (RUBY_PLATFORM == 'java')
5
2
  if $is_java
6
3
  require 'arjdbc'
@@ -10,34 +7,6 @@ else
10
7
  end
11
8
 
12
9
  module IntegrationWithRails
13
- def debug?
14
- false
15
- end
16
-
17
- def run_fixture_tests(content)
18
- output = nil
19
- f = Tempfile.new('rr_test_fixture')
20
- f.write(content)
21
- f.close
22
- bash = Session::Bash.new
23
- cmd = "ruby #{f.path} 2>&1"
24
- puts cmd if debug?
25
- stdout, stderr = bash.execute(cmd)
26
- success = !!(bash.exit_status == 0 || stdout =~ /Finished/)
27
- if debug? or !success
28
- puts stdout
29
- puts stderr
30
- end
31
- success.should be_true
32
- stdout
33
- ensure
34
- f.unlink
35
- end
36
-
37
- def test_helper_path
38
- File.expand_path('../../../global_helper', __FILE__)
39
- end
40
-
41
10
  def sqlite_adapter
42
11
  $is_java ? 'jdbcsqlite3' : 'sqlite3'
43
12
  end
@@ -50,10 +19,6 @@ module IntegrationWithRails
50
19
  ruby_18? ? 'test_help' : 'rails/test_help'
51
20
  end
52
21
 
53
- def ruby_18?
54
- RUBY_VERSION =~ /^1\.8/
55
- end
56
-
57
22
  def bootstrap_active_record
58
23
  <<-EOT
59
24
  #{bootstrap}
@@ -73,22 +38,6 @@ module IntegrationWithRails
73
38
 
74
39
  def self.included(base)
75
40
  base.class_eval do
76
- specify "when RR raises an error it raises a failure not an exception" do
77
- output = run_fixture_tests <<-EOT
78
- #{bootstrap}
79
- require "#{test_helper_path}"
80
-
81
- class FooTest < ActiveSupport::TestCase
82
- def test_one
83
- object = Object.new
84
- mock(object).foo
85
- end
86
- end
87
- EOT
88
- output.should match /Failure/
89
- output.should match /1 failures/
90
- end
91
-
92
41
  specify "the database is properly rolled back after an RR error" do
93
42
  require 'active_record'
94
43
  FileUtils.rm_f(sqlite_db_file_path)