Class: Cucumber::Formatter::PickleSanitizer
- Inherits:
-
Object
- Object
- Cucumber::Formatter::PickleSanitizer
- Defined in:
- lib/cuke-inspector/formatter/pickle_sanitizer.rb
Constant Summary collapse
- @@pickle_parser =
nil
- @@pickle_capture_methods =
['capture_model', 'capture_fields', 'capture_factory', 'capture_plural_factory', 'capture_predicate']
Class Method Summary collapse
- .find_methods_that_match(regexp_string) ⇒ Object
-
.hacky_capture_predicate_sanitizer(regexp_string) ⇒ Object
Because the capture_predicate method at the time of running this code seems to differ from when it was run in the step that defined it, the simple method of replacing it does not work.
- .unpickle(regexp_string) ⇒ Object
Class Method Details
.find_methods_that_match(regexp_string) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cuke-inspector/formatter/pickle_sanitizer.rb', line 32 def self.find_methods_that_match(regexp_string) methods = @@pickle_parser.methods.select { |m| m =~ /^match|capture/ } methods.select do |method| begin foo = @@pickle_parser.send(method) regexp_string.include?(foo) rescue false end end.sort end |
.hacky_capture_predicate_sanitizer(regexp_string) ⇒ Object
Because the capture_predicate method at the time of running this code seems to differ from when it was run in the step that defined it, the simple method of replacing it does not work. Here is a convoluted regexp that does it. Better suggestions are welcome.
28 29 30 |
# File 'lib/cuke-inspector/formatter/pickle_sanitizer.rb', line 28 def self.hacky_capture_predicate_sanitizer(regexp_string) regexp_string.gsub(/\(\(\?:((?:\w+(?:\[_ \]\w+)*)(?:\|\w+(?:\[_ \]\w+)*)*)\)\)/, '#{capture_predicate}') end |
.unpickle(regexp_string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cuke-inspector/formatter/pickle_sanitizer.rb', line 11 def self.unpickle(regexp_string) if Gem.available?('pickle') @@pickle_parser ||= Pickle::Parser.new(:config => Pickle::Config.new) @@pickle_capture_methods.each do |capture_method| regexp_string.gsub!(@@pickle_parser.send(capture_method), "\#{#{capture_method}}") end regexp_string = hacky_capture_predicate_sanitizer(regexp_string) end regexp_string end |