repository_steps.rb
5.16 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
Given(/^I have a sample configuration with native metrics$/) do
reading_group = FactoryGirl.create(:reading_group, id: nil)
reading = FactoryGirl.create(:reading, {id: nil, group_id: reading_group.id})
@configuration = FactoryGirl.create(:mezuro_configuration, id: nil)
metric_configuration = FactoryGirl.create(:metric_configuration,
{id: nil,
metric: FactoryGirl.build(:loc),
reading_group_id: reading_group.id,
configuration_id: @configuration.id})
range = FactoryGirl.build(:mezuro_range, {id: nil, 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,
configuration_id: @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,
configuration_id: @configuration.id, id: nil, name: name})
end
Given(/^I start to process that repository$/) do
@repository.process
end
Given(/^I wait up for a ready processing$/) do
unless Processing.has_ready_processing(@repository.id)
while(true)
if Processing.has_ready_processing(@repository.id)
break
else
sleep(10)
end
end
end
end
Given(/^I am at the New Repository page$/) do
visit new_project_repository_path(@project.id)
end
Given(/^I am at repository edit page$/) do
visit edit_project_repository_path(@repository.project_id, @repository.id)
end
Given(/^I ask for the last ready processing of the given repository$/) do
@processing = Processing.last_ready_processing_of @repository.id
end
Given(/^I ask for the module result of the given processing$/) do
@module_result = ModuleResult.find @processing.results_root_id
end
Given(/^I ask for the metric results of the given module result$/) do
@metric_results = @module_result.metric_results
end
Given(/^I see a sample metric's name$/) do
page.should have_content(@metric_results.first.metric_configuration_snapshot.metric.name)
end
When(/^I click on the sample metric's name$/) do
find_link(@metric_results.first.metric_configuration_snapshot.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 project_repository_path(@project.id, @repository.id)
end
When(/^I click on the sample child's name$/) do
click_link @module_result.children.first.module.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} = '#{val}'")
end
Then(/^I should see the sample repository name$/) do
page.should have_content(@repository.name)
end
Then(/^the field "(.*?)" should be filled with "(.*?)"$/) do |field, value|
page.find_field(field).value.should eq(value)
end
Then(/^I should see the given module result$/) do
page.should have_content(@module_result.module.name)
end
Then(/^I should see a sample child's name$/) do
page.should have_content(@module_result.children.first.module.name)
end
Then(/^I should see the given repository's content$/) do
page.should have_content(@repository.type)
page.should have_content(@repository.description)
page.should have_content(@repository.name)
page.should have_content(@repository.license)
page.should have_content(@repository.address)
page.should have_content(@configuration.name)
page.should have_content("1 day") # The given repository periodicity
end
Then(/^I should see a loaded graphic for the sample metric$/) do
page.all("canvas#container" + @metric_results.first.id.to_s)[0].should_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
page.should 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.
page.should have_content(@repository.type)
page.should have_content(@repository.description)
page.should have_content(@repository.name)
page.should have_content(@repository.license)
page.should have_content(@repository.address)
page.should have_content(@configuration.name)
end
Then(/^"(.*?)" should be less than "(.*?)"$/) do |arg1, arg2|
v1 = eval "@#{arg1}"
v2 = eval "@#{arg2}"
(v1 < v2).should be_true
end