rr 1.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +6 -0
  3. data/CHANGES.md +102 -1
  4. data/CREDITS.md +5 -0
  5. data/Gemfile +3 -0
  6. data/README.md +91 -110
  7. data/Rakefile +43 -0
  8. data/doc/02_syntax_comparison.md +1 -0
  9. data/gemfiles/ruby_19_rspec_2.gemfile +14 -0
  10. data/gemfiles/ruby_19_rspec_2.gemfile.lock +49 -0
  11. data/gemfiles/ruby_19_rspec_2_rails_4.gemfile +15 -0
  12. data/gemfiles/ruby_19_rspec_2_rails_4.gemfile.lock +119 -0
  13. data/lib/rr/class_instance_method_defined.rb +1 -1
  14. data/lib/rr/core_ext/array.rb +2 -0
  15. data/lib/rr/core_ext/hash.rb +2 -0
  16. data/lib/rr/deprecations.rb +97 -0
  17. data/lib/rr/double.rb +28 -10
  18. data/lib/rr/double_definitions/double_definition.rb +39 -16
  19. data/lib/rr/double_definitions/double_definition_create.rb +5 -5
  20. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +10 -4
  21. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +1 -1
  22. data/lib/rr/double_definitions/double_injections/instance.rb +2 -2
  23. data/lib/rr/double_definitions/strategies/strategy.rb +27 -8
  24. data/lib/rr/double_definitions/strategies/verification/mock.rb +8 -2
  25. data/lib/rr/double_matches.rb +4 -3
  26. data/lib/rr/dsl.rb +152 -0
  27. data/lib/rr/expectations/any_argument_expectation.rb +4 -4
  28. data/lib/rr/expectations/argument_equality_expectation.rb +43 -5
  29. data/lib/rr/injections/double_injection.rb +67 -19
  30. data/lib/rr/injections/method_missing_injection.rb +37 -6
  31. data/lib/rr/integrations.rb +13 -12
  32. data/lib/rr/integrations/decorator.rb +4 -1
  33. data/lib/rr/integrations/minitest_4.rb +1 -1
  34. data/lib/rr/integrations/minitest_4_active_support.rb +1 -1
  35. data/lib/rr/integrations/rspec/invocation_matcher.rb +0 -8
  36. data/lib/rr/integrations/rspec_2.rb +28 -3
  37. data/lib/rr/keyword_arguments.rb +15 -0
  38. data/lib/rr/method_dispatches/base_method_dispatch.rb +22 -5
  39. data/lib/rr/method_dispatches/method_dispatch.rb +21 -10
  40. data/lib/rr/method_dispatches/method_missing_dispatch.rb +14 -5
  41. data/lib/rr/recorded_call.rb +35 -0
  42. data/lib/rr/recorded_calls.rb +23 -9
  43. data/lib/rr/space.rb +15 -5
  44. data/lib/rr/spy_verification.rb +13 -5
  45. data/lib/rr/version.rb +1 -2
  46. data/lib/rr/wildcard_matchers.rb +10 -10
  47. data/lib/rr/without_autohook.rb +7 -14
  48. data/rr.gemspec +14 -5
  49. data/spec/custom_formatter_for_rspec.rb +18 -0
  50. data/spec/custom_formatter_for_rspec_2.rb +40 -0
  51. data/spec/defines_spec_suite_tasks.rb +57 -0
  52. data/spec/fixtures/rubygems_patch_for_187.rb +598 -0
  53. data/spec/global_helper.rb +38 -0
  54. data/spec/spec.opts +3 -0
  55. data/spec/spec_suite_configuration.rb +126 -0
  56. data/spec/spec_suite_runner.rb +47 -0
  57. data/spec/suites.yml +10 -0
  58. data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +147 -0
  59. data/spec/suites/rspec_2/functional/dont_allow_spec.rb +17 -0
  60. data/spec/suites/rspec_2/functional/mock_bang_spec.rb +20 -0
  61. data/spec/suites/rspec_2/functional/mock_instance_of_spec.rb +14 -0
  62. data/spec/suites/rspec_2/functional/mock_instance_of_strong_spec.rb +15 -0
  63. data/spec/suites/rspec_2/functional/mock_proxy_instance_of_spec.rb +15 -0
  64. data/spec/suites/rspec_2/functional/mock_proxy_spec.rb +14 -0
  65. data/spec/suites/rspec_2/functional/mock_spec.rb +17 -0
  66. data/spec/suites/rspec_2/functional/mock_strong_spec.rb +14 -0
  67. data/spec/suites/rspec_2/functional/received_spec.rb +16 -0
  68. data/spec/suites/rspec_2/functional/spy_spec.rb +102 -0
  69. data/spec/suites/rspec_2/functional/stub_bang_spec.rb +20 -0
  70. data/spec/suites/rspec_2/functional/stub_instance_of_spec.rb +15 -0
  71. data/spec/suites/rspec_2/functional/stub_instance_of_strong_spec.rb +15 -0
  72. data/spec/suites/rspec_2/functional/stub_proxy_instance_of_spec.rb +16 -0
  73. data/spec/suites/rspec_2/functional/stub_proxy_spec.rb +45 -0
  74. data/spec/suites/rspec_2/functional/stub_spec.rb +71 -0
  75. data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -0
  76. data/spec/suites/rspec_2/functional/wildcard_matchers_spec.rb +128 -0
  77. data/spec/suites/rspec_2/helper.rb +28 -0
  78. data/spec/suites/rspec_2/integration/minitest_4_spec.rb +109 -0
  79. data/spec/suites/rspec_2/integration/minitest_spec.rb +109 -0
  80. data/spec/suites/rspec_2/spec_helper.rb +3 -0
  81. data/spec/suites/rspec_2/support/matchers/wildcard_matcher_matchers.rb +32 -0
  82. data/spec/suites/rspec_2/support/mixins/double_definition_creator_helpers.rb +173 -0
  83. data/spec/suites/rspec_2/support/mixins/mock_definition_creator_helpers.rb +45 -0
  84. data/spec/suites/rspec_2/support/mixins/proxy_definition_creator_helpers.rb +33 -0
  85. data/spec/suites/rspec_2/support/mixins/stub_creator_helpers.rb +43 -0
  86. data/spec/suites/rspec_2/support/mixins/stub_definition_creator_helpers.rb +45 -0
  87. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_never_called_qualifier.rb +39 -0
  88. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_times_called_qualifier.rb +50 -0
  89. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_without_qualifiers.rb +131 -0
  90. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/dont_allow.rb +148 -0
  91. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb +26 -0
  92. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of_strong.rb +28 -0
  93. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_proxy.rb +11 -0
  94. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_strong.rb +37 -0
  95. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mocking.rb +107 -0
  96. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of.rb +32 -0
  97. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb +39 -0
  98. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_proxy.rb +11 -0
  99. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_strong.rb +37 -0
  100. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stubbing.rb +57 -0
  101. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/array_flatten_bug.rb +35 -0
  102. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/block_form.rb +31 -0
  103. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/comparing_arity.rb +63 -0
  104. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/object_is_proxy.rb +43 -0
  105. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/sequential_invocations.rb +26 -0
  106. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/setting_implementation.rb +51 -0
  107. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/yields.rb +81 -0
  108. data/spec/suites/rspec_2/support/shared_examples/space.rb +13 -0
  109. data/spec/suites/rspec_2/support/shared_examples/times_called_expectation.rb +9 -0
  110. data/spec/suites/rspec_2/unit/core_ext/array_spec.rb +39 -0
  111. data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +53 -0
  112. data/spec/suites/rspec_2/unit/core_ext/hash_spec.rb +55 -0
  113. data/spec/suites/rspec_2/unit/core_ext/range_spec.rb +41 -0
  114. data/spec/suites/rspec_2/unit/core_ext/regexp_spec.rb +41 -0
  115. data/spec/suites/rspec_2/unit/deprecations_spec.rb +27 -0
  116. data/spec/suites/rspec_2/unit/double_definitions/child_double_definition_create_spec.rb +114 -0
  117. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_blank_slate_spec.rb +93 -0
  118. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +446 -0
  119. data/spec/suites/rspec_2/unit/dsl/double_creators_spec.rb +133 -0
  120. data/spec/suites/rspec_2/unit/dsl/space_spec.rb +99 -0
  121. data/spec/suites/rspec_2/unit/dsl/wildcard_matchers_spec.rb +67 -0
  122. data/spec/suites/rspec_2/unit/errors/rr_error_spec.rb +67 -0
  123. data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +48 -0
  124. data/spec/suites/rspec_2/unit/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  125. data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +135 -0
  126. data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +30 -0
  127. data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +92 -0
  128. data/spec/suites/rspec_2/unit/expectations/satisfy_argument_equality_expectation_spec.rb +61 -0
  129. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/any_times_matcher_spec.rb +22 -0
  130. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_least_matcher_spec.rb +37 -0
  131. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_most_matcher_spec.rb +43 -0
  132. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb +58 -0
  133. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/proc_matcher_spec.rb +35 -0
  134. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/range_matcher_spec.rb +39 -0
  135. data/spec/suites/rspec_2/unit/hash_with_object_id_key_spec.rb +88 -0
  136. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +533 -0
  137. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_verify_spec.rb +32 -0
  138. data/spec/suites/rspec_2/unit/integrations/rspec/invocation_matcher_spec.rb +297 -0
  139. data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +70 -0
  140. data/spec/suites/rspec_2/unit/rr_spec.rb +28 -0
  141. data/spec/suites/rspec_2/unit/space_spec.rb +598 -0
  142. data/spec/suites/rspec_2/unit/spy_verification_spec.rb +133 -0
  143. data/spec/suites/rspec_2/unit/times_called_matchers/any_times_matcher_spec.rb +46 -0
  144. data/spec/suites/rspec_2/unit/times_called_matchers/at_least_matcher_spec.rb +54 -0
  145. data/spec/suites/rspec_2/unit/times_called_matchers/at_most_matcher_spec.rb +69 -0
  146. data/spec/suites/rspec_2/unit/times_called_matchers/integer_matcher_spec.rb +69 -0
  147. data/spec/suites/rspec_2/unit/times_called_matchers/proc_matcher_spec.rb +54 -0
  148. data/spec/suites/rspec_2/unit/times_called_matchers/range_matcher_spec.rb +75 -0
  149. data/spec/suites/rspec_2/unit/times_called_matchers/times_called_matcher_spec.rb +117 -0
  150. data/spec/suites/rspec_2/unit/wildcard_matchers/anything_spec.rb +33 -0
  151. data/spec/suites/rspec_2/unit/wildcard_matchers/boolean_spec.rb +45 -0
  152. data/spec/suites/rspec_2/unit/wildcard_matchers/duck_type_spec.rb +64 -0
  153. data/spec/suites/rspec_2/unit/wildcard_matchers/hash_including_spec.rb +64 -0
  154. data/spec/suites/rspec_2/unit/wildcard_matchers/is_a_spec.rb +55 -0
  155. data/spec/suites/rspec_2/unit/wildcard_matchers/numeric_spec.rb +46 -0
  156. data/spec/suites/rspec_2/unit/wildcard_matchers/satisfy_spec.rb +57 -0
  157. data/spec/support/adapter.rb +22 -0
  158. data/spec/support/adapter_tests/base.rb +45 -0
  159. data/spec/support/adapter_tests/minitest.rb +7 -0
  160. data/spec/support/adapter_tests/rspec.rb +70 -0
  161. data/spec/support/adapter_tests/test_unit.rb +47 -0
  162. data/spec/support/command_runner.rb +105 -0
  163. data/spec/support/generator.rb +56 -0
  164. data/spec/support/integration_tests/base.rb +64 -0
  165. data/spec/support/integration_tests/rails.rb +60 -0
  166. data/spec/support/integration_tests/rails_minitest.rb +13 -0
  167. data/spec/support/integration_tests/rails_rspec.rb +13 -0
  168. data/spec/support/integration_tests/rails_test_unit.rb +13 -0
  169. data/spec/support/integration_tests/rails_test_unit_like.rb +13 -0
  170. data/spec/support/integration_tests/ruby.rb +7 -0
  171. data/spec/support/integration_tests/ruby_minitest.rb +13 -0
  172. data/spec/support/integration_tests/ruby_rspec.rb +13 -0
  173. data/spec/support/integration_tests/ruby_test_unit.rb +13 -0
  174. data/spec/support/matchers/be_a_subset_of_matcher.rb +24 -0
  175. data/spec/support/project/cucumber.rb +50 -0
  176. data/spec/support/project/generator.rb +348 -0
  177. data/spec/support/project/minitest.rb +39 -0
  178. data/spec/support/project/rails.rb +199 -0
  179. data/spec/support/project/rails_minitest.rb +17 -0
  180. data/spec/support/project/rails_rspec.rb +50 -0
  181. data/spec/support/project/rails_test_unit.rb +17 -0
  182. data/spec/support/project/rails_test_unit_like.rb +17 -0
  183. data/spec/support/project/rspec.rb +69 -0
  184. data/spec/support/project/ruby.rb +34 -0
  185. data/spec/support/project/ruby_minitest.rb +11 -0
  186. data/spec/support/project/ruby_rspec.rb +29 -0
  187. data/spec/support/project/ruby_test_unit.rb +11 -0
  188. data/spec/support/project/ruby_test_unit_like.rb +21 -0
  189. data/spec/support/project/test_unit.rb +29 -0
  190. data/spec/support/project/test_unit_like.rb +7 -0
  191. data/spec/support/project/tests_runner.rb +22 -0
  192. data/spec/support/test.sqlite3 +0 -0
  193. data/spec/support/test_case/generator.rb +53 -0
  194. data/spec/support/test_case/minitest.rb +13 -0
  195. data/spec/support/test_case/rspec.rb +19 -0
  196. data/spec/support/test_case/test_unit.rb +21 -0
  197. data/spec/support/test_file/generator.rb +120 -0
  198. data/spec/support/test_file/minitest.rb +19 -0
  199. data/spec/support/test_file/rails_minitest.rb +7 -0
  200. data/spec/support/test_file/rails_rspec.rb +12 -0
  201. data/spec/support/test_file/rails_test_unit.rb +25 -0
  202. data/spec/support/test_file/rspec.rb +33 -0
  203. data/spec/support/test_file/test_unit.rb +36 -0
  204. data/spec/support/test_helper/generator.rb +27 -0
  205. data/spec/support/test_helper/minitest.rb +7 -0
  206. data/spec/support/test_helper/rails.rb +31 -0
  207. data/spec/support/test_helper/rails_minitest.rb +7 -0
  208. data/spec/support/test_helper/rails_rspec.rb +25 -0
  209. data/spec/support/test_helper/rails_test_unit.rb +23 -0
  210. data/spec/support/test_helper/rspec.rb +7 -0
  211. data/spec/support/test_helper/ruby.rb +31 -0
  212. data/spec/support/test_helper/test_unit.rb +7 -0
  213. metadata +240 -19
  214. data/VERSION +0 -1
  215. data/lib/rr/adapters.rb +0 -44
  216. data/lib/rr/adapters/rr_methods.rb +0 -142
  217. data/lib/rr/integrations/rspec_1.rb +0 -46
  218. data/lib/rr/integrations/test_unit_1.rb +0 -63
  219. data/lib/rr/integrations/test_unit_2.rb +0 -15
  220. data/lib/rr/integrations/test_unit_200.rb +0 -27
  221. data/lib/rr/integrations/test_unit_200_active_support.rb +0 -25
  222. data/lib/rr/integrations/test_unit_2_active_support.rb +0 -38
  223. data/lib/rr/proc_from_block.rb +0 -11
@@ -0,0 +1,38 @@
1
+ require 'pp'
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ if ENV['COVERAGE']
6
+ require 'simplecov'
7
+ SimpleCov.start
8
+ end
9
+
10
+ module RR
11
+ module Test
12
+ def self.setup_test_suite(adapter_name)
13
+ puts "Setting up test suite for #{adapter_name}" if ENV['RR_DEBUG']
14
+ unset_bundler_vars
15
+ adapter = Adapter.new(adapter_name)
16
+ ENV['ADAPTER'] = adapter.name.to_s
17
+ puts "Using appraisal: #{adapter.appraisal.name}" if ENV['RR_DEBUG']
18
+ ENV['BUNDLE_GEMFILE'] = adapter.appraisal.gemfile_path
19
+ puts "Using gemfile: #{adapter.appraisal.gemfile_path}" if ENV['RR_DEBUG']
20
+ Bundler.setup(:default)
21
+ $:.unshift File.expand_path('../../lib', __FILE__)
22
+ end
23
+
24
+ def self.unset_bundler_vars
25
+ # Copied from appraisal
26
+ %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |name|
27
+ ENV[name] = nil
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ lib_path = File.expand_path("../../lib", __FILE__)
34
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
35
+
36
+ Dir[ File.expand_path('../support/**/*.rb', __FILE__) ].each { |fn| require fn }
37
+
38
+ $stdout.sync = true
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --require ./spec/custom_formatter_for_rspec
2
+ --format CustomFormatterForRSpec
3
+ --color
@@ -0,0 +1,126 @@
1
+ require File.expand_path('../spec_suite_runner', __FILE__)
2
+
3
+ require 'yaml'
4
+ require 'erb'
5
+ require 'forwardable'
6
+ require 'ostruct'
7
+
8
+ class SpecSuiteConfiguration
9
+ SUITES_CONFIG_FILE = File.expand_path('../suites.yml', __FILE__)
10
+ TRAVIS_CONFIG_FILE = File.expand_path('../../.travis.yml', __FILE__)
11
+
12
+ class Suite < Struct.new(:name, :desc, :rvm_version, :ruby_id, :env, :travis)
13
+ attr_reader :runner
14
+
15
+ def initialize(name, desc, rvm_version, ruby_id, env, travis)
16
+ super
17
+ @runner = SpecSuiteRunner.new(self)
18
+ end
19
+
20
+ def appraisal_name
21
+ "ruby_#{ruby_id}_#{name}"
22
+ end
23
+
24
+ def run
25
+ runner.call
26
+ end
27
+
28
+ def current_ruby_id
29
+ '19'
30
+ end
31
+
32
+ def matching_current_ruby_version?
33
+ ruby_id == current_ruby_id
34
+ end
35
+ end
36
+
37
+ attr_reader :ruby_groups, :runners
38
+
39
+ def self.build
40
+ new(parse)
41
+ end
42
+
43
+ def self.parse
44
+ suites = []
45
+ yaml = ERB.new(File.read(SUITES_CONFIG_FILE)).result(binding)
46
+ ruby_groups = YAML.load(yaml)
47
+ ruby_groups.each do |ruby_id, ruby_group|
48
+ base_env = ruby_group.fetch('env', {})
49
+ ruby_group['suites'].each do |suite|
50
+ ruby_group['rvm_versions'].each do |rvm_version|
51
+ suite = suite.dup
52
+ suite['ruby_id'] = ruby_id.to_s
53
+ suite['rvm_version'] = rvm_version['name']
54
+ suite['env'] = base_env.merge(rvm_version.fetch('env', {}))
55
+ suite['travis'] = ruby_group.fetch('travis', {})
56
+ suite['travis']['env'] = base_env.merge(suite['travis'].fetch('env', {}))
57
+ suites << suite
58
+ end
59
+ end
60
+ end
61
+ suites
62
+ end
63
+
64
+ def self.root_dir
65
+ File.expand_path('../..', __FILE__)
66
+ end
67
+
68
+ attr_reader :suites
69
+
70
+ def initialize(suites)
71
+ @suites = suites.map do |suite|
72
+ Suite.new(
73
+ suite['name'],
74
+ suite['desc'],
75
+ suite['rvm_version'],
76
+ suite['ruby_id'],
77
+ suite['env'],
78
+ suite['travis']
79
+ )
80
+ end
81
+ end
82
+
83
+ def each_matching_suite(&block)
84
+ suites.
85
+ select { |suite| suite.matching_current_ruby_version? }.
86
+ each(&block)
87
+ end
88
+
89
+ def to_travis_config
90
+ inclusions = []
91
+ allowed_failures = []
92
+
93
+ sorted_suites = suites.sort_by { |suite| [suite.rvm_version, suite.name] }
94
+
95
+ sorted_suites.each do |suite|
96
+ env = suite.travis['env'].merge('SUITE' => suite.name)
97
+ row = {
98
+ 'rvm' => suite.rvm_version,
99
+ 'env' => env.map { |key, val| "#{key}=#{val.inspect}" }
100
+ }
101
+ inclusions << row
102
+ if suite.rvm_version == 'jruby-19mode'
103
+ allowed_failures << row
104
+ end
105
+ end
106
+ {
107
+ 'language' => 'ruby',
108
+ 'script' => 'rake spec:${SUITE}',
109
+ 'rvm' => '1.9.3',
110
+ 'matrix' => {
111
+ # exclude default row
112
+ 'exclude' => [
113
+ {'rvm' => '1.9.3'},
114
+ ],
115
+ 'include' => inclusions,
116
+ 'allow_failures' => allowed_failures
117
+ }
118
+ }
119
+ end
120
+
121
+ def generate_travis_config
122
+ config = to_travis_config
123
+ File.open(TRAVIS_CONFIG_FILE, 'w') {|f| YAML.dump(config, f) }
124
+ puts "Updated .travis.yml."
125
+ end
126
+ end
@@ -0,0 +1,47 @@
1
+ class SpecSuiteRunner
2
+ attr_reader :suite
3
+
4
+ def initialize(suite)
5
+ @suite = suite
6
+ end
7
+
8
+ def call
9
+ command = build_command
10
+ if ENV['RR_DEBUG']
11
+ puts "Running: #{command}"
12
+ end
13
+ execute_command(command)
14
+ end
15
+
16
+ private
17
+
18
+ def execute_command(command)
19
+ system(command)
20
+ status = $?.exitstatus
21
+ OpenStruct.new(:success? => (status == 0))
22
+ end
23
+
24
+ def build_command
25
+ parts = ['env'] + build_env_pairs + ['ruby'] + build_file_list
26
+ parts.join(" ")
27
+ end
28
+
29
+ def build_env_pairs
30
+ # If `bundle exec rake` is run instead of just `rake`, Bundler will set
31
+ # RUBYOPT to "-I <path to bundler> -r bundler/setup". This is unfortunate as
32
+ # it causes Bundler to be loaded before we load Bundler in
33
+ # RR::Test.setup_test_suite, thereby rendering our second Bundler.setup a
34
+ # no-op.
35
+ env = suite.env.merge(
36
+ 'BUNDLE_BIN_PATH' => '',
37
+ 'BUNDLE_GEMFILE' => '',
38
+ 'RUBYOPT' => '',
39
+ 'ADAPTER' => suite.name
40
+ )
41
+ env.map { |key, val| "#{key}=\"#{val}\"" }
42
+ end
43
+
44
+ def build_file_list
45
+ Dir[ File.expand_path("../suites/#{suite.name}/{.,*,**}/*_spec.rb", __FILE__) ]
46
+ end
47
+ end
data/spec/suites.yml ADDED
@@ -0,0 +1,10 @@
1
+ 19:
2
+ rvm_versions:
3
+ - name: 1.9.3
4
+ - name: 2.0.0
5
+ - name: jruby-19mode
6
+ suites:
7
+ - name: rspec_2
8
+ desc: 'RSpec 2'
9
+ env:
10
+ SPEC_OPTS: '--require $PWD/spec/custom_formatter_for_rspec_2 --format CustomFormatterForRSpec2 --backtrace'
@@ -0,0 +1,147 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe 'any_instance_of' do
4
+ context 'stubs for instance methods of a class' do
5
+ context 'via block form' do
6
+ context 'for existing methods' do
7
+ it "can be defined" do
8
+ a_class = Class.new { def some_method; 'value'; end }
9
+ any_instance_of(a_class) { |c| stub(c).some_method { 'value' } }
10
+ instance = a_class.new
11
+ expect(instance.some_method).to eq 'value'
12
+ end
13
+
14
+ it "can be reset" do
15
+ a_class = Class.new { def some_method; 'original value'; end }
16
+ any_instance_of(a_class) { |c| stub(c).some_method { 'value' } }
17
+ RR.reset
18
+ instance = a_class.new
19
+ expect(instance.some_method).to eq 'original value'
20
+ end
21
+ end
22
+
23
+ context 'for non-existing methods' do
24
+ it "can be defined" do
25
+ a_class = Class.new
26
+ any_instance_of(a_class) { |c| stub(c).some_method { 'value' } }
27
+ instance = a_class.new
28
+ expect(instance.some_method).to eq 'value'
29
+ end
30
+
31
+ it "can be reset" do
32
+ a_class = Class.new
33
+ any_instance_of(a_class) { |c| stub(c).some_method { 'value' } }
34
+ RR.reset
35
+ instance = a_class.new
36
+ expect(instance).not_to respond_to(:some_method)
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'via hash form' do
42
+ context 'for existing methods' do
43
+ it "can be defined" do
44
+ a_class = Class.new { def some_method; 'value'; end }
45
+ any_instance_of(a_class, :some_method => lambda { 'value' })
46
+ instance = a_class.new
47
+ expect(instance.some_method).to eq 'value'
48
+ end
49
+
50
+ it "can be reset" do
51
+ a_class = Class.new { def some_method; 'original value'; end }
52
+ any_instance_of(a_class, :some_method => lambda { 'value' })
53
+ RR.reset
54
+ instance = a_class.new
55
+ expect(instance.some_method).to eq 'original value'
56
+ end
57
+ end
58
+
59
+ context 'for non-existing methods' do
60
+ it "can be defined" do
61
+ a_class = Class.new
62
+ any_instance_of(a_class, :some_method => lambda { 'value' })
63
+ instance = a_class.new
64
+ expect(instance.some_method).to eq 'value'
65
+ end
66
+
67
+ it "can be reset" do
68
+ a_class = Class.new
69
+ any_instance_of(a_class, :some_method => lambda { 'value' })
70
+ RR.reset
71
+ instance = a_class.new
72
+ expect(instance).not_to respond_to(:some_method)
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'stub-proxies for instance methods of a class' do
79
+ it "can be defined" do
80
+ a_class = Class.new { def some_method; 'value'; end }
81
+ any_instance_of(a_class) { |c| stub.proxy(c).some_method { 'value' } }
82
+ instance = a_class.new
83
+ expect(instance.some_method).to eq 'value'
84
+ end
85
+
86
+ it "can be reset" do
87
+ a_class = Class.new { def some_method; 'original value'; end }
88
+ any_instance_of(a_class) { |c| stub.proxy(c).some_method { 'value' } }
89
+ RR.reset
90
+ instance = a_class.new
91
+ expect(instance.some_method).to eq 'original value'
92
+ end
93
+ end
94
+
95
+ context 'mocks for instance methods of a class' do
96
+ context 'for existing methods' do
97
+ it "can be defined" do
98
+ a_class = Class.new { def some_method; 'value'; end }
99
+ any_instance_of(a_class) { |c| mock(c).some_method { 'value' } }
100
+ instance = a_class.new
101
+ expect(instance.some_method).to eq 'value'
102
+ end
103
+
104
+ it "can be reset" do
105
+ a_class = Class.new { def some_method; 'original value'; end }
106
+ any_instance_of(a_class) { |c| mock(c).some_method { 'value' } }
107
+ RR.reset
108
+ instance = a_class.new
109
+ expect(instance.some_method).to eq 'original value'
110
+ end
111
+ end
112
+
113
+ context 'for non-existing methods' do
114
+ it "can be defined" do
115
+ a_class = Class.new
116
+ any_instance_of(a_class) { |c| mock(c).some_method { 'value' } }
117
+ instance = a_class.new
118
+ expect(instance.some_method).to eq 'value'
119
+ end
120
+
121
+ it "can be reset" do
122
+ a_class = Class.new
123
+ any_instance_of(a_class) { |c| mock(c).some_method { 'value' } }
124
+ RR.reset
125
+ instance = a_class.new
126
+ expect(instance).not_to respond_to(:some_method)
127
+ end
128
+ end
129
+ end
130
+
131
+ context 'mock-proxies for instance methods of a class' do
132
+ it "can be defined" do
133
+ a_class = Class.new { def some_method; 'value'; end }
134
+ any_instance_of(a_class) { |c| mock.proxy(c).some_method { 'value' } }
135
+ instance = a_class.new
136
+ expect(instance.some_method).to eq 'value'
137
+ end
138
+
139
+ it "can be reset" do
140
+ a_class = Class.new { def some_method; 'original value'; end }
141
+ any_instance_of(a_class) { |c| mock.proxy(c).some_method { 'value' } }
142
+ RR.reset
143
+ instance = a_class.new
144
+ expect(instance.some_method).to eq 'original value'
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe 'dont_allow', is_mock: true, is_dont_allow: true do
4
+ include MockDefinitionCreatorHelpers
5
+
6
+ context 'against instance methods', method_type: :instance do
7
+ include_context 'tests for a double definition creator method that supports dont_allow'
8
+ end
9
+
10
+ context 'against class methods', method_type: :class do
11
+ include_context 'tests for a double definition creator method that supports dont_allow'
12
+ end
13
+
14
+ def double_definition_creator_for(object, &block)
15
+ dont_allow(object, &block)
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe 'mock!' do
4
+ it "is a terser way of creating an object and mocking it" do
5
+ object = mock!.some_method { 'value' }.subject
6
+ expect(object.some_method).to eq 'value'
7
+ end
8
+
9
+ it "can be used inside the implementation block of a double" do
10
+ object = Object.new
11
+ stub(object).some_method { mock!.another_method { 'value' } }
12
+ expect(object.some_method.another_method).to eq 'value'
13
+ end
14
+
15
+ it "can be called on a double" do
16
+ object = Object.new
17
+ stub(object).some_method.mock!.another_method { 'value' }
18
+ expect(object.some_method.another_method).to eq 'value'
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ permutations =
4
+ %w(mock instance_of).permutation.map { |parts| parts.join('.') }
5
+
6
+ permutations.each do |permutation|
7
+ describe permutation, is_mock: true, is_instance_of: true do
8
+ include_context 'mock + instance_of'
9
+
10
+ define_method(:double_definition_creator_for) do |object, &block|
11
+ eval(permutation + '(object, &block)')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ permutations =
4
+ %w(mock instance_of strong).permutation.to_a.
5
+ map { |parts| parts.join('.') }
6
+
7
+ permutations.each do |permutation|
8
+ describe permutation, is_mock: true, is_instance_of: true, is_strong: true do
9
+ include_context 'mock + instance_of + strong'
10
+
11
+ define_method(:double_definition_creator_for) do |object, &block|
12
+ eval(permutation + '(object, &block)')
13
+ end
14
+ end
15
+ end