aboutsummaryrefslogtreecommitdiffhomepage
path: root/test.bats
blob: dd0f54c239873631b7fcf7ac1fffa8b4d2d81e6b (plain)
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
#!/usr/bin/env bats

export TOOL_NAME='gist'
export GIST_USER='phamhsieh'
export GIST_API_TOKEN='dd43dc9949a5b4a1d6c7''b779f13af357282016e4'

@test "Testing ${TOOL_NAME} tool" {
  echo "${TOOL_NAME}"
}

@test "The help command should print usage" {
  run ./gist help

  [[ "$status" -eq 0 ]]
  [[ "${lines[0]}" = "${TOOL_NAME}" ]]
}

@test "Use config command to add configuarion for user" {
  run ./gist config user ${GIST_USER}
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "user='${GIST_USER}'" ]
}

@test "Use config command to add configuarion for token" {
  run ./gist config token ${GIST_API_TOKEN}
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "token=${GIST_API_TOKEN}" ]
}

@test "The new command should create a new public gist with gist command" {
  hint=false run ./gist new --file gist --desc 'Manage gist like a pro' gist
  [ "$status" -eq 0 ]
  [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]]
}

@test "The fetch command should fetch user gists" {
  hint=false run ./gist fetch
  [ "$status" -eq 0 ]
  [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]]
}

@test "The fetch command should fetch starred gists" {
  hint=false run ./gist fetch star
  [ "$status" -eq 0 ]
  echo ${lines[-1]}
  [[ "${lines[-1]}" =~ (Not a single valid gist|^ *s[0-9]+ +https://gist.github.com/[0-9a-z]+) ]]
}

@test "No arguments prints the list of gists" {
  hint=false run ./gist 
  [ "$status" -eq 0 ]
  [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]]
}

@test "Specify an index to return the path of cloned repo" {
  run ./gist 1 --no-action
  [ "$status" -eq 0 ]
  [[ "${lines[-1]}" =~ (${HOME}/gist/[0-9a-z]+) ]]
}

@test "The edit command should modify the description of a gist" {
  ./gist edit 1 "Modified description"
  run ./gist detail 1
  [ "$status" -eq 0 ]
  [[ "${lines[0]}" =~ (Modified description$) ]]
}

@test "The delete command should delete specified gists" {
  run ./gist delete 1 --force
  [ "$status" -eq 0 ]
}

@test "The user command should get the list of public gists from a user" {
  hint=false run ./gist user defunkt
  [ "$status" -eq 0 ]
  [[ "${lines[0]}" =~ (https://gist.github.com/[0-9a-z]+ defunkt) ]]
}