ribose-cli 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Ribose Space" do
4
+ describe "Listing spaces" do
5
+ context "default option" do
6
+ it "retrieves user spaces in default format" do
7
+ command = %w(space list)
8
+
9
+ stub_ribose_space_list_api
10
+ output = capture_stdout { Ribose::CLI.start(command) }
11
+
12
+ expect(output).to match(/Work/)
13
+ expect(output).to match(/0e8d5c16-1a31-4df9-83d9-eeaa374d5adc/)
14
+ end
15
+ end
16
+
17
+ context "with format option" do
18
+ it "retrieves user spaces in specified format" do
19
+ command = %w(space list --format json)
20
+
21
+ stub_ribose_space_list_api
22
+ output = capture_stdout { Ribose::CLI.start(command) }
23
+
24
+ expect(output).to match(/"name":"Work"/)
25
+ expect(output).to match(/"id":"0e8d5c16-1a31-4df9-83d9-eeaa374d5adc"/)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "Retrieving a space" do
31
+ context "with default options" do
32
+ it "displays the space in tabular format" do
33
+ command = %w(space show --space-id 123456789)
34
+
35
+ stub_ribose_space_fetch_api(123_456_789)
36
+ output = capture_stdout { Ribose::CLI.start(command) }
37
+
38
+ expect(output).to match(/name | Work/)
39
+ expect(output).to match(/visibility | invisible/)
40
+ end
41
+ end
42
+
43
+ context "with format option" do
44
+ it "displays as the space in supported format" do
45
+ command = %w(space show --space-id 123456789 --format json)
46
+
47
+ stub_ribose_space_fetch_api(123_456_789)
48
+ output = capture_stdout { Ribose::CLI.start(command) }
49
+
50
+ expect(output).to match(/"name":"Work"/)
51
+ expect(output).to match(/"id":"0e8d5c16-1a31-4df9-83d9-eeaa374d5adc"/)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "Adding a new space" do
57
+ it "allows us to add a new space" do
58
+ command = %W(
59
+ space add
60
+ --name #{space.name}
61
+ --access #{space.access}
62
+ --description #{space.description}
63
+ --category-id #{space.category_id}
64
+ )
65
+
66
+ stub_ribose_space_create_api(space.to_h)
67
+ output = capture_stdout { Ribose::CLI.start(command) }
68
+
69
+ expect(output).to match(/New Space created!/)
70
+ expect(output).to match(/Id: 6b2741ad-4cde-4b4d-af3b-a162a4f6bc25/)
71
+ end
72
+ end
73
+
74
+ describe "Updating a space" do
75
+ it "updates an existing user space" do
76
+ command = %W(
77
+ space update
78
+ --space-id 123456789
79
+ --access #{space.access}
80
+ --description #{space.description}
81
+ --category-id #{space.category_id}
82
+ --name #{space.name}
83
+ )
84
+
85
+ stub_ribose_space_update_api(123456789, space.to_h)
86
+ output = capture_stdout { Ribose::CLI.start(command) }
87
+
88
+ expect(output).to match(/Your space has been updated!/)
89
+ end
90
+ end
91
+
92
+ describe "Remove an existing space" do
93
+ it "removes an existing space" do
94
+ space_uuid = "6b2741ad-4cde-4b4d-af3b-a162a4f6bc25"
95
+ command = %W(space remove --space-id #{space_uuid} --confirmation 12345)
96
+
97
+ stub_ribose_space_remove_api(space_uuid, password_confirmation: "12345")
98
+ output = capture_stdout { Ribose::CLI.start(command) }
99
+
100
+ expect(output).to match(/The Sapce has been removed!/)
101
+ end
102
+ end
103
+
104
+ def space
105
+ @space ||= OpenStruct.new(
106
+ access: "public",
107
+ description: "Space description",
108
+ category_id: "12",
109
+ name: "CLI Space",
110
+ )
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ :api_token: SECRET_TOKEN
3
+ :user_email: user-one@example.com
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+ require "ribose/cli/rcfile"
3
+
4
+ RSpec.describe Ribose::CLI::RCFile do
5
+ describe ".set" do
6
+ it "allows us to set API Token and User Email" do
7
+ api_token = "SECRET_TOKEN"
8
+ user_email = "user-one@example.com"
9
+ allow(File).to receive(:expand_path).and_return(fixtures_path)
10
+
11
+ Ribose::CLI::RCFile.set(token: api_token, email: user_email)
12
+
13
+ expect(Ribose::CLI::RCFile.api_token).to eq(api_token)
14
+ expect(Ribose::CLI::RCFile.user_email).to eq(user_email)
15
+ end
16
+ end
17
+
18
+ def fixtures_path
19
+ File.expand_path("../../../fixtures", __FILE__)
20
+ end
21
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,22 @@
1
- require "bundler/setup"
1
+ require "webmock/rspec"
2
2
  require "ribose/cli"
3
+ require "ribose/rspec"
4
+
5
+ Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
3
6
 
4
7
  RSpec.configure do |config|
5
8
  # Enable flags like --only-failures and --next-failure
6
9
  config.example_status_persistence_file_path = ".rspec_status"
10
+ config.include Ribose::ConsoleHelper
7
11
 
8
12
  config.expect_with :rspec do |c|
9
13
  c.syntax = :expect
10
14
  end
15
+
16
+ config.before :all do
17
+ Ribose.configure do |ribose_config|
18
+ ribose_config.api_token = ENV["RIBOSE_API_TOKEN"] || "SECRET_TOKEN"
19
+ ribose_config.user_email = ENV["RIBOSE_USER_EMAIL"] || "user@ribose.com"
20
+ end
21
+ end
11
22
  end
@@ -0,0 +1,29 @@
1
+ module Ribose
2
+ module ConsoleHelper
3
+ def capture_stdout(&_block)
4
+ original_stdout = $stdout
5
+ $stdout = fake = StringIO.new
6
+
7
+ begin
8
+ yield
9
+ ensure
10
+ $stdout = original_stdout
11
+ end
12
+
13
+ fake.string
14
+ end
15
+
16
+ def capture_stderr(&_block)
17
+ original_stderr = $stderr
18
+ $stderr = fake = StringIO.new
19
+
20
+ begin
21
+ yield
22
+ ensure
23
+ $stderr = original_stderr
24
+ end
25
+
26
+ fake.string
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ribose-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-08 00:00:00.000000000 Z
11
+ date: 2018-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: ribose
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,10 +94,25 @@ dependencies:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
55
111
  description: The Ribose CLI
56
112
  email:
57
113
  - operations@ribose.com
58
- executables: []
114
+ executables:
115
+ - ribose
59
116
  extensions: []
60
117
  extra_rdoc_files: []
61
118
  files:
@@ -69,13 +126,38 @@ files:
69
126
  - README.md
70
127
  - Rakefile
71
128
  - bin/console
129
+ - bin/ribose
72
130
  - bin/rspec
73
131
  - bin/setup
74
132
  - lib/ribose/cli.rb
133
+ - lib/ribose/cli/auth.rb
134
+ - lib/ribose/cli/command.rb
135
+ - lib/ribose/cli/commands/base.rb
136
+ - lib/ribose/cli/commands/conversation.rb
137
+ - lib/ribose/cli/commands/file.rb
138
+ - lib/ribose/cli/commands/invitation.rb
139
+ - lib/ribose/cli/commands/join_space.rb
140
+ - lib/ribose/cli/commands/member.rb
141
+ - lib/ribose/cli/commands/message.rb
142
+ - lib/ribose/cli/commands/note.rb
143
+ - lib/ribose/cli/commands/space.rb
144
+ - lib/ribose/cli/rcfile.rb
145
+ - lib/ribose/cli/util.rb
75
146
  - lib/ribose/cli/version.rb
76
147
  - ribose-cli.gemspec
77
- - spec/ribose/cli_spec.rb
148
+ - spec/acceptance/config_spec.rb
149
+ - spec/acceptance/conversation_spec.rb
150
+ - spec/acceptance/file_spec.rb
151
+ - spec/acceptance/invitation_spec.rb
152
+ - spec/acceptance/join_space_spec.rb
153
+ - spec/acceptance/member_spec.rb
154
+ - spec/acceptance/message_spec.rb
155
+ - spec/acceptance/note_spec.rb
156
+ - spec/acceptance/space_spec.rb
157
+ - spec/fixtures/.riboserc
158
+ - spec/ribose/cli/rcfile_spec.rb
78
159
  - spec/spec_helper.rb
160
+ - spec/support/console_helper.rb
79
161
  homepage: https://github.com/riboseinc/ribose-cli
80
162
  licenses:
81
163
  - MIT
@@ -96,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
178
  version: '0'
97
179
  requirements: []
98
180
  rubyforge_project:
99
- rubygems_version: 2.5.2
181
+ rubygems_version: 2.7.7
100
182
  signing_key:
101
183
  specification_version: 4
102
184
  summary: The Ribose CLI
@@ -1,4 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Ribose::Cli do
4
- end