mutant 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,209 @@
1
+ module Inflector
2
+ # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
3
+ # inflection rules. Examples:
4
+ #
5
+ # Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1\2en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ #
9
+ # inflect.irregular 'octopus', 'octopi'
10
+ #
11
+ # inflect.uncountable "equipment"
12
+ # end
13
+ #
14
+ # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
15
+ # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
16
+ # already have been loaded.
17
+ class Inflections
18
+ def self.instance
19
+ @__instance__ ||= new
20
+ end
21
+
22
+ attr_reader :plurals, :singulars, :uncountables, :humans
23
+
24
+ def initialize
25
+ @plurals, @singulars, @uncountables, @humans = [], [], [], []
26
+ end
27
+
28
+ # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
29
+ # The replacement should always be a string that may include references to the matched data from the rule.
30
+ def plural(rule, replacement)
31
+ @uncountables.delete(rule) if rule.is_a?(String)
32
+ @uncountables.delete(replacement)
33
+ @plurals.insert(0, [rule, replacement])
34
+ end
35
+
36
+ # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
37
+ # The replacement should always be a string that may include references to the matched data from the rule.
38
+ def singular(rule, replacement)
39
+ @uncountables.delete(rule) if rule.is_a?(String)
40
+ @uncountables.delete(replacement)
41
+ @singulars.insert(0, [rule, replacement])
42
+ end
43
+
44
+ # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
45
+ # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
46
+ #
47
+ # Examples:
48
+ # irregular 'octopus', 'octopi'
49
+ # irregular 'person', 'people'
50
+ def irregular(singular, plural)
51
+ @uncountables.delete(singular)
52
+ @uncountables.delete(plural)
53
+ if singular[0,1].upcase == plural[0,1].upcase
54
+ plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
55
+ plural(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + plural[1..-1])
56
+ singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
57
+ else
58
+ plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
59
+ plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
60
+ plural(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
61
+ plural(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
62
+ singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
63
+ singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
64
+ end
65
+ end
66
+
67
+ # Add uncountable words that shouldn't be attempted inflected.
68
+ #
69
+ # Examples:
70
+ # uncountable "money"
71
+ # uncountable "money", "information"
72
+ # uncountable %w( money information rice )
73
+ def uncountable(*words)
74
+ (@uncountables << words).flatten!
75
+ end
76
+
77
+ # Specifies a humanized form of a string by a regular expression rule or by a string mapping.
78
+ # When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
79
+ # When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
80
+ #
81
+ # Examples:
82
+ # human /_cnt$/i, '\1_count'
83
+ # human "legacy_col_person_name", "Name"
84
+ def human(rule, replacement)
85
+ @humans.insert(0, [rule, replacement])
86
+ end
87
+
88
+ # Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
89
+ # Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
90
+ # <tt>:singulars</tt>, <tt>:uncountables</tt>, <tt>:humans</tt>.
91
+ #
92
+ # Examples:
93
+ # clear :all
94
+ # clear :plurals
95
+ def clear(scope = :all)
96
+ case scope
97
+ when :all
98
+ @plurals, @singulars, @uncountables = [], [], []
99
+ else
100
+ instance_variable_set "@#{scope}", []
101
+ end
102
+ end
103
+ end
104
+
105
+ # Yields a singleton instance of Inflector::Inflections so you can specify additional
106
+ # inflector rules.
107
+ #
108
+ # Example:
109
+ # Inflector.inflections do |inflect|
110
+ # inflect.uncountable "rails"
111
+ # end
112
+ def inflections
113
+ if block_given?
114
+ yield Inflections.instance
115
+ else
116
+ Inflections.instance
117
+ end
118
+ end
119
+
120
+ # Returns the plural form of the word in the string.
121
+ #
122
+ # Examples:
123
+ # "post".pluralize # => "posts"
124
+ # "octopus".pluralize # => "octopi"
125
+ # "sheep".pluralize # => "sheep"
126
+ # "words".pluralize # => "words"
127
+ # "CamelOctopus".pluralize # => "CamelOctopi"
128
+ def pluralize(word)
129
+ result = word.to_s.dup
130
+
131
+ if word.empty? || inflections.uncountables.include?(result.downcase)
132
+ result
133
+ else
134
+ inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
135
+ result
136
+ end
137
+ end
138
+
139
+ # The reverse of +pluralize+, returns the singular form of a word in a string.
140
+ #
141
+ # Examples:
142
+ # "posts".singularize # => "post"
143
+ # "octopi".singularize # => "octopus"
144
+ # "sheep".singularize # => "sheep"
145
+ # "word".singularize # => "word"
146
+ # "CamelOctopi".singularize # => "CamelOctopus"
147
+ def singularize(word)
148
+ result = word.to_s.dup
149
+
150
+ if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i }
151
+ result
152
+ else
153
+ inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
154
+ result
155
+ end
156
+ end
157
+
158
+ # Capitalizes the first word and turns underscores into spaces and strips a
159
+ # trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
160
+ #
161
+ # Examples:
162
+ # "employee_salary" # => "Employee salary"
163
+ # "author_id" # => "Author"
164
+ def humanize(lower_case_and_underscored_word)
165
+ result = lower_case_and_underscored_word.to_s.dup
166
+
167
+ inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
168
+ result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
169
+ end
170
+
171
+ # Capitalizes all the words and replaces some characters in the string to create
172
+ # a nicer looking title. +titleize+ is meant for creating pretty output. It is not
173
+ # used in the Rails internals.
174
+ #
175
+ # +titleize+ is also aliased as as +titlecase+.
176
+ #
177
+ # Examples:
178
+ # "man from the boondocks".titleize # => "Man From The Boondocks"
179
+ # "x-men: the last stand".titleize # => "X Men: The Last Stand"
180
+ def titleize(word)
181
+ humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
182
+ end
183
+
184
+ # Create the name of a table like Rails does for models to table names. This method
185
+ # uses the +pluralize+ method on the last word in the string.
186
+ #
187
+ # Examples
188
+ # "RawScaledScorer".tableize # => "raw_scaled_scorers"
189
+ # "egg_and_ham".tableize # => "egg_and_hams"
190
+ # "fancyCategory".tableize # => "fancy_categories"
191
+ def tableize(class_name)
192
+ pluralize(underscore(class_name))
193
+ end
194
+
195
+ # Create a class name from a plural table name like Rails does for table names to models.
196
+ # Note that this returns a string and not a Class. (To convert to an actual class
197
+ # follow +classify+ with +constantize+.)
198
+ #
199
+ # Examples:
200
+ # "egg_and_hams".classify # => "EggAndHam"
201
+ # "posts".classify # => "Post"
202
+ #
203
+ # Singular names are not handled correctly:
204
+ # "business".classify # => "Busines"
205
+ def classify(table_name)
206
+ # strip out any leading schema name
207
+ camelize(singularize(table_name.to_s.sub(/.*\./, '')))
208
+ end
209
+ end
@@ -0,0 +1,149 @@
1
+ # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
2
+ # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
3
+ # in inflections.rb.
4
+ #
5
+ # The Rails core team has stated patches for the inflections library will not be accepted
6
+ # in order to avoid breaking legacy applications which may be relying on errant inflections.
7
+ # If you discover an incorrect inflection and require it for your application, you'll need
8
+ # to correct it yourself (explained below).
9
+ module Inflector
10
+ extend self
11
+
12
+ # By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
13
+ # is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
14
+ #
15
+ # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
16
+ #
17
+ # Examples:
18
+ # "active_record".camelize # => "ActiveRecord"
19
+ # "active_record".camelize(:lower) # => "activeRecord"
20
+ # "active_record/errors".camelize # => "ActiveRecord::Errors"
21
+ # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
22
+ #
23
+ # As a rule of thumb you can think of +camelize+ as the inverse of +underscore+,
24
+ # though there are cases where that does not hold:
25
+ #
26
+ # "SSLError".underscore.camelize # => "SslError"
27
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
28
+ if first_letter_in_uppercase
29
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
30
+ else
31
+ lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
32
+ end
33
+ end
34
+
35
+ # Makes an underscored, lowercase form from the expression in the string.
36
+ #
37
+ # Changes '::' to '/' to convert namespaces to paths.
38
+ #
39
+ # Examples:
40
+ # "ActiveRecord".underscore # => "active_record"
41
+ # "ActiveRecord::Errors".underscore # => active_record/errors
42
+ #
43
+ # As a rule of thumb you can think of +underscore+ as the inverse of +camelize+,
44
+ # though there are cases where that does not hold:
45
+ #
46
+ # "SSLError".underscore.camelize # => "SslError"
47
+ def underscore(camel_cased_word)
48
+ word = camel_cased_word.to_s.dup
49
+ word.gsub!(/::/, '/')
50
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
51
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
52
+ word.tr!("-", "_")
53
+ word.downcase!
54
+ word
55
+ end
56
+
57
+ # Replaces underscores with dashes in the string.
58
+ #
59
+ # Example:
60
+ # "puni_puni" # => "puni-puni"
61
+ def dasherize(underscored_word)
62
+ underscored_word.gsub(/_/, '-')
63
+ end
64
+
65
+ # Removes the module part from the expression in the string.
66
+ #
67
+ # Examples:
68
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
69
+ # "Inflections".demodulize # => "Inflections"
70
+ def demodulize(class_name_in_module)
71
+ class_name_in_module.to_s.gsub(/^.*::/, '')
72
+ end
73
+
74
+ # Creates a foreign key name from a class name.
75
+ # +separate_class_name_and_id_with_underscore+ sets whether
76
+ # the method should put '_' between the name and 'id'.
77
+ #
78
+ # Examples:
79
+ # "Message".foreign_key # => "message_id"
80
+ # "Message".foreign_key(false) # => "messageid"
81
+ # "Admin::Post".foreign_key # => "post_id"
82
+ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
83
+ underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
84
+ end
85
+
86
+ # Ruby 1.9 introduces an inherit argument for Module#const_get and
87
+ # #const_defined? and changes their default behavior.
88
+ if Module.method(:const_get).arity == 1
89
+ # Tries to find a constant with the name specified in the argument string:
90
+ #
91
+ # "Module".constantize # => Module
92
+ # "Test::Unit".constantize # => Test::Unit
93
+ #
94
+ # The name is assumed to be the one of a top-level constant, no matter whether
95
+ # it starts with "::" or not. No lexical context is taken into account:
96
+ #
97
+ # C = 'outside'
98
+ # module M
99
+ # C = 'inside'
100
+ # C # => 'inside'
101
+ # "C".constantize # => 'outside', same as ::C
102
+ # end
103
+ #
104
+ # NameError is raised when the name is not in CamelCase or the constant is
105
+ # unknown.
106
+ def constantize(camel_cased_word)
107
+ names = camel_cased_word.split('::')
108
+ names.shift if names.empty? || names.first.empty?
109
+
110
+ constant = Object
111
+ names.each do |name|
112
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
113
+ end
114
+ constant
115
+ end
116
+ else
117
+ def constantize(camel_cased_word) #:nodoc:
118
+ names = camel_cased_word.split('::')
119
+ names.shift if names.empty? || names.first.empty?
120
+
121
+ constant = Object
122
+ names.each do |name|
123
+ constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
124
+ end
125
+ constant
126
+ end
127
+ end
128
+
129
+ # Turns a number into an ordinal string used to denote the position in an
130
+ # ordered sequence such as 1st, 2nd, 3rd, 4th.
131
+ #
132
+ # Examples:
133
+ # ordinalize(1) # => "1st"
134
+ # ordinalize(2) # => "2nd"
135
+ # ordinalize(1002) # => "1002nd"
136
+ # ordinalize(1003) # => "1003rd"
137
+ def ordinalize(number)
138
+ if (11..13).include?(number.to_i % 100)
139
+ "#{number}th"
140
+ else
141
+ case number.to_i % 10
142
+ when 1; "#{number}st"
143
+ when 2; "#{number}nd"
144
+ when 3; "#{number}rd"
145
+ else "#{number}th"
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,3 @@
1
+ module Inflector
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -1,28 +1,103 @@
1
- require 'mutant/extensions'
2
- require 'mutant/formatter'
3
- require 'mutant/implementation'
4
- require 'mutant/literal'
5
- require 'mutant/method'
6
- require 'mutant/mutatee'
7
- require 'mutant/mutation'
8
- require 'mutant/mutator'
9
- require 'mutant/node'
10
- require 'mutant/random'
11
- require 'mutant/reporter'
12
- require 'mutant/version'
1
+ require 'backports'
2
+ require 'adamantium'
3
+ require 'ice_nine'
4
+ require 'abstract_type'
5
+ require 'descendants_tracker'
6
+ require 'securerandom'
7
+ require 'equalizer'
8
+ require 'digest/sha1'
9
+ require 'to_source'
10
+ require 'inflector'
11
+ require 'ice_nine'
12
+ require 'ice_nine/core_ext/object'
13
+ require 'diff/lcs'
14
+ require 'diff/lcs/hunk'
15
+ require 'rspec'
13
16
 
17
+ # Library namespace
14
18
  module Mutant
15
- module Runners
16
- autoload :RSpec, 'mutant/runners/rspec'
17
- end
18
19
 
19
- def self.run(args)
20
- Runners::RSpec.run(args)
21
- end
20
+ # Define instance of subclassed superclass as constant
21
+ #
22
+ # @param [Class] superclass
23
+ # @param [Symbol] name
24
+ #
25
+ # @return [self]
26
+ #
27
+ # @api private
28
+ #
29
+ def self.define_singleton_subclass(name, superclass, &block)
30
+ klass = Class.new(superclass) do
31
+
32
+ def inspect; self.class.name; end
33
+
34
+ define_singleton_method(:name) do
35
+ "#{superclass.name}::#{name}".freeze
36
+ end
22
37
 
23
- def self.mutate(implementation)
24
- implementation.mutatees.each do |mutatee|
25
- Mutator.new(mutatee).mutate
26
38
  end
39
+ klass.class_eval(&block)
40
+ superclass.const_set(name, klass.new)
41
+ self
27
42
  end
43
+
28
44
  end
45
+
46
+ require 'mutant/support/method_object'
47
+ require 'mutant/helper'
48
+ require 'mutant/random'
49
+ require 'mutant/mutator'
50
+ require 'mutant/mutation'
51
+ require 'mutant/mutation/filter'
52
+ require 'mutant/mutation/filter/code'
53
+ require 'mutant/mutation/filter/whitelist'
54
+ require 'mutant/mutator/registry'
55
+ require 'mutant/mutator/util'
56
+ require 'mutant/mutator/node'
57
+ require 'mutant/mutator/node/literal'
58
+ require 'mutant/mutator/node/literal/boolean'
59
+ require 'mutant/mutator/node/literal/range'
60
+ require 'mutant/mutator/node/literal/symbol'
61
+ require 'mutant/mutator/node/literal/string'
62
+ require 'mutant/mutator/node/literal/fixnum'
63
+ require 'mutant/mutator/node/literal/float'
64
+ require 'mutant/mutator/node/literal/array'
65
+ require 'mutant/mutator/node/literal/empty_array'
66
+ require 'mutant/mutator/node/literal/hash'
67
+ require 'mutant/mutator/node/literal/regex'
68
+ require 'mutant/mutator/node/literal/nil'
69
+ require 'mutant/mutator/node/block'
70
+ require 'mutant/mutator/node/noop'
71
+ require 'mutant/mutator/node/send'
72
+ require 'mutant/mutator/node/arguments'
73
+ require 'mutant/mutator/node/define'
74
+ require 'mutant/mutator/node/return'
75
+ require 'mutant/mutator/node/if_statement'
76
+ require 'mutant/mutator/node/receiver_case'
77
+ require 'mutant/loader'
78
+ require 'mutant/context'
79
+ require 'mutant/context/scope'
80
+ require 'mutant/subject'
81
+ require 'mutant/matcher'
82
+ require 'mutant/matcher/chain'
83
+ require 'mutant/matcher/object_space'
84
+ require 'mutant/matcher/method'
85
+ require 'mutant/matcher/method/singleton'
86
+ require 'mutant/matcher/method/instance'
87
+ require 'mutant/matcher/method/classifier'
88
+ require 'mutant/matcher/scope_methods'
89
+ require 'mutant/killer'
90
+ require 'mutant/killer/static'
91
+ require 'mutant/killer/rspec'
92
+ require 'mutant/killer/forking'
93
+ require 'mutant/strategy'
94
+ require 'mutant/strategy/rspec'
95
+ require 'mutant/strategy/rspec/example_lookup'
96
+ require 'mutant/runner'
97
+ require 'mutant/cli'
98
+ require 'mutant/color'
99
+ require 'mutant/differ'
100
+ require 'mutant/reporter'
101
+ require 'mutant/reporter/stats'
102
+ require 'mutant/reporter/null'
103
+ require 'mutant/reporter/cli'