FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
github_cli/spec/github_cli/config_spec.rb at master · danieldeb/github_cli · GitHub
danieldeb
/
github_cli
Public
forked from
piotrmurach/github_cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
github_cli
/
spec
/
github_cli
/
config_spec.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
124 lines (102 loc) · 3.1 KB
Breadcrumbs
github_cli
/
spec
/
github_cli
/
config_spec.rb
Copy path
File metadata and controls
124 lines (102 loc) · 3.1 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
# encoding: utf-8
require
'spec_helper'
describe
GithubCLI
::
Config
do
let
(
:filename
)
{
'.githubrc'
}
let
(
:path
)
{
"/users/
#{
filename
}
"
}
let
(
:config_name
)
{
'simple_config'
}
let
(
:config
)
{
described_class
.
new
fixture_path
}
before
do
config
.
stub
(
:global_options_file
)
{
fixture_path
(
config_name
)
}
File
.
stub
(
:open
)
{
YAML
.
load
fixture
(
'simple_config'
)
}
end
it
'returns config type'
do
GithubCLI
.
config
=
GithubCLI
::
Config
.
new
filename
GithubCLI
.
config
.
should
be_a
GithubCLI
::
Config
end
context
'array access'
do
it
'returns value for the key'
do
expect
(
config
[
'user.login'
]
)
.
to
eql
(
'login'
)
end
it
'searches in commands'
do
expect
(
config
[
'issue.list'
]
)
.
to
eql
(
{
'title'
=>
'ticket'
}
)
end
it
'returns nil for missing key'
do
expect
(
config
[
'non-existent'
]
)
.
to
be_nil
end
end
context
'#fetch'
do
it
'finds value'
do
expect
(
config
.
fetch
(
'user.token'
)
)
.
to
eql
(
'ad7f9asdf97as98df7as9fd7'
)
end
it
'uses default value'
do
expect
(
config
.
fetch
(
'unkown'
,
11
)
)
.
to
eql
(
11
)
end
it
'raises error'
do
expect
{
config
.
fetch
(
'unkown'
)
}
.
to
raise_error
(
IndexError
)
end
end
context
'#pretty'
do
it
'collects options into array'
do
options
=
{
'user.token'
=>
'abc123'
}
config
.
stub
(
:all
)
.
and_return
options
expect
(
config
.
pretty
)
.
to
eql
(
[
[
'user.token'
,
'abc123'
]
]
)
end
it
'marks nil option value as undefined'
do
options
=
{
'option'
=>
nil
}
config
.
stub
(
:all
)
.
and_return
options
expect
(
config
.
pretty
)
.
to
eql
(
[
[
'option'
,
'UNDEFINED'
]
]
)
end
end
context
'#save'
do
let
(
:attrs
)
{
{
}
}
let
(
:cmd
)
{
stub
(
:cmd
,
:namespace
=>
'repo'
,
:name
=>
'create'
)
}
before
do
GithubCLI
::
Command
.
stub
(
:all
)
{
[
cmd
]
}
File
.
stub
(
:open
)
end
it
'saves config to yaml format'
do
File
.
stub
(
:open
)
.
and_yield
filename
YAML
.
should_receive
(
:dump
)
.
with
(
attrs
,
filename
)
config
.
save
attrs
end
it
'retrieves api commands'
do
config
.
save
attrs
attrs
.
should
have_key
'commands.repo.create'
end
it
'skips commands with no namespace'
do
cmd
.
stub
(
:namespace
)
{
''
}
config
.
save
attrs
attrs
.
keys
.
should
be_empty
end
it
'skips help commands'
do
cmd
.
stub
(
:name
)
{
'help'
}
config
.
save
attrs
attrs
.
keys
.
should
be_empty
end
end
context
"#load"
do
it
"loads empty hash if config doesn't exist"
do
File
.
stub
(
:exists?
)
{
false
}
config
.
load
==
{
}
end
it
"loads yaml config"
do
File
.
stub
(
:exists?
)
{
true
}
File
.
stub
(
:open
)
.
and_yield
filename
YAML
.
should_receive
(
:load
)
.
with
(
filename
)
config
.
load
end
end
context
"#path"
do
it
'looks for local config file'
do
root
=
"/users/"
File
.
stub
(
:exists?
)
{
true
}
config
=
GithubCLI
::
Config
.
new
root
config
.
path
.
to_s
.
should
==
"
#{
root
}
/.githubrc"
end
it
'reads global file if local is missing '
do
File
.
stub
(
:exists?
)
{
false
}
config
=
GithubCLI
::
Config
.
new
path
config
.
path
.
to_s
.
should
==
"
#{
ENV
[
'HOME'
]
}
/
#{
filename
}
"
end
end
end
# GithubCLI::Config
Back
|
FazBrowse Home
|
New Git URL