mutant 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. data/.gitignore +5 -11
  2. data/.rspec +0 -1
  3. data/.travis.yml +14 -3
  4. data/Changelog.md +3 -0
  5. data/Gemfile +5 -1
  6. data/Gemfile.devtools +49 -0
  7. data/Guardfile +18 -0
  8. data/README.md +67 -0
  9. data/Rakefile +4 -1
  10. data/TODO +13 -0
  11. data/bin/mutant +14 -0
  12. data/bin/zombie +14 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +2 -0
  15. data/config/roodi.yml +26 -0
  16. data/config/site.reek +93 -0
  17. data/config/yardstick.yml +2 -0
  18. data/lib/inflector.rb +7 -0
  19. data/lib/inflector/defaults.rb +62 -0
  20. data/lib/inflector/inflections.rb +209 -0
  21. data/lib/inflector/methods.rb +149 -0
  22. data/lib/inflector/version.rb +3 -0
  23. data/lib/mutant.rb +96 -21
  24. data/lib/mutant/cli.rb +309 -0
  25. data/lib/mutant/color.rb +61 -0
  26. data/lib/mutant/context.rb +36 -0
  27. data/lib/mutant/context/scope.rb +138 -0
  28. data/lib/mutant/differ.rb +100 -0
  29. data/lib/mutant/helper.rb +38 -0
  30. data/lib/mutant/killer.rb +136 -0
  31. data/lib/mutant/killer/forking.rb +41 -0
  32. data/lib/mutant/killer/rspec.rb +49 -0
  33. data/lib/mutant/killer/static.rb +19 -0
  34. data/lib/mutant/loader.rb +129 -0
  35. data/lib/mutant/matcher.rb +55 -0
  36. data/lib/mutant/matcher/chain.rb +66 -0
  37. data/lib/mutant/matcher/method.rb +173 -0
  38. data/lib/mutant/matcher/method/classifier.rb +126 -0
  39. data/lib/mutant/matcher/method/instance.rb +67 -0
  40. data/lib/mutant/matcher/method/singleton.rb +141 -0
  41. data/lib/mutant/matcher/object_space.rb +114 -0
  42. data/lib/mutant/matcher/scope_methods.rb +127 -0
  43. data/lib/mutant/mutation.rb +101 -12
  44. data/lib/mutant/mutation/filter.rb +75 -0
  45. data/lib/mutant/mutation/filter/code.rb +68 -0
  46. data/lib/mutant/mutation/filter/regexp.rb +39 -0
  47. data/lib/mutant/mutation/filter/whitelist.rb +47 -0
  48. data/lib/mutant/mutator.rb +134 -30
  49. data/lib/mutant/mutator/node.rb +163 -0
  50. data/lib/mutant/mutator/node/arguments.rb +24 -0
  51. data/lib/mutant/mutator/node/block.rb +24 -0
  52. data/lib/mutant/mutator/node/define.rb +24 -0
  53. data/lib/mutant/mutator/node/if_statement.rb +93 -0
  54. data/lib/mutant/mutator/node/literal.rb +54 -0
  55. data/lib/mutant/mutator/node/literal/array.rb +28 -0
  56. data/lib/mutant/mutator/node/literal/boolean.rb +49 -0
  57. data/lib/mutant/mutator/node/literal/dynamic.rb +24 -0
  58. data/lib/mutant/mutator/node/literal/empty_array.rb +26 -0
  59. data/lib/mutant/mutator/node/literal/fixnum.rb +37 -0
  60. data/lib/mutant/mutator/node/literal/float.rb +48 -0
  61. data/lib/mutant/mutator/node/literal/hash.rb +89 -0
  62. data/lib/mutant/mutator/node/literal/nil.rb +25 -0
  63. data/lib/mutant/mutator/node/literal/range.rb +94 -0
  64. data/lib/mutant/mutator/node/literal/regex.rb +43 -0
  65. data/lib/mutant/mutator/node/literal/string.rb +26 -0
  66. data/lib/mutant/mutator/node/literal/symbol.rb +26 -0
  67. data/lib/mutant/mutator/node/noop.rb +55 -0
  68. data/lib/mutant/mutator/node/receiver_case.rb +140 -0
  69. data/lib/mutant/mutator/node/return.rb +31 -0
  70. data/lib/mutant/mutator/node/send.rb +112 -0
  71. data/lib/mutant/mutator/registry.rb +48 -0
  72. data/lib/mutant/mutator/util.rb +87 -0
  73. data/lib/mutant/random.rb +24 -27
  74. data/lib/mutant/reporter.rb +48 -30
  75. data/lib/mutant/reporter/cli.rb +221 -0
  76. data/lib/mutant/reporter/null.rb +42 -0
  77. data/lib/mutant/reporter/stats.rb +64 -0
  78. data/lib/mutant/runner.rb +112 -0
  79. data/lib/mutant/strategy.rb +42 -0
  80. data/lib/mutant/strategy/rspec.rb +59 -0
  81. data/lib/mutant/strategy/rspec/example_lookup.rb +122 -0
  82. data/lib/mutant/subject.rb +115 -0
  83. data/lib/mutant/support/method_object.rb +31 -0
  84. data/locator.rb +87 -0
  85. data/mutant.gemspec +21 -21
  86. data/spec/integration/mutant/differ_spec.rb +15 -0
  87. data/spec/integration/mutant/loader_spec.rb +21 -0
  88. data/spec/integration/mutant/method_matching_spec.rb +269 -0
  89. data/spec/integration/mutant/rspec_killer_spec.rb +24 -0
  90. data/spec/integration/mutant/runner_spec.rb +26 -0
  91. data/spec/integration/mutant/zombie_spec.rb +8 -0
  92. data/spec/rcov.opts +7 -0
  93. data/spec/shared/command_method_behavior.rb +7 -0
  94. data/spec/shared/each_method_behaviour.rb +15 -0
  95. data/spec/shared/hash_method_behavior.rb +17 -0
  96. data/spec/shared/idempotent_method_behavior.rb +7 -0
  97. data/spec/shared/invertible_method_behaviour.rb +9 -0
  98. data/spec/shared/method_filter_parse_behavior.rb +16 -0
  99. data/spec/shared/method_match_behavior.rb +39 -0
  100. data/spec/shared/mutator_behavior.rb +46 -0
  101. data/spec/spec_helper.rb +11 -14
  102. data/spec/support/compress_helper.rb +10 -0
  103. data/spec/support/rspec.rb +22 -0
  104. data/spec/support/test_app.rb +5 -0
  105. data/spec/support/zombie.rb +141 -0
  106. data/spec/unit/mutant/cli/class_methods/new_spec.rb +87 -0
  107. data/spec/unit/mutant/cli/class_methods/run_spec.rb +38 -0
  108. data/spec/unit/mutant/context/root_spec.rb +11 -0
  109. data/spec/unit/mutant/context/scope/class_methods/build_spec.rb +29 -0
  110. data/spec/unit/mutant/context/scope/root_spec.rb +22 -0
  111. data/spec/unit/mutant/context/scope/unqualified_name_spec.rb +27 -0
  112. data/spec/unit/mutant/killer/fail_ques_spec.rb +39 -0
  113. data/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb +32 -0
  114. data/spec/unit/mutant/loader/eval/class_methods/run_spec.rb +33 -0
  115. data/spec/unit/mutant/loader/rubinius/class_methods/run_spec.rb +42 -0
  116. data/spec/unit/mutant/matcher/chain/each_spec.rb +37 -0
  117. data/spec/unit/mutant/matcher/chain/matchers_spec.rb +12 -0
  118. data/spec/unit/mutant/matcher/class_methods/from_string_spec.rb +49 -0
  119. data/spec/unit/mutant/matcher/class_methods/parse_spec.rb +12 -0
  120. data/spec/unit/mutant/matcher/each_spec.rb +14 -0
  121. data/spec/unit/mutant/matcher/method/class_methods/parse_spec.rb +21 -0
  122. data/spec/unit/mutant/matcher/method/classifier/class_methods/run_spec.rb +34 -0
  123. data/spec/unit/mutant/matcher/method/method_spec.rb +11 -0
  124. data/spec/unit/mutant/matcher/object_space/class_methods/parse_spec.rb +24 -0
  125. data/spec/unit/mutant/matcher/object_space/each_spec.rb +31 -0
  126. data/spec/unit/mutant/mutator/each_spec.rb +25 -0
  127. data/spec/unit/mutant/mutator/emit_new_spec.rb +51 -0
  128. data/spec/unit/mutant/mutator/emit_spec.rb +52 -0
  129. data/spec/unit/mutant/mutator/node/block/mutation_spec.rb +36 -0
  130. data/spec/unit/mutant/mutator/node/define/mutation_spec.rb +47 -0
  131. data/spec/unit/mutant/mutator/node/if_statement/mutation_spec.rb +30 -0
  132. data/spec/unit/mutant/mutator/node/literal/array_spec.rb +30 -0
  133. data/spec/unit/mutant/mutator/node/literal/boolean/mutation_spec.rb +23 -0
  134. data/spec/unit/mutant/mutator/node/literal/empty_array_spec.rb +17 -0
  135. data/spec/unit/mutant/mutator/node/literal/fixnum_spec.rb +17 -0
  136. data/spec/unit/mutant/mutator/node/literal/float_spec.rb +25 -0
  137. data/spec/unit/mutant/mutator/node/literal/hash_spec.rb +34 -0
  138. data/spec/unit/mutant/mutator/node/literal/nil_spec.rb +13 -0
  139. data/spec/unit/mutant/mutator/node/literal/range_spec.rb +35 -0
  140. data/spec/unit/mutant/mutator/node/literal/regex_spec.rb +23 -0
  141. data/spec/unit/mutant/mutator/node/literal/string_spec.rb +17 -0
  142. data/spec/unit/mutant/mutator/node/literal/symbol_spec.rb +17 -0
  143. data/spec/unit/mutant/mutator/node/receiver_case/mutation_spec.rb +27 -0
  144. data/spec/unit/mutant/mutator/node/return/mutation_spec.rb +21 -0
  145. data/spec/unit/mutant/mutator/node/send/mutation_spec.rb +78 -0
  146. data/spec/unit/mutant/mutator/self_spec.rb +7 -0
  147. data/spec/unit/mutant/subject/class_methods/new_spec.rb +13 -0
  148. data/spec/unit/mutant/subject/context_spec.rb +14 -0
  149. data/spec/unit/mutant/subject/each_spec.rb +35 -0
  150. data/spec/unit/mutant/subject/node_spec.rb +13 -0
  151. data/tasks/metrics/ci.rake +7 -0
  152. data/tasks/metrics/flay.rake +41 -0
  153. data/tasks/metrics/flog.rake +43 -0
  154. data/tasks/metrics/heckle.rake +216 -0
  155. data/tasks/metrics/metric_fu.rake +31 -0
  156. data/tasks/metrics/reek.rake +15 -0
  157. data/tasks/metrics/roodi.rake +15 -0
  158. data/tasks/metrics/yardstick.rake +23 -0
  159. data/tasks/spec.rake +45 -0
  160. data/tasks/yard.rake +9 -0
  161. data/test_app/.rspec +1 -0
  162. data/test_app/lib/test_app.rb +5 -0
  163. data/test_app/lib/test_app/literal.rb +32 -0
  164. data/test_app/spec/shared/command_method_behavior.rb +7 -0
  165. data/test_app/spec/shared/each_method_behaviour.rb +15 -0
  166. data/test_app/spec/shared/hash_method_behavior.rb +17 -0
  167. data/test_app/spec/shared/idempotent_method_behavior.rb +7 -0
  168. data/test_app/spec/shared/invertible_method_behaviour.rb +9 -0
  169. data/test_app/spec/shared/method_filter_parse_behavior.rb +16 -0
  170. data/test_app/spec/shared/method_match_behavior.rb +39 -0
  171. data/test_app/spec/shared/mutator_behavior.rb +44 -0
  172. data/test_app/spec/spec_helper.rb +7 -0
  173. data/test_app/spec/unit/test_app/literal/command_spec.rb +9 -0
  174. data/test_app/spec/unit/test_app/literal/string_spec.rb +9 -0
  175. metadata +346 -124
  176. data/.rvmrc +0 -1
  177. data/Readme.md +0 -13
  178. data/exe/mutate +0 -6
  179. data/lib/mutant/extensions.rb +0 -8
  180. data/lib/mutant/formatter.rb +0 -19
  181. data/lib/mutant/implementation.rb +0 -70
  182. data/lib/mutant/literal.rb +0 -147
  183. data/lib/mutant/method.rb +0 -31
  184. data/lib/mutant/mutatee.rb +0 -61
  185. data/lib/mutant/node.rb +0 -26
  186. data/lib/mutant/runners/rspec.rb +0 -34
  187. data/lib/mutant/version.rb +0 -3
  188. data/spec/functional/class_spec.rb +0 -46
  189. data/spec/functional/instance_method/array_spec.rb +0 -53
  190. data/spec/functional/instance_method/boolean_spec.rb +0 -101
  191. data/spec/functional/instance_method/call_spec.rb +0 -161
  192. data/spec/functional/instance_method/fixnum_spec.rb +0 -53
  193. data/spec/functional/instance_method/float_spec.rb +0 -53
  194. data/spec/functional/instance_method/hash_spec.rb +0 -53
  195. data/spec/functional/instance_method/if_spec.rb +0 -57
  196. data/spec/functional/instance_method/ivar_assign_spec.rb +0 -62
  197. data/spec/functional/instance_method/range_spec.rb +0 -53
  198. data/spec/functional/instance_method/regex_spec.rb +0 -55
  199. data/spec/functional/instance_method/string_spec.rb +0 -53
  200. data/spec/functional/instance_method/symbol_spec.rb +0 -53
  201. data/spec/functional/reporter/method_loaded_spec.rb +0 -62
  202. data/spec/functional/reporter/running_mutations_spec.rb +0 -60
  203. data/spec/functional/runners/rspec_spec.rb +0 -26
  204. data/spec/functional/singleton_method/array_spec.rb +0 -53
  205. data/spec/functional/singleton_method/boolean_spec.rb +0 -101
  206. data/spec/functional/singleton_method/call_spec.rb +0 -161
  207. data/spec/functional/singleton_method/fixnum_spec.rb +0 -53
  208. data/spec/functional/singleton_method/float_spec.rb +0 -53
  209. data/spec/functional/singleton_method/hash_spec.rb +0 -53
  210. data/spec/functional/singleton_method/if_spec.rb +0 -57
  211. data/spec/functional/singleton_method/ivar_assign_spec.rb +0 -60
  212. data/spec/functional/singleton_method/range_spec.rb +0 -53
  213. data/spec/functional/singleton_method/regex_spec.rb +0 -55
  214. data/spec/functional/singleton_method/string_spec.rb +0 -53
  215. data/spec/functional/singleton_method/symbol_spec.rb +0 -53
  216. data/spec/mutant/extensions_spec.rb +0 -13
  217. data/spec/mutant/implementation_spec.rb +0 -223
  218. data/spec/mutant/literal_spec.rb +0 -129
  219. data/spec/mutant/mutatee_spec.rb +0 -28
  220. data/spec/mutant/node_spec.rb +0 -41
  221. data/spec/mutant/random_spec.rb +0 -33
  222. data/spec/mutant/reporter_spec.rb +0 -17
  223. data/spec/mutant_spec.rb +0 -28
  224. data/spec/support/example_group_helpers.rb +0 -11
  225. data/spec/support/example_helpers.rb +0 -5
@@ -0,0 +1,31 @@
1
+ module Mutant
2
+ # A mixing to create method object semantics
3
+ module MethodObject
4
+ # Hook called when descendant is extended
5
+ #
6
+ # @param [Module|Class] descendant
7
+ #
8
+ # @return [undefined]
9
+ #
10
+ # @api private
11
+ #
12
+ def self.extended(descendant)
13
+ descendant.class_eval do
14
+ private_class_method :new
15
+ end
16
+ end
17
+
18
+ # Run the method object
19
+ #
20
+ # Not aliased to prevent problems from inheritance
21
+ #
22
+ # @return [Objecct]
23
+ # returns the created object
24
+ #
25
+ # @api private
26
+ #
27
+ def run(*args)
28
+ new(*args)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,87 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Mutant::Matcher::Method::Instance, '.each' do
5
+ subject { object.each(scope) { |item| yields << item } }
6
+
7
+ let(:object) { described_class }
8
+ let(:yields) { [] }
9
+
10
+ context 'when scope is a Class' do
11
+ let(:scope) do
12
+ ancestor = Class.new do
13
+ def ancestor_method
14
+ end
15
+ end
16
+
17
+ Class.new(ancestor) do
18
+ def self.name; 'SomeRandomClass'; end
19
+
20
+ def public_method; end
21
+ public :public_method
22
+
23
+ def protected_method; end
24
+ protected :protected_method
25
+
26
+ def private_method; end
27
+ private :private_method
28
+ end
29
+ end
30
+
31
+ it 'should yield instance method matchers' do
32
+ expected = [
33
+ Mutant::Matcher::Method::Instance.new(scope, :public_method ),
34
+ Mutant::Matcher::Method::Instance.new(scope, :protected_method),
35
+ Mutant::Matcher::Method::Instance.new(scope, :private_method )
36
+ ].sort_by(&:method_name)
37
+
38
+ expect { subject }.to change { yields.dup }.from([]).to(expected)
39
+ end
40
+ end
41
+ end
42
+
43
+ require 'spec_helper'
44
+
45
+ describe Mutant::Matcher::Method::Singleton, '.each' do
46
+ subject { object.each(scope) { |item| yields << item } }
47
+
48
+ let(:each_arguments) { [scope] }
49
+
50
+ let(:object) { described_class }
51
+ let(:yields) { [] }
52
+
53
+ context 'when scope is a Class' do
54
+ let(:scope) do
55
+ ancestor = Class.new do
56
+ def self.ancestor_method
57
+ end
58
+
59
+ def self.name; 'SomeRandomClass'; end
60
+ end
61
+
62
+ Class.new(ancestor) do
63
+ def self.public_method; end
64
+ public_class_method :public_method
65
+
66
+ class << self
67
+ def protected_method; end
68
+
69
+ protected :protected_method
70
+ end
71
+
72
+ def self.private_method; end
73
+ private_class_method :private_method
74
+ end
75
+ end
76
+
77
+ it 'should yield instance method matchers' do
78
+ expected = [
79
+ Mutant::Matcher::Method::Singleton.new(scope, :public_method ),
80
+ Mutant::Matcher::Method::Singleton.new(scope, :protected_method),
81
+ Mutant::Matcher::Method::Singleton.new(scope, :private_method )
82
+ ].sort_by(&:method_name)
83
+
84
+ expect { subject }.to change { yields.dup }.from([]).to(expected)
85
+ end
86
+ end
87
+ end
@@ -1,26 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "mutant/version"
4
2
 
5
- Gem::Specification.new do |s|
6
- s.name = 'mutant'
7
- s.version = Mutant::VERSION
8
- s.authors = ["Justin Ko", "Josep M. Bach"]
9
- s.email = ["justin@kospecinc.com", "josep.m.bach@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{Mutation tester}
12
- s.description = %q{Mutation tester}
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'mutant'
5
+ gem.version = '0.2.0'
6
+ gem.authors = [ 'Markus Schirp' ]
7
+ gem.email = [ 'mbj@seonic.net' ]
8
+ gem.description = 'Mutation testing for ruby under rubinius'
9
+ gem.summary = gem.description
10
+ gem.homepage = 'https://github.com/mbj/mutant'
13
11
 
14
- s.rubyforge_project = "mutant"
12
+ gem.require_paths = [ 'lib' ]
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- spec`.split("\n")
15
+ gem.extra_rdoc_files = %w[TODO]
16
+ gem.executables = [ 'mutant' ]
15
17
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- spec/*`.split("\n")
18
- s.bindir = 'exe'
19
- s.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
-
22
- s.add_runtime_dependency 'to_source'
23
- s.add_development_dependency 'rake'
24
- s.add_development_dependency 'rspec', '~> 2.7'
25
- s.add_development_dependency 'aruba'
18
+ gem.add_runtime_dependency('to_source', '~> 0.2.0')
19
+ gem.add_runtime_dependency('ice_nine', '~> 0.5.0')
20
+ gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
21
+ gem.add_runtime_dependency('backports', '~> 2.6')
22
+ gem.add_runtime_dependency('adamantium', '~> 0.0.3')
23
+ gem.add_runtime_dependency('equalizer', '~> 0.0.1')
24
+ gem.add_runtime_dependency('abstract_type', '~> 0.0.2')
25
+ gem.add_runtime_dependency('diff-lcs', '~> 1.1.3')
26
26
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mutant,'differ' do
4
+ specify 'allows to create diffs from text' do
5
+ a = "Foo\nBar\n"
6
+ b = "Foo\nBaz\n"
7
+ differ = Mutant::Differ.new(a,b)
8
+ differ.diff.should == strip_indent(<<-RUBY)
9
+ @@ -1,3 +1,3 @@
10
+ Foo
11
+ -Bar
12
+ +Baz
13
+ RUBY
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ class CodeLoadingSubject
4
+ def x
5
+ true
6
+ end
7
+ end
8
+
9
+ describe Mutant, 'code loading' do
10
+ let(:context) { Mutant::Context::Scope.build(CodeLoadingSubject,"/some/path") }
11
+ let(:node) { 'def foo; :bar; end'.to_ast }
12
+ let(:root) { context.root(node) }
13
+
14
+ subject { Mutant::Loader::Eval.run(root) }
15
+
16
+ before { subject }
17
+
18
+ it 'should add the method to subject' do
19
+ CodeLoadingSubject.new.foo.should be(:bar)
20
+ end
21
+ end
@@ -0,0 +1,269 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mutant, 'method matching' do
4
+ after do
5
+ if defined?(::Foo)
6
+ Object.send(:remove_const, 'Foo')
7
+ end
8
+ end
9
+
10
+ before do
11
+ #eval(body, TOPLEVEL_BINDING, __FILE__, 0)
12
+ eval(body)
13
+ File.stub(:read => body)
14
+ end
15
+
16
+ let(:defaults) { {} }
17
+
18
+ context 'on instance methods' do
19
+ def name(node)
20
+ node.name
21
+ end
22
+
23
+ def arguments(node)
24
+ node.arguments
25
+ end
26
+
27
+ let(:pattern) { 'Foo#bar' }
28
+ let(:defaults) do
29
+ {
30
+ :scope => Foo,
31
+ :node_class => Rubinius::AST::Define,
32
+ :method_name => :bar,
33
+ :method_arity => 0
34
+ }
35
+ end
36
+
37
+ context 'when method is defined once' do
38
+ let(:body) do
39
+ <<-RUBY
40
+ class Foo
41
+ def bar; end
42
+ end
43
+ RUBY
44
+ end
45
+
46
+ let(:expectation) do
47
+ { :method_line => 2 }
48
+ end
49
+
50
+ it_should_behave_like 'a method match'
51
+ end
52
+
53
+ context 'when method is defined multiple times' do
54
+ context 'on differend lines' do
55
+ let(:body) do
56
+ <<-RUBY
57
+ class Foo
58
+ def bar; end
59
+ def bar(arg); end
60
+ end
61
+ RUBY
62
+ end
63
+
64
+ let(:expectation) do
65
+ {
66
+ :method_line => 3,
67
+ :method_arity => 1
68
+ }
69
+ end
70
+
71
+ it_should_behave_like 'a method match'
72
+ end
73
+
74
+ context 'on the same line' do
75
+ let(:body) do
76
+ <<-RUBY
77
+ class Foo
78
+ def bar; end; def bar(arg); end
79
+ end
80
+ RUBY
81
+ end
82
+
83
+ let(:expectation) do
84
+ {
85
+ :method_line => 2,
86
+ :method_arity => 1
87
+ }
88
+ end
89
+
90
+ it_should_behave_like 'a method match'
91
+ end
92
+
93
+ context 'on the same line with differend scope' do
94
+ let(:body) do
95
+ <<-RUBY
96
+ class Foo
97
+ def self.bar; end; def bar(arg); end
98
+ end
99
+ RUBY
100
+ end
101
+
102
+ let(:expectation) do
103
+ {
104
+ :method_line => 2,
105
+ :method_arity => 1
106
+ }
107
+ end
108
+
109
+ it_should_behave_like 'a method match'
110
+ end
111
+
112
+ context 'when nested' do
113
+ let(:pattern) { 'Foo::Bar#baz' }
114
+
115
+ context 'in class' do
116
+ let(:body) do
117
+ <<-RUBY
118
+ class Foo
119
+ class Bar
120
+ def baz; end
121
+ end
122
+ end
123
+ RUBY
124
+ end
125
+
126
+ let(:expectation) do
127
+ {
128
+ :method_line => 3,
129
+ :method_name => :baz,
130
+ :scope => Foo::Bar
131
+ }
132
+ end
133
+
134
+ it_should_behave_like 'a method match'
135
+ end
136
+
137
+ context 'in module' do
138
+ let(:body) do
139
+ <<-RUBY
140
+ module Foo
141
+ class Bar
142
+ def baz; end
143
+ end
144
+ end
145
+ RUBY
146
+ end
147
+
148
+ let(:expectation) do
149
+ {
150
+ :method_line => 3,
151
+ :method_name => :baz,
152
+ :scope => Foo::Bar
153
+ }
154
+ end
155
+
156
+ it_should_behave_like 'a method match'
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ context 'on singleton methods' do
163
+ let(:pattern) { 'Foo.bar' }
164
+ let(:defaults) do
165
+ {
166
+ :scope => Foo,
167
+ :node_class => Rubinius::AST::DefineSingleton,
168
+ :method_arity => 0
169
+ }
170
+ end
171
+
172
+ def name(node)
173
+ node.body.name
174
+ end
175
+
176
+ def arguments(node)
177
+ node.body.arguments
178
+ end
179
+
180
+ context 'when defined on self' do
181
+ let(:body) do
182
+ <<-RUBY
183
+ class Foo
184
+ def self.bar; end
185
+ end
186
+ RUBY
187
+ end
188
+
189
+
190
+ let(:expectation) do
191
+ {
192
+ :method_name => :bar,
193
+ :method_line => 2,
194
+ }
195
+ end
196
+
197
+ it_should_behave_like 'a method match'
198
+ end
199
+
200
+ context 'when defined on constant' do
201
+
202
+ context 'inside namespace' do
203
+ let(:body) do
204
+ <<-RUBY
205
+ class Foo
206
+ def Foo.bar; end
207
+ end
208
+ RUBY
209
+ end
210
+
211
+
212
+ let(:expectation) do
213
+ {
214
+ :method_name => :bar,
215
+ :method_line => 2,
216
+ }
217
+ end
218
+
219
+ it_should_behave_like 'a method match'
220
+ end
221
+
222
+ context 'outside namespace' do
223
+ let(:body) do
224
+ <<-RUBY
225
+ class Foo; end;
226
+ def Foo.bar; end
227
+ RUBY
228
+ end
229
+
230
+
231
+ let(:expectation) do
232
+ {
233
+ :method_name => :bar,
234
+ :method_line => 2,
235
+ }
236
+ end
237
+
238
+ it_should_behave_like 'a method match'
239
+ end
240
+ end
241
+
242
+ context 'when defined multiple times in the same line' do
243
+ context 'with method on differend scope' do
244
+ let(:body) do
245
+ <<-RUBY
246
+ module Foo; end
247
+
248
+ module Bar
249
+ def self.baz; end; def Foo.baz(arg); end
250
+ end
251
+ RUBY
252
+ end
253
+
254
+ let(:pattern) { 'Bar.baz' }
255
+
256
+ let(:expectation) do
257
+ {
258
+ :scope => Bar,
259
+ :method_name => :baz,
260
+ :method_line => 4,
261
+ :method_arity => 0
262
+ }
263
+ end
264
+
265
+ it_should_behave_like 'a method match'
266
+ end
267
+ end
268
+ end
269
+ end