repository_steps.rb
11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
Given(/^I have a sample configuration with native metrics but without ranges$/) do
reading_group = FactoryGirl.create(:reading_group)
reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id})
@kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
metric_configuration = FactoryGirl.create(:metric_configuration,
{metric: FactoryGirl.build(:loc),
reading_group_id: reading_group.id,
kalibro_configuration_id: @kalibro_configuration.id})
end
Given(/^I have a sample configuration with native metrics$/) do
@reading_group = FactoryGirl.create(:reading_group)
reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id})
@kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
FactoryGirl.create(:kalibro_configuration_attributes, {id: nil, user_id: @user.id, kalibro_configuration_id: @kalibro_configuration.id})
metric_configuration = FactoryGirl.create(:metric_configuration,
{metric: FactoryGirl.build(:loc),
reading_group_id: @reading_group.id,
kalibro_configuration_id: @kalibro_configuration.id})
range = FactoryGirl.build(:kalibro_range, {reading_id: reading.id, beginning: '-INF', :end => 'INF', metric_configuration_id: metric_configuration.id})
range.save
end
Given(/^I have a sample repository within the sample project$/) do
@repository = FactoryGirl.create(:repository, {project_id: @project.id,
kalibro_configuration_id: @kalibro_configuration.id, id: nil})
end
Given(/^I have a sample ruby repository within the sample project$/) do
@repository = FactoryGirl.create(:ruby_repository, {project_id: @project.id,
kalibro_configuration_id: @kalibro_configuration.id, id: nil})
end
Given(/^I have a sample repository within the sample project named "(.+)"$/) do |name|
@repository = FactoryGirl.create(:repository, {project_id: @project.id,
kalibro_configuration_id: @kalibro_configuration.id, id: nil, name: name})
end
Given(/^I have a sample repository named "(.+)"$/) do |name|
@repository = FactoryGirl.create(:repository,
project_id: nil,
kalibro_configuration_id: @kalibro_configuration.id,
id: nil,
name: name)
end
Given(/^I have a sample of an invalid repository within the sample project$/) do
@repository = FactoryGirl.create(:repository, {project_id: @project.id,
kalibro_configuration_id: @kalibro_configuration.id, id: nil, address: "https://invalidrepository.git"})
end
Given(/^I start to process that repository$/) do
@repository = @independent_repository if @repository.nil?
@repository.process
end
Given(/^I wait up for a ready processing$/) do
while !@repository.has_ready_processing
expect(@repository.last_processing_state).to_not eq "ERROR"
sleep(10)
end
end
Given(/^I wait up for the last processing to get ready$/) do
while @repository.last_processing.state != "READY"
sleep(10)
end
end
Given(/^I wait up for an error processing$/) do
while @repository.last_processing_state != "ERROR"
sleep(10)
end
end
Given(/^I am at the New Repository page$/) do
if @project
visit new_project_repository_path(project_id: @project.id)
else
visit new_repository_path
end
end
Given(/^I am at repository edit page$/) do
visit edit_repository_path(id: @repository.id)
end
Given(/^I ask for the last ready processing of the given repository$/) do
@processing = @repository.last_ready_processing
end
Given(/^I ask for the module result of the given processing$/) do
@module_result = ModuleResult.find @processing.root_module_result_id
end
Given(/^I ask for the metric results of the given module result$/) do
@metric_results = @module_result.tree_metric_results
end
Given(/^I ask for the hotspot metric results of the given module result$/) do
@metric_results = @module_result.hotspot_metric_results
end
Given(/^I own that repository$/) do
FactoryGirl.create(:repository_attributes, {repository_id: @repository.id, user_id: @user.id})
end
Given(/^I own that independent repository$/) do
FactoryGirl.create(:repository_attributes, {repository_id: @independent_repository.id, user_id: @user.id})
end
Given(/^I have a sample repository$/) do
@independent_repository = FactoryGirl.create(:ruby_repository, kalibro_configuration_id: @kalibro_configuration.id)
end
Given(/^I have a Kalibro Client GitLab repository$/) do
@independent_repository = FactoryGirl.create(:kalibro_client_gitlab_repository, kalibro_configuration_id: @kalibro_configuration.id)
end
Given(/^I am at the All Repositories page$/) do
visit repositories_path
end
Given(/^I have a sample configuration with the (\w+) native metric$/) do |metric|
metric_configuration_factory = (metric + "_metric_configuration").downcase
metric_factory = metric.downcase
@kalibro_configuration = FactoryGirl.create(:ruby_configuration)
metric_configuration = FactoryGirl.create(metric_configuration_factory.to_sym,
{id: 4,
metric: FactoryGirl.build(metric_factory.to_sym),
reading_group_id: @reading_group.id,
kalibro_configuration_id: @kalibro_configuration.id})
end
Given(/^I have a public repository named "(.*?)"$/) do |name|
@repository = FactoryGirl.create(:repository,
project_id: nil,
kalibro_configuration_id: @kalibro_configuration.id,
id: nil,
name: name)
FactoryGirl.create(:repository_attributes, {repository_id: @repository.id})
end
When(/^I click on the sample metric's name$/) do
find_link(@metric_results.first.metric_configuration.metric.name).trigger('click')
end
When(/^I set the select field "(.+)" as "(.+)"$/) do |field, text|
select text, from: field
end
When(/^I visit the repository show page$/) do
visit repository_path(id: @repository.id)
end
When(/^I click on the sample child's name$/) do
click_link @module_result.children.first.kalibro_module.short_name
end
When(/^I click the "(.*?)" h3$/) do |text|
page.find('h3', text: text).click()
end
When(/^I wait up for the ajax request$/) do
while (page.driver.network_traffic.last.response_parts.empty?) do
sleep(10)
end
end
When(/^I get the Creation Date information as "(.*?)"$/) do |variable|
val = page.find('p', text: 'Creation Date').text.match(/^Creation Date:(.*)$/).captures.first
eval ("@#{variable} = DateTime.parse('#{val}')")
end
When(/^I push some commits to the repository$/) do
request = FactoryGirl.build(:gitlab_webhook_request)
set_headers(request.headers)
page.driver.post(repository_notify_push_path(id: @repository.id), request.params)
end
When(/^I push some commits to an invalid repository$/) do
request = FactoryGirl.build(:gitlab_webhook_request)
set_headers(request.headers)
page.driver.post(repository_notify_push_path(id: 0), request.params)
end
Then(/^I should see the sample metric's name$/) do
expect(page).to have_content(@metric_results.first.metric_configuration.metric.name)
end
Then(/^I should see the ruby metric results$/) do
@metric_results.each do |metric_result|
expect(find('#metric_results')).to have_content(format('%.2f', metric_result.value))
end
end
Then(/^I should see the sample repository name$/) do
expect(page).to have_content(@repository.name)
end
Then(/^I should see the given module result$/) do
expect(page).to have_content(@module_result.kalibro_module.short_name)
end
Then(/^I should see a sample child's name$/) do
expect(page).to have_content(@module_result.children.first.kalibro_module.short_name)
end
Then(/^I should see the given repository's content$/) do
expect(page).to have_content(@repository.scm_type)
expect(page).to have_content(@repository.description)
expect(page).to have_content(@repository.name)
expect(page).to have_content(@repository.license)
expect(page).to have_content(@repository.address)
expect(page).to have_content(@kalibro_configuration.name)
expect(page).to have_content("1 day") # The given repository periodicity
end
Then(/^I should see a loaded graphic for the sample metric$/) do
expect(page.all("canvas#container" + @metric_results.first.id.to_s)[0]).to_not be_nil
end
Then(/^I wait for "(.*?)" seconds or until I see "(.*?)"$/) do |timeout, text|
start_time = Time.now
while(page.html.match(text).nil?)
break if (Time.now - start_time) >= timeout.to_f
sleep 1
end
expect(page).to have_content(text)
end
Then(/^I wait for "(.*?)" seconds$/) do |timeout|
sleep timeout.to_f
end
Then(/^I should see the saved repository's content$/) do
@repository = Repository.all.last # suposing the last repository created is the only created too.
expect(page).to have_content(@repository.scm_type)
expect(page).to have_content(@repository.description)
expect(page).to have_content(@repository.name)
expect(page).to have_content(@repository.license)
expect(page).to have_content(@repository.address)
expect(page).to have_content(@kalibro_configuration.name)
end
Then(/^"(.*?)" should be lesser than "(.*?)"$/) do |arg1, arg2|
v1 = eval "@#{arg1}"
v2 = eval "@#{arg2}"
expect(v1 < v2).to be_truthy
end
Then(/^the sample repository should be there$/) do
expect(page).to have_content(@independent_repository.name)
expect(page).to have_content(@independent_repository.description)
end
Then(/^the sample repository should not be there$/) do
expect(page).to_not have_content(@independent_repository.name)
end
Then(/^the project repository should be there$/) do
expect(page).to have_content(@repository.name)
expect(page).to have_content(@repository.description)
end
Then(/^I should be at the Repositories index$/) do
expect(page.current_path).to end_with(repositories_path) # We use end_with in order to avoid the language route
end
Then(/^I should have at least one hotspot metric result$/) do
expect(@metric_results.count).to be > 0
end
Then(/^I should see the hotspot metric results messages$/) do
@metric_results.each do |metric_result|
expect(page).to have_content(metric_result.message)
end
end
Then(/^I should see the hotspot metric results file names$/) do
@metric_results.each do |metric_result|
expect(page).to have_content(metric_result.module_result.kalibro_module.short_name)
end
end
Then(/^Mezuro should process the repository again$/) do
expect(@repository.last_processing).not_to eq(@repository.first_processing)
end
Then(/^I should get a not found error$/) do
expect(page.driver.status_code).to eq(404)
end
Then(/^I should see the correct notify push url$/) do
step "I should see \"Notify Push Url for Gitlab\""
expect(page).to have_selector("input[value=\"#{repository_notify_push_url(host: Capybara.current_session.server.host, port: Capybara.current_session.server.port, locale: :en, id: @repository.id)}\"]")
end