cuke-inspector 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
22
  cuke-inspector.gemspec
23
+ .specification
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -0,0 +1,51 @@
1
+ module Cucumber
2
+ module Formatter
3
+ class PickleSanitizer
4
+ @@pickle_parser = nil
5
+ @@pickle_capture_methods = ['capture_model',
6
+ 'capture_fields',
7
+ 'capture_factory',
8
+ 'capture_plural_factory',
9
+ 'capture_predicate']
10
+
11
+ def self.unpickle(regexp_string)
12
+ if Gem.available?('pickle')
13
+ @@pickle_parser ||= Pickle::Parser.new(:config => Pickle::Config.new)
14
+ @@pickle_capture_methods.each do |capture_method|
15
+ regexp_string.gsub!(@@pickle_parser.send(capture_method), "\#{#{capture_method}}")
16
+ end
17
+ regexp_string = hacky_capture_predicate_sanitizer(regexp_string)
18
+ end
19
+
20
+ regexp_string
21
+ end
22
+
23
+ # Because the capture_predicate method at the time of running
24
+ # this code seems to differ from when it was run in the step
25
+ # that defined it, the simple method of replacing it does not
26
+ # work. Here is a convoluted regexp that does it. Better
27
+ # suggestions are welcome.
28
+ def self.hacky_capture_predicate_sanitizer(regexp_string)
29
+ regexp_string.gsub(/\(\(\?:((?:\w+(?:\[_ \]\w+)*)(?:\|\w+(?:\[_ \]\w+)*)*)\)\)/, '#{capture_predicate}')
30
+ end
31
+
32
+ def self.find_methods_that_match(regexp_string)
33
+ methods = @@pickle_parser.methods.select { |m| m =~ /^match|capture/ }
34
+ methods.select do |method|
35
+ begin
36
+ foo = @@pickle_parser.send(method)
37
+ regexp_string.include?(foo)
38
+ rescue
39
+ false
40
+ end
41
+ end.sort
42
+ end
43
+
44
+ private
45
+
46
+ def self.reset
47
+ @@pickle_parser = nil
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,6 @@
1
1
  require 'cucumber'
2
2
  require 'cucumber/formatter/usage'
3
+ require 'cuke-inspector/formatter/pickle_sanitizer'
3
4
 
4
5
  module Cucumber
5
6
  module Formatter
@@ -27,7 +28,7 @@ module Cucumber
27
28
  regexp.gsub!(/\(\[\^\\?\"\]\*\??\)/, prompt)
28
29
  regexp.gsub!('(.*)', prompt)
29
30
  regexp.gsub!('\/([^\/]*)\/', "/#{prompt}/")
30
- regexp
31
+ return PickleSanitizer.unpickle(regexp)
31
32
  end
32
33
 
33
34
  def progress(status)
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cuke-inspector/formatter/pickle_sanitizer'
3
+ require 'pickle' # pickle is required to run the test suite
4
+
5
+ module Cucumber
6
+ module Formatter
7
+ describe PickleSanitizer do
8
+ describe "when pickle is not loaded" do
9
+ before do
10
+ Gem.stub!(:available?).with('pickle').and_return false
11
+ end
12
+
13
+ it "returns any regexp string unmodified" do
14
+ regexp_string = "a user exists with name: \"??\""
15
+ PickleSanitizer.unpickle(regexp_string).should == regexp_string
16
+ end
17
+
18
+ it "never creates a pickle parser" do
19
+ Pickle::Parser.should_not_receive(:new)
20
+ PickleSanitizer.unpickle('foo')
21
+ end
22
+ end
23
+
24
+ describe "when pickle is loaded" do
25
+ before do
26
+ PickleSanitizer.reset
27
+ Gem.stub!(:available?).with('pickle').and_return true
28
+ @parser = mock('pickle parser')
29
+ @parser.stub!(:capture_model).and_return 'mock capture model'
30
+ @parser.stub!(:capture_fields).and_return 'mock capture fields'
31
+ @parser.stub!(:capture_factory).and_return 'mock capture factory'
32
+ @parser.stub!(:capture_plural_factory).and_return 'mock capture plural factory'
33
+ @parser.stub!(:capture_predicate).and_return 'mock capture predicate'
34
+ Pickle::Parser.stub!(:new).and_return @parser
35
+ end
36
+
37
+ it "creates a pickle parser with a new config" do
38
+ mock_config = mock('pickle config')
39
+ Pickle::Config.stub!(:new).and_return mock_config
40
+ Pickle::Parser.should_receive(:new).with hash_including(:config => mock_config)
41
+ PickleSanitizer.unpickle('foo')
42
+ end
43
+
44
+ it "only creates a pickle parser once" do
45
+ PickleSanitizer.unpickle('foo')
46
+ Pickle::Parser.should_not_receive(:new)
47
+ PickleSanitizer.unpickle('foo')
48
+ end
49
+
50
+ it "maps a model capture to a placeholder" do
51
+ @parser.stub!(:capture_model).and_return('stubbed model capture regexp')
52
+ regexp_string = "this is a stubbed model capture regexp example"
53
+ PickleSanitizer.unpickle(regexp_string).should ==
54
+ "this is a \#{capture_model} example"
55
+ end
56
+
57
+ it "maps a fields capture to a placeholder" do
58
+ @parser.stub!(:capture_fields).and_return('stubbed fields capture regexp')
59
+ regexp_string = "this is a stubbed fields capture regexp example"
60
+ PickleSanitizer.unpickle(regexp_string).should ==
61
+ "this is a \#{capture_fields} example"
62
+ end
63
+
64
+ it "maps capture_factory to a placeholder" do
65
+ @parser.stub!(:capture_factory).and_return('stubbed factory capture regexp')
66
+ regexp_string = "this is a stubbed factory capture regexp example"
67
+ PickleSanitizer.unpickle(regexp_string).should ==
68
+ "this is a \#{capture_factory} example"
69
+ end
70
+
71
+ it "maps capture_plural_factory to a place holder" do
72
+ @parser.stub!(:capture_plural_factory).and_return('stubbed plural factory capture regexp')
73
+ regexp_string = "this is a stubbed plural factory capture regexp example"
74
+ PickleSanitizer.unpickle(regexp_string).should ==
75
+ "this is a \#{capture_plural_factory} example"
76
+ end
77
+
78
+ it "maps capture_predicate" do
79
+ @parser.stub!(:capture_predicate).and_return('stubbed predicate capture regexp')
80
+ regexp_string = "this is a stubbed predicate capture regexp example"
81
+ PickleSanitizer.unpickle(regexp_string).should ==
82
+ "this is a \#{capture_predicate} example"
83
+ end
84
+
85
+ it "maps capture_predicate even if it has changed" do
86
+ predicate_example = "((?:position[_ ]by[_ ]type|respond[_ ]to[_ ]without[_ ]attributes|invalid|publishing[_ ]enabled|attribute[_ ]present|nil|updated[_ ]at|acts[_ ]like|first[_ ]item|present))"
87
+ @parser.stub!(:capture_predicate).and_return(predicate_example)
88
+ regexp_string = "this string contains a simple predicate capture ((?:position[_ ]by[_ ]type|respond[_ ]to[_ ]without[_ ]attributes|invalid|publishing[_ ]enabled)) just before here"
89
+ PickleSanitizer.unpickle(regexp_string).should ==
90
+ 'this string contains a simple predicate capture #{capture_predicate} just before here'
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -5,6 +5,13 @@ module Cucumber
5
5
  module Formatter
6
6
  describe StepdefsJson do
7
7
  describe "extracting text from regexp" do
8
+ before do
9
+ # Pretend that unpickle will always return its argument unmodified
10
+ def PickleSanitizer.unpickle(foo)
11
+ foo
12
+ end
13
+ end
14
+
8
15
  it "should just return a simple string" do
9
16
  StepdefsJson.extract_text_from_regexp("bla").should == "bla"
10
17
  end
data/spec/spec_helper.rb CHANGED
@@ -5,5 +5,7 @@ require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
-
9
8
  end
9
+
10
+ require 'ruby-debug'
11
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuke-inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom ten Thij
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-01 00:00:00 +00:00
12
+ date: 2010-02-02 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,7 +67,9 @@ files:
67
67
  - generators/cuke_inspector_view/templates/stylesheets/cuke_inspector.css
68
68
  - generators/cuke_inspector_view/templates/stylesheets/tablesorter.css
69
69
  - lib/cuke-inspector.rb
70
+ - lib/cuke-inspector/formatter/pickle_sanitizer.rb
70
71
  - lib/cuke-inspector/formatter/stepdefs_json.rb
72
+ - spec/cuke-inspector/formatter/pickle_sanitizer_spec.rb
71
73
  - spec/cuke-inspector/formatter/stepdefs_json_spec.rb
72
74
  - spec/cuke-inspector_spec.rb
73
75
  - spec/spec.opts
@@ -101,6 +103,7 @@ signing_key:
101
103
  specification_version: 3
102
104
  summary: Inspect the steps in a cucumber suite
103
105
  test_files:
106
+ - spec/cuke-inspector/formatter/pickle_sanitizer_spec.rb
104
107
  - spec/cuke-inspector/formatter/stepdefs_json_spec.rb
105
108
  - spec/cuke-inspector_spec.rb
106
109
  - spec/spec_helper.rb