cuke-inspector 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/cuke-inspector.rb +4 -0
- data/lib/cuke-inspector/formatter/stepdefs_json.rb +42 -0
- data/spec/cuke-inspector/formatter/stepdefs_json_spec.rb +51 -0
- metadata +4 -1
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/cuke-inspector.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'cucumber'
|
2
|
+
require 'cucumber/formatter/usage'
|
3
|
+
|
4
|
+
module Cucumber
|
5
|
+
module Formatter
|
6
|
+
class StepdefsJson < Usage
|
7
|
+
|
8
|
+
# @stepdef_to_match is a hash with step definitions as keys and
|
9
|
+
# a list of matches as value
|
10
|
+
#
|
11
|
+
# What we want is to export is a hash with the step regexp as
|
12
|
+
# the key and a uniquified sorted list of steps as the value
|
13
|
+
def build_regexp_usage_structure
|
14
|
+
regexp_uses_hash = {}
|
15
|
+
@stepdef_to_match.to_a.each do |step_matches_pair|
|
16
|
+
step_text = StepdefsJson.extract_text_from_regexp(step_matches_pair[0].regexp_source)
|
17
|
+
matches = step_matches_pair[1].map{|m| m[:step_match].format_args}.uniq.sort
|
18
|
+
regexp_uses_hash[step_text] = matches
|
19
|
+
end
|
20
|
+
json = regexp_uses_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.extract_text_from_regexp(regexp)
|
24
|
+
prompt = '??'
|
25
|
+
regexp.sub!(/^\/\^?/, '')
|
26
|
+
regexp.sub!(/\$?\/$/, '')
|
27
|
+
regexp.gsub!(/\(\[\^\\?\"\]\*\??\)/, prompt)
|
28
|
+
regexp.gsub!('(.*)', prompt)
|
29
|
+
regexp.gsub!('\/([^\/]*)\/', "/#{prompt}/")
|
30
|
+
regexp
|
31
|
+
end
|
32
|
+
|
33
|
+
def progress(status)
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_summary(features)
|
37
|
+
add_unused_stepdefs
|
38
|
+
@io.print "cucumberStepCompletion.cucumberSteps = " + build_regexp_usage_structure.to_json
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require 'cuke-inspector/formatter/stepdefs_json'
|
3
|
+
|
4
|
+
module Cucumber
|
5
|
+
module Formatter
|
6
|
+
describe StepdefsJson do
|
7
|
+
describe "extracting text from regexp" do
|
8
|
+
it "should just return a simple string" do
|
9
|
+
StepdefsJson.extract_text_from_regexp("bla").should == "bla"
|
10
|
+
end
|
11
|
+
it "should ignore regexp markers" do
|
12
|
+
StepdefsJson.extract_text_from_regexp("/bla/").should == "bla"
|
13
|
+
end
|
14
|
+
it "should ignore the beginning of line marker" do
|
15
|
+
StepdefsJson.extract_text_from_regexp("/^bla/").should == "bla"
|
16
|
+
end
|
17
|
+
it "should ignore the end of line marker" do
|
18
|
+
StepdefsJson.extract_text_from_regexp("/bla$/").should == "bla"
|
19
|
+
end
|
20
|
+
it "should replace a non-quote capture with a prompt" do
|
21
|
+
StepdefsJson.extract_text_from_regexp('the value is "([^\"]*)"').should ==
|
22
|
+
'the value is "??"'
|
23
|
+
end
|
24
|
+
it "should replace all non-quote captures with a prompt with quote unscaped" do
|
25
|
+
StepdefsJson.extract_text_from_regexp('the value of "([^\"]*)" is "([^\"]*)"').should ==
|
26
|
+
'the value of "??" is "??"'
|
27
|
+
end
|
28
|
+
it "should replace a capture with a prompt" do
|
29
|
+
StepdefsJson.extract_text_from_regexp('the value is (.*)').should ==
|
30
|
+
'the value is ??'
|
31
|
+
end
|
32
|
+
it "should replace all captures with a prompt" do
|
33
|
+
StepdefsJson.extract_text_from_regexp('the value of (.*) is (.*)').should ==
|
34
|
+
'the value of ?? is ??'
|
35
|
+
end
|
36
|
+
it "should replace all captures with a non-greedy match" do
|
37
|
+
StepdefsJson.extract_text_from_regexp('/^I should see "([^\"]*?)" in the "([^\"]*?)"$/').should ==
|
38
|
+
'I should see "??" in the "??"'
|
39
|
+
end
|
40
|
+
it "should replace all non-quote captures with a prompt with just a quote" do
|
41
|
+
StepdefsJson.extract_text_from_regexp('the value of "([^"]*)" is "([^"]*)"').should ==
|
42
|
+
'the value of "??" is "??"'
|
43
|
+
end
|
44
|
+
it "should replace all regexp args with a regexp prompt" do
|
45
|
+
StepdefsJson.extract_text_from_regexp('it matches \/([^\/]*)\/ or \/([^\/]*)\//').should ==
|
46
|
+
'it matches /??/ or /??/'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
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.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom ten Thij
|
@@ -52,6 +52,8 @@ files:
|
|
52
52
|
- features/step_definitions/cuke-inspector_steps.rb
|
53
53
|
- features/support/env.rb
|
54
54
|
- lib/cuke-inspector.rb
|
55
|
+
- lib/cuke-inspector/formatter/stepdefs_json.rb
|
56
|
+
- spec/cuke-inspector/formatter/stepdefs_json_spec.rb
|
55
57
|
- spec/cuke-inspector_spec.rb
|
56
58
|
- spec/spec.opts
|
57
59
|
- spec/spec_helper.rb
|
@@ -84,5 +86,6 @@ signing_key:
|
|
84
86
|
specification_version: 3
|
85
87
|
summary: Inspect the steps in a cucumber suite
|
86
88
|
test_files:
|
89
|
+
- spec/cuke-inspector/formatter/stepdefs_json_spec.rb
|
87
90
|
- spec/cuke-inspector_spec.rb
|
88
91
|
- spec/spec_helper.rb
|