cucumber_monitor 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,8 @@ module CucumberMonitor
32
32
  def step_definitions_files
33
33
  collection = []
34
34
  dir_entries = Dir.entries(self.class.step_definitions_path)
35
- search_and_include_step_definitions(dir_entries)
35
+ path = self.class.step_definitions_path + "/step_definitions"
36
+ search_and_include_step_definitions(dir_entries,path)
36
37
  end
37
38
 
38
39
  def search_and_include_features(dir_entries, collection=[])
@@ -44,13 +45,13 @@ module CucumberMonitor
44
45
  collection
45
46
  end
46
47
 
47
- def search_and_include_step_definitions(dir_entries, collection=[])
48
+ def search_and_include_step_definitions(dir_entries, path, collection=[])
48
49
  dir_entries.each do |entrie|
49
50
  if entrie.include?('_step.rb')
50
51
  collection << entrie
51
52
  end
52
53
  end
53
- collection
54
+ {collection: collection, path: path}
54
55
  end
55
56
 
56
57
  def features
@@ -63,8 +64,9 @@ module CucumberMonitor
63
64
 
64
65
  def step_definitions
65
66
  collection = []
66
- step_definitions_files.each do |file|
67
- collection << CucumberMonitor::StepDefinitionFile.new(file)
67
+ step_definitions_files[:collection].each do |file|
68
+ path = "#{step_definitions_files[:path]}/#{file}"
69
+ collection << StepDefinitionFile.new(file,path)
68
70
  end
69
71
  collection
70
72
  end
@@ -85,11 +87,12 @@ module CucumberMonitor
85
87
  results = []
86
88
  step_definitions.each do |step_definition|
87
89
  step_definition.definitions.each do |definition|
88
- matcher = Amatch::Sellers.new(criteria)
89
- results << {definition: definition, score: matcher.match(definition.description)}
90
+ if definition.matcher && criteria.match(definition.matcher)
91
+ results << definition
92
+ end
90
93
  end
91
94
  end
92
- results.min {|a,b| a[:score] <=> b[:score]}[:definition] if results.any?
95
+ results.first if results.any?
93
96
  end
94
97
 
95
98
  end
@@ -4,11 +4,16 @@ module CucumberMonitor
4
4
 
5
5
  class Definition
6
6
 
7
- attr_accessor :description, :file
7
+ attr_accessor :description, :file, :line
8
8
 
9
- def initialize(description, file)
9
+ def initialize(description, file, line)
10
10
  @description = description
11
11
  @file = file
12
+ @line = line
13
+ end
14
+
15
+ def matcher
16
+ description.scan(/\/(.*)\//).flatten.first
12
17
  end
13
18
 
14
19
  def raw_content
@@ -40,6 +45,14 @@ module CucumberMonitor
40
45
  content[1..-2].collect{|c| c.strip }
41
46
  end
42
47
 
48
+ def location
49
+ "#{file.file}:#{line}"
50
+ end
51
+
52
+ def location_path
53
+ "#{file.path}:#{line}"
54
+ end
55
+
43
56
  end
44
57
 
45
58
  end
@@ -1,5 +1,3 @@
1
- require 'amatch'
2
-
3
1
  module CucumberMonitor
4
2
 
5
3
  class Step
@@ -16,7 +14,7 @@ module CucumberMonitor
16
14
  end
17
15
 
18
16
  def description_without_keyword
19
- description.gsub(/^\w+\s/,'')
17
+ description.gsub(/^\S+\s/,'')
20
18
  end
21
19
 
22
20
  def siblings_and_self
@@ -58,7 +56,29 @@ module CucumberMonitor
58
56
  end
59
57
 
60
58
  def definition
61
- Base.new.search_match(description)
59
+ Base.new.search_match(description_without_keyword)
60
+ end
61
+
62
+ def params
63
+ if implemented? && !table? && !named_params.blank?
64
+ result = description_without_keyword.match(definition.matcher)
65
+ data = {}
66
+ result.size.times do |n|
67
+ next if n == 0
68
+ data.merge!(named_params[n-1].to_sym => result[n])
69
+ end
70
+ data
71
+ end
72
+ end
73
+
74
+ def named_params
75
+ if implemented? && !table?
76
+ definition.description[/\|(.*)\|/].gsub(/\|/,'').split(",").map{|p| p.strip}
77
+ end
78
+ end
79
+
80
+ def implemented?
81
+ !definition.nil?
62
82
  end
63
83
 
64
84
  def formatted
@@ -4,14 +4,15 @@ module CucumberMonitor
4
4
 
5
5
  class StepDefinitionFile
6
6
 
7
- attr_accessor :file
7
+ attr_accessor :file, :path
8
8
 
9
9
  def self.keywords
10
10
  [I18n.t("given"), I18n.t("when"), I18n.t("then"), I18n.t("and"), I18n.t("but")].collect{|c| c[2..-1]}
11
11
  end
12
12
 
13
- def initialize(file)
13
+ def initialize(file,path)
14
14
  @file = file
15
+ @path = path
15
16
  end
16
17
 
17
18
  def name
@@ -27,9 +28,9 @@ module CucumberMonitor
27
28
 
28
29
  def definitions
29
30
  df = []
30
- lines.each do |line|
31
+ lines.each_with_index do |line,i|
31
32
  if self.class.keywords.any?{|k| line.include?(k)}
32
- df << Definition.new(line.strip,self)
33
+ df << Definition.new(line.strip,self,i+1)
33
34
  end
34
35
  end
35
36
  df
@@ -1,10 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'amatch'
4
-
5
3
  class String
6
-
7
- include Amatch
8
4
 
9
5
  def clean
10
6
  term = self.split(': ')[1]
@@ -1,3 +1,3 @@
1
1
  module CucumberMonitor
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/test/base_test.rb CHANGED
@@ -28,9 +28,10 @@ class BaseTest < ActiveSupport::TestCase
28
28
  'Then I should see "Invalid username/password"',
29
29
  'Then I should see my personal information',
30
30
  'Then I should see "Personal data successfully changed"',
31
- 'And I should see "Petter Summers"',
31
+ 'And I should see 1 username for "Petter Summers"',
32
32
  'I should see the following table:',
33
- 'Then I should see "The New York Times - Breaking News, World News & Multimedia"'
33
+ 'Then I should see "The New York Times - Breaking News, World News & Multimedia"',
34
+ 'And I should see 1 occurrence of "New York Times Company"'
34
35
  ]
35
36
 
36
37
  assert_equal steps, @cucumber.search(term).map(&:description)
@@ -0,0 +1,189 @@
1
+ require 'test_helper'
2
+
3
+ def definition_sample_codes
4
+ [
5
+ "User.create(email: email, password: password)",
6
+ "visit new_user_session_url",
7
+ "fill_in 'Email', with: email",
8
+ "fill_in 'Password', with: password",
9
+ "fill_in('Email', with: email)",
10
+ "click_button 'Access'",
11
+ "click_link 'Logout'",
12
+ "assert_equal new_user_session_url, current_url",
13
+ "assert_equal user_root_path, current_path",
14
+ "assert page.has_content?(string)",
15
+ "sign_in(:user, User.make!)"
16
+ ]
17
+ end
18
+
19
+ def has_parentheses?(line)
20
+ line.scan(/\((.*)\)/).flatten.any?
21
+ end
22
+
23
+ def first_method_without_parentheses?(line)
24
+ line.scan(/\w+\s/).any?
25
+ end
26
+
27
+ def between_parentheses(line)
28
+ line.scan(/\((.*)\)/).flatten.first
29
+ end
30
+
31
+ def has_comma?(line)
32
+ line.scan(/,/).any?
33
+ end
34
+
35
+ def between_comma(line)
36
+ line.split(",").map{|o| o.strip}
37
+ end
38
+
39
+ def has_new_hash_key?(line)
40
+ line.scan(/\w+:/).any?
41
+ end
42
+
43
+ def new_hash_keys(line)
44
+ result = []
45
+ if line.kind_of?(Array)
46
+ line.each do |l|
47
+ result << l.scan(/\w+:/).map{|l| l.strip.gsub(/:/,'')}
48
+ end
49
+ else
50
+ result << line.scan(/\w+:/).map{|l| l.strip.gsub(/:/,'')}
51
+ end
52
+ result.flatten
53
+ end
54
+
55
+ def new_hash_values(line)
56
+ result = []
57
+ if line.kind_of?(Array)
58
+ line.each do |l|
59
+ result << l.split(/\w+:/).map{|o| o.strip.gsub(/,/,"")}.reject{|s| s.empty?}
60
+ end
61
+ else
62
+ result << line.split(/\w+:/).map{|l| l.strip.gsub(/,/,"")}.reject{|s| s.empty?}
63
+ end
64
+ result.flatten
65
+ end
66
+
67
+ def new_hash_keys_and_values(line)
68
+ result = {}
69
+ keys = new_hash_keys(line)
70
+ values = new_hash_values(line)
71
+ if keys.size == values.size
72
+ keys.each_with_index do |k,i|
73
+ result.merge!({k.to_sym => values[i]})
74
+ end
75
+ end
76
+ result
77
+ end
78
+
79
+ def inspect_line(line)
80
+ result = {}
81
+ if !first_method_without_parentheses?(line) && !has_new_hash_key?(line)
82
+
83
+ lines = line.split(/\((.*)\)/)
84
+ result.merge!(method: lines[0])
85
+ rest = between_comma(lines[1..-1].first)
86
+ rest.each_with_index do |l,i|
87
+ key_name = "param_#{i+1}"
88
+ result.merge!({key_name.to_sym => l})
89
+ end
90
+ elsif first_method_without_parentheses?(line) && !has_new_hash_key?(line)
91
+
92
+ lines = line.split(" ")
93
+ result.merge!(method: lines[0])
94
+ result.merge!(param_1: lines[1].gsub(/,/,"")) if lines[1]
95
+
96
+ rest = lines[2..-1].join(" ")
97
+ if !rest.blank? && !has_comma?(rest) && has_new_hash_key?(rest)
98
+
99
+ result.merge!(options: new_hash_keys_and_values(rest))
100
+ else
101
+ lines[2..-1].each_with_index do |l,i|
102
+ key_name = has_new_hash_key?(l) ? :options : "param_#{i+2}"
103
+
104
+ if key_name == :options
105
+ value = new_hash_keys_and_values(l)
106
+ else
107
+ value = l
108
+ end
109
+ result.merge!({key_name.to_sym => value})
110
+ end
111
+ end
112
+ elsif first_method_without_parentheses?(line) && has_new_hash_key?(line)
113
+ lines = line.split(" ")
114
+ result.merge!(method: lines[0])
115
+ rest = lines[1..-1].join(" ")
116
+ if new_hash_keys_and_values(rest).blank? && has_comma?(rest)
117
+ param_data = between_comma(rest)
118
+ param_data.each_with_index do |p,i|
119
+ key_name = "param_#{i+1}"
120
+ value = p
121
+ if has_new_hash_key?(value)
122
+ result.merge!(options: new_hash_keys_and_values(value))
123
+ else
124
+ result.merge!({key_name.to_sym => value})
125
+ end
126
+ end
127
+ end
128
+ elsif !first_method_without_parentheses?(line) && has_parentheses?(line)
129
+
130
+ lines = line.split(/\((.*)\)/)
131
+ result.merge!(method: lines[0])
132
+ within_parentheses = between_parentheses(line)
133
+ if new_hash_keys_and_values(within_parentheses).blank? && has_comma?(within_parentheses)
134
+ param_data = between_comma(within_parentheses)
135
+ param_data.each_with_index do |p,i|
136
+ key_name = "param_#{i+1}"
137
+ value = p
138
+ if has_new_hash_key?(value)
139
+ result.merge!(options: new_hash_keys_and_values(value))
140
+ else
141
+ result.merge!({key_name.to_sym => value})
142
+ end
143
+ end
144
+ elsif !new_hash_keys_and_values(within_parentheses).blank?
145
+ result.merge!(param_1: new_hash_keys_and_values(within_parentheses))
146
+ end
147
+ end
148
+ result
149
+ end
150
+
151
+ class DefinitionTest < ActiveSupport::TestCase
152
+
153
+ test "should return identify params from code" do
154
+
155
+ line_1 = {:method=>"User.create", :param_1=>{:email=>"email", :password=>"password"}}
156
+ assert_equal line_1, inspect_line(definition_sample_codes[0])
157
+
158
+ line_2 = {:method=>"visit", :param_1=>"new_user_session_url"}
159
+ assert_equal line_2, inspect_line(definition_sample_codes[1])
160
+
161
+ line_3 = {:method=>"fill_in", :param_1=>"'Email'", :options=>{:with=>"email"}}
162
+ assert_equal line_3, inspect_line(definition_sample_codes[2])
163
+
164
+ line_4 = {:method=>"fill_in", :param_1=>"'Password'", :options=>{:with=>"password"}}
165
+ assert_equal line_4, inspect_line(definition_sample_codes[3])
166
+
167
+ line_5 = {:method=>"fill_in", :param_1=>"'Email'", :options=>{:with=>"email"}}
168
+ assert_equal line_5, inspect_line(definition_sample_codes[4])
169
+
170
+ line_6 = {:method=>"click_button", :param_1=>"'Access'"}
171
+ assert_equal line_6, inspect_line(definition_sample_codes[5])
172
+
173
+ line_7 = {:method=>"click_link", :param_1=>"'Logout'"}
174
+ assert_equal line_7, inspect_line(definition_sample_codes[6])
175
+
176
+ line_8 = {:method=>"assert_equal", :param_1=>"new_user_session_url", :param_2=>"current_url"}
177
+ assert_equal line_8, inspect_line(definition_sample_codes[7])
178
+
179
+ line_9 = {:method=>"assert_equal", :param_1=>"user_root_path", :param_2=>"current_path"}
180
+ assert_equal line_9, inspect_line(definition_sample_codes[8])
181
+
182
+ line_10 = {:method=>"assert", :param_1=>"page.has_content?(string)"}
183
+ assert_equal line_10, inspect_line(definition_sample_codes[9])
184
+
185
+ line_11 = {:method=>"sign_in", :param_1=>":user", :param_2=>"User.make!"}
186
+ assert_equal line_11, inspect_line(definition_sample_codes[10])
187
+
188
+ end
189
+ end
File without changes
@@ -11,7 +11,7 @@ Feature: Change personal data
11
11
  And I fill in "Name" with "Peter Summers"
12
12
  And I press "Save"
13
13
  Then I should see "Personal data successfully changed"
14
- And I should see "Petter Summers"
14
+ And I should see 1 username for "Petter Summers"
15
15
 
16
16
  Scenario: Listing my roles
17
17
  When I access the system
@@ -3,4 +3,5 @@ Feature: Searching on Google
3
3
  Scenario: Search for New York Times
4
4
  Given I am at the google page
5
5
  When I search for "New York Times"
6
- Then I should see "The New York Times - Breaking News, World News & Multimedia"
6
+ Then I should see "The New York Times - Breaking News, World News & Multimedia"
7
+ And I should see 1 occurrence of "New York Times Company"
@@ -4,8 +4,13 @@ end
4
4
 
5
5
  When /^I search for "(.*?)"$/ do |term|
6
6
  fill_in 'gbqfq', with: term
7
+ click_on 'gbqfba'
7
8
  end
8
9
 
9
10
  Then /^I should see "(.*?)"$/ do |string|
10
- page.has_content?(string)
11
+ assert page.has_content?(string)
12
+ end
13
+
14
+ Then /^I should see (\d+) occurrence of "(.*?)"$/ do |number, string|
15
+ assert_equal number.to_i, page.all('a', text: string).count
11
16
  end
@@ -1,48 +0,0 @@
1
- Connecting to database specified by database.yml
2
- Connecting to database specified by database.yml
3
- Connecting to database specified by database.yml
4
- Connecting to database specified by database.yml
5
- Connecting to database specified by database.yml
6
- Connecting to database specified by database.yml
7
- Connecting to database specified by database.yml
8
- Connecting to database specified by database.yml
9
- Connecting to database specified by database.yml
10
- Connecting to database specified by database.yml
11
- Connecting to database specified by database.yml
12
- Connecting to database specified by database.yml
13
- Connecting to database specified by database.yml
14
- Connecting to database specified by database.yml
15
- Connecting to database specified by database.yml
16
- Connecting to database specified by database.yml
17
- Connecting to database specified by database.yml
18
- Connecting to database specified by database.yml
19
- Connecting to database specified by database.yml
20
- Connecting to database specified by database.yml
21
- Connecting to database specified by database.yml
22
- Connecting to database specified by database.yml
23
- Connecting to database specified by database.yml
24
- Connecting to database specified by database.yml
25
- Connecting to database specified by database.yml
26
- Connecting to database specified by database.yml
27
- Connecting to database specified by database.yml
28
- Connecting to database specified by database.yml
29
- Connecting to database specified by database.yml
30
- Connecting to database specified by database.yml
31
- Connecting to database specified by database.yml
32
- Connecting to database specified by database.yml
33
- Connecting to database specified by database.yml
34
- Connecting to database specified by database.yml
35
- Connecting to database specified by database.yml
36
- Connecting to database specified by database.yml
37
- Connecting to database specified by database.yml
38
- Connecting to database specified by database.yml
39
- Connecting to database specified by database.yml
40
- Connecting to database specified by database.yml
41
- Connecting to database specified by database.yml
42
- Connecting to database specified by database.yml
43
- Connecting to database specified by database.yml
44
- Connecting to database specified by database.yml
45
- Connecting to database specified by database.yml
46
- Connecting to database specified by database.yml
47
- Connecting to database specified by database.yml
48
- Connecting to database specified by database.yml