FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tip4commit/features/step_definitions/common.rb at master · tip4commit/tip4commit · GitHub
tip4commit
tip4commit
Repository navigation
Code
Issues
54
(54)
Pull requests
13
(13)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
tip4commit
/
features
/
step_definitions
/
common.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
176 lines (140 loc) · 4.91 KB
Breadcrumbs
tip4commit
/
features
/
step_definitions
/
common.rb
Copy path
File metadata and controls
176 lines (140 loc) · 4.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# frozen_string_literal: true
Before
do
ActionMailer
::
Base
.
deliveries
.
clear
# mock branches method to prevent api call
Project
.
any_instance
.
stub
(
:branches
)
.
and_return
(
%w[
master
]
)
@default_tip
=
CONFIG
[
'tip'
]
@default_our_fee
=
CONFIG
[
'our_fee'
]
@default_min_tip
=
CONFIG
[
'min_tip'
]
end
After
do
|
_scenario
|
OmniAuth
.
config
.
test_mode
=
false
CONFIG
[
'tip'
]
=
@default_tip
CONFIG
[
'our_fee'
]
=
@default_our_fee
CONFIG
[
'min_tip'
]
=
@default_min_tip
# Cucumber.wants_to_quit = true if scenario.status.eql? :failed
# Cucumber.wants_to_quit = true if scenario.status.eql? :undefined
# Cucumber.wants_to_quit = true if scenario.status.eql? :pending
end
def
mock_github_user
(
nickname
)
email
=
"
#{
nickname
.
parameterize
}
@example.com"
OmniAuth
.
config
.
test_mode
=
true
OmniAuth
.
config
.
mock_auth
[
:github
]
=
{
'info'
=>
{
'nickname'
=>
nickname
,
'primary_email'
=>
email
,
'verified_emails'
=>
[
email
]
}
}
.
to_ostruct
step
"a developer named
\"
#{
nickname
}
\"
exists without a bitcoin address"
end
Given
(
/^a GitHub user named "(.*?)" exists$/
)
do
|
nickname
|
mock_github_user
nickname
end
Given
(
/^I'm signed in as "(.*?)"$/
)
do
|
nickname
|
mock_github_user
nickname
visit
root_path
first
(
:link
,
'Sign in'
)
.
click
click_on
'Sign in with Github'
page
.
should
have_content
(
'Successfully authenticated'
)
end
Given
(
/^I'm not signed in$/
)
do
visit
root_path
if
page
.
has_content?
(
'Sign out'
)
click_on
'Sign out'
page
.
should
have_content
(
'Signed out successfully'
)
else
page
.
should
have_content
(
'Sign in'
)
end
OmniAuth
.
config
.
test_mode
=
false
end
Given
(
/^I sign in as "(.*?)"$/
)
{
|
nickname
|
step
"I'm signed in as
\"
#{
nickname
}
\"
"
}
Given
(
/^I sign out$/
)
{
step
"I'm not signed in"
}
def
parse_path_from_page_string
(
page_string
)
path
=
nil
# explicit cases
# e.g. "a-user/a-project github-project edit"
# e.g. "a-user user edit"
tokens
=
page_string
.
split
name
=
tokens
[
0
]
model
=
tokens
[
1
]
action
=
tokens
[
2
]
||
''
# '' => 'show'
is_user
=
model
.
eql?
'user'
is_project
=
%w[
github-project
bitbucket-project
]
.
include?
model
if
is_project
projects_paths
=
[
''
,
'edit'
,
'decide_tip_amounts'
,
'tips'
,
'deposits'
]
is_valid_path
=
projects_paths
.
include?
action
service
=
model
.
split
(
'-'
)
.
first
path
=
"/
#{
service
}
/
#{
name
}
/
#{
action
}
"
if
is_valid_path
elsif
is_user
user_paths
=
[
''
,
'tips'
]
is_valid_path
=
user_paths
.
include?
action
path
=
"/users/
#{
name
}
/
#{
action
}
"
if
is_valid_path
# TODO: nyi
# implicit cases
else
case
page_string
when
'home'
then
path
=
root_path
when
'sign_up'
then
path
=
new_user_registration_path
when
'sign_in'
then
path
=
new_user_session_path
when
'users'
then
path
=
users_path
when
'projects'
then
path
=
projects_path
when
'search'
then
path
=
search_projects_path
when
'tips'
then
path
=
tips_path
when
'deposits'
then
path
=
deposits_path
when
'withdrawals'
then
path
=
withdrawals_path
end
end
path
||
page_string
end
Given
(
/^I visit the "(.*?)" page$/
)
do
|
page_string
|
visit
parse_path_from_page_string
(
page_string
)
end
Given
(
/^I browse to the explicit path "(.*?)"$/
)
do
|
url
|
visit
url
end
Then
(
/^I should be on the "(.*?)" page$/
)
do
|
page_string
|
expected
=
parse_path_from_page_string
(
page_string
)
actual
=
CGI
.
unescape
(
page
.
current_path
)
expected
=
expected
.
chop
if
(
expected
.
end_with?
'/'
)
&&
(
expected
.
size
>
1
)
actual
=
actual
.
chop
if
(
actual
.
end_with?
'/'
)
&&
(
actual
.
size
>
1
)
actual
.
should
eq
expected
end
def
find_element
(
node_name
)
case
node_name
when
'header'
then
page
.
find
'.masthead'
end
end
Given
(
/^I click "(.*?)"$/
)
do
|
arg1
|
click_on
(
arg1
)
end
Given
(
/^I click "(.*?)" within the "(.*?)" area$/
)
do
|
link_text
,
node_name
|
within
(
find_element
(
node_name
)
)
{
click_on
link_text
}
end
Given
(
/^I check "(.*?)"$/
)
do
|
arg1
|
check
(
arg1
)
end
Then
(
/^I should see "(.*?)"$/
)
do
|
arg1
|
page
.
should
have_content
(
arg1
.
gsub
(
'\n'
,
"
\n
"
)
)
end
Then
(
/^I should not see "(.*?)"$/
)
do
|
arg1
|
page
.
should
have_no_content
(
arg1
)
end
Given
(
/^I fill "(.*?)" with:$/
)
do
|
arg1
,
string
|
fill_in
arg1
,
with
:
string
end
Given
(
/^I fill "(.*?)" with: "(.*?)"$/
)
do
|
text_field
,
string
|
fill_in
text_field
,
with
:
string
end
Then
(
/^there should be (
\d
+) email sent$/
)
do
|
arg1
|
ActionMailer
::
Base
.
deliveries
.
size
.
should
eq
(
arg1
.
to_i
)
end
When
(
/^the email counters are reset$/
)
do
ActionMailer
::
Base
.
deliveries
.
clear
end
When
(
/^I confirm the email address: "(.*?)"$/
)
do
|
email
|
mail
=
ActionMailer
::
Base
.
deliveries
.
select
{
|
ea
|
ea
.
to
.
first
.
eql?
email
}
.
first
mail_body
=
mail
.
body
.
raw_source
token
=
mail_body
.
split
(
'?confirmation_token='
)
[
1
]
.
split
(
'">Confirm my account'
)
.
first
visit
"/users/confirmation?confirmation_token=
#{
token
}
"
end
Then
(
/^some magic stuff happens in the cloud$/
)
{
true
}
Back
|
FazBrowse Home
|
New Git URL