hackpad-cli 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75ec97eebdcae4ec244fa66f3275faa0b7f0db0c
4
- data.tar.gz: 8190edde668cfaf92831a30ca7b5ce83d77228e3
3
+ metadata.gz: 5037a0a37741a8faadffe8bcf9a879f9cdebc73d
4
+ data.tar.gz: 13b30296a3f1bba92040cc4fd0938a2ccff19665
5
5
  SHA512:
6
- metadata.gz: e44e5752085dc49e72dff125796dc0ece1b44538927020d092f032552c228d35d2dc3c301b79b6f2decc4eff6dc1d6cf50645745699770bde3be2c8810eb6198
7
- data.tar.gz: 4b7d16c5a5bd6055cbbb291f6e8b7fc484cdafd2dfa996f52bae62443ec06b2ff5a140ca787daf7ba7539039f60a0b9b5b859c0647f95285b1d3a025f1258e33
6
+ metadata.gz: bcc048e283ead0d1eff603cab042d039aeef5c501c86599645eea8215c45a2144a2dc18d13cb4303de5d27f3ce6c8e2fd6a9f14b144472a4b5309ce02d30e575
7
+ data.tar.gz: 35fe21d9f7ffee3887de231c4e736affbf5a686ff985d10f979b5897f036bc4cb3acfd8864e91ed957f16fff3edf58cb3e8cf200fa9234973b5f594ef77e4cd6
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  Hackpad-cli changelog
2
2
  =====================
3
3
 
4
+ v0.1.1 - 2014-05-25
5
+ -------------------
6
+
7
+ - add a `default` command to switch workspaces
8
+ - renamed `check` into `getnew` to make it clearer what it does
9
+ - switch from colorize to paint gems (monkey patch of colorize was itchy)
10
+ - switch the prompt code to another gem called cliprompt
11
+ - add a command `workspaces` to list workspaces
12
+ - move config file from ~/.hackpad-cli/default.yml to ~/.hackpad-cli/default/config.yml
13
+
4
14
  v0.1.0 - 2014-05-17
5
15
  -------------------
6
16
 
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hackpad-cli.gemspec
4
4
  gemspec
5
+
data/README.md CHANGED
@@ -42,14 +42,16 @@ Usage
42
42
 
43
43
  ```
44
44
  Commands:
45
- hpcli check # Checks differences between local cache and remote list (options: -u to show urls).
45
+ hpcli default # change the default workspace.
46
+ hpcli getnew # Downloads the new pads the are not cached yet (options: -u to show urls).
46
47
  hpcli help [COMMAND] # Describe available commands or one specific command
47
48
  hpcli info [pad_id] # gets info for the pad <pad_id>.
48
49
  hpcli list # Lists available pads (options: -u to show urls, -r to refresh).
49
50
  hpcli search [term] # Lists available pads matching [term] (options: -u to show urls)
50
- hpcli show [pad_id] [format] # shows pad <pad_id> in format [html,txt,md] (default txt) (options: -r to refresh).
51
+ hpcli show [pad_id] [format] # shows pad <pad_id> in format [html,txt,md], default txt (options: -r to refresh).
51
52
  hpcli stats # Lists configuration values.
52
53
  hpcli version # Displays the hackpad-cli version.
54
+ hpcli workspaces # Lists configurated hackpad workspaces.
53
55
 
54
56
  Options:
55
57
  -c, [--configdir=CONFIGDIR] # Path to the hackpad-cli directory to use.
@@ -59,7 +61,7 @@ Options:
59
61
  -p, [--plain], [--no-plain] # Add this if you don't want colors.
60
62
  ```
61
63
 
62
- At first launch it will create your config dir (default ~/.hackpad-cli/), and will ask you questions to create the config file (default is .. default.yml). If you pass the `-w whatever` option at the end, it will ask questions again to write whatever.yml config file.
64
+ At first launch it will create your config dir (default ~/.hackpad-cli/), and will ask you questions to create the config file (default is `default/config.yml`). If you pass the `-w whatever` option at the end, it will ask questions again to write `whatever/config.yml` config file.
63
65
 
64
66
 
65
67
  Roadmap and todoz
@@ -74,6 +76,9 @@ Check the [Changelog](CHANGELOG.md) for past evolutions.
74
76
  - <s>display cached date in output</s>
75
77
  - <s>write proper tests</s>
76
78
  - for v0.2.0
79
+ - clean the markdown generated by reverse_markdown
80
+ - add a command for searching on local cache, in titles only or in body
81
+ - elaborate a better search syntax so we can have and/or and strings
77
82
  - add commands for creating a new pad, linked to $EDITOR
78
83
  - add a gateway to github so a pad could be copied over a wiki page directly or in a repo somehow
79
84
  - for v0.3.0
data/hackpad-cli.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'thor'
22
- spec.add_dependency 'colorize'
22
+ spec.add_dependency 'cliprompt', '~> 0.0.4'
23
+ spec.add_dependency 'paint'
23
24
  spec.add_dependency 'oauth'
24
25
  spec.add_dependency 'reverse_markdown'
25
26
 
@@ -13,9 +13,9 @@ module Hackpad
13
13
 
14
14
  def prepare(config)
15
15
  consumer = OAuth::Consumer.new(
16
- config['client_id'],
17
- config['secret'],
18
- site: config['site']
16
+ config.client_id,
17
+ config.secret,
18
+ site: config.site
19
19
  )
20
20
  @token = OAuth::AccessToken.new consumer
21
21
  end
@@ -1,5 +1,5 @@
1
1
  require 'reverse_markdown'
2
- require 'colorize'
2
+ require 'paint'
3
3
 
4
4
  require_relative 'config'
5
5
  require_relative 'api'
@@ -11,19 +11,32 @@ module Hackpad
11
11
  module Cli
12
12
  class Client
13
13
 
14
- def initialize(options, output = STDOUT)
14
+ attr_reader :config
15
+
16
+ def initialize(options, input = STDIN, output = STDOUT)
15
17
  @output = output
18
+ @input = input
16
19
  @options = options
17
- Store.prepare @options
18
- @config = Config.load @options
20
+ @config = Config.new @options, input, output
21
+ Store.prepare @config
19
22
  Api.prepare @config
20
- if @options[:plain]
21
- load File.expand_path('../plain_colors.rb', __FILE__)
23
+ if @options[:plain] == true || @config.use_colors == false
24
+ Paint.mode = 0
25
+ end
26
+ end
27
+
28
+ def workspaces
29
+ @config.workspaces.each do |s|
30
+ table s.name, s.site
22
31
  end
23
32
  end
24
33
 
34
+ def default
35
+ @config.change_default
36
+ end
37
+
25
38
  def stats
26
- table 'Site', @config['site'].blue
39
+ table 'Site', Paint[@config.site, :blue]
27
40
  table 'Cached Pads', Store.count_pads
28
41
  table 'Last Refresh', Store.last_refresh || 'not refreshed yet'
29
42
  end
@@ -31,7 +44,7 @@ module Hackpad
31
44
  def search(term, start = 0)
32
45
  payload = Api.search(term, start)
33
46
  payload.each do |a|
34
- @output.puts "#{id_or_url a['id']} - #{unescape(a['title']).yellow}"
47
+ @output.puts "#{id_or_url a['id']} - #{Paint[unescape(a['title']), :yellow]}"
35
48
  @output.puts " #{extract a['snippet']}"
36
49
  end
37
50
  end
@@ -42,9 +55,9 @@ module Hackpad
42
55
  }
43
56
  end
44
57
 
45
- def check
58
+ def getnew
46
59
  @output.puts 'New pads:'
47
- padlist = Padlist.check_list(@options['refresh']).map
60
+ padlist = Padlist.get_new
48
61
  if padlist.count == 0
49
62
  @output.puts 'There is no new pad.'
50
63
  else
@@ -57,9 +70,9 @@ module Hackpad
57
70
  def info(id)
58
71
  pad = Pad.new id
59
72
  pad.load 'txt'
60
- table 'Id', "#{id}".bold
61
- table 'Title', "#{pad.title}".yellow
62
- table 'URI', "#{@config['site']}/#{id}"
73
+ table 'Id', Paint[id, :bold]
74
+ table 'Title', Paint[pad.title, :yellow]
75
+ table 'URI', "#{@config.site}/#{id}"
63
76
  table 'Chars', "#{pad.chars}"
64
77
  table 'Lines', "#{pad.lines}"
65
78
  table 'Guest Policy', "#{pad.guest_policy}"
@@ -81,7 +94,7 @@ module Hackpad
81
94
  private
82
95
 
83
96
  def padline(pad)
84
- "#{(@config['site'] + '/') if @options[:urls]}#{pad.id} - #{pad.title}"
97
+ "#{(@config.site + '/') if @options[:urls]}#{pad.id} - #{pad.title}"
85
98
  end
86
99
 
87
100
  def unescape(s)
@@ -89,7 +102,7 @@ module Hackpad
89
102
  end
90
103
 
91
104
  def extract(s)
92
- unescape(s).gsub(/<b class="hit">([^<]*)<\/b>/) { Regexp.last_match[1].cyan.bold }
105
+ unescape(s).gsub(/<b class="hit">([^<]*)<\/b>/) { Paint[Regexp.last_match[1], :cyan, :bold] }
93
106
  end
94
107
 
95
108
  def table(key, value)
@@ -97,7 +110,7 @@ module Hackpad
97
110
  end
98
111
 
99
112
  def id_or_url(id)
100
- "#{(@config['site'] + '/') if @options[:urls]}#{id.bold}"
113
+ "#{(@config.site + '/') if @options[:urls]}#{Paint[id, :bold]}"
101
114
  end
102
115
 
103
116
  end
@@ -1,39 +1,86 @@
1
- require 'colorize'
1
+ require 'ostruct'
2
+ require 'cliprompt'
2
3
 
3
4
  module Hackpad
4
5
  module Cli
5
- module Config
6
- module_function
7
-
8
- def load(options, input = STDIN, output = STDOUT)
9
- @input = input
10
- @output = output
11
- configdir = options[:configdir]
12
- configfile = File.join(configdir, "#{options[:workspace]}.yml")
13
- if !Dir.exist?(configdir) || !File.exist?(configfile)
14
- setup configfile, input, output
6
+ class Config < OpenStruct
7
+
8
+ include Cliprompt
9
+
10
+ def initialize(options = nil, input = STDIN, output = STDOUT)
11
+ super(options)
12
+ @@input = input
13
+ @@output = output
14
+ self.configdir ||= File.join(ENV['HOME'], '.hackpad-cli')
15
+ self.refresh ||= false
16
+ self.urls ||= false
17
+ self.output = output
18
+ setio input, output
19
+ patch_1
20
+ addvalues 'config'
21
+ self.workspace ||= 'default'
22
+ self.workspacedir = File.join(configdir, workspace)
23
+ addvalues 'workspace'
24
+ end
25
+
26
+ def addvalues(type)
27
+ dir = send("#{type}dir".to_sym)
28
+ file = File.join(dir, 'config.yml')
29
+ FileUtils.mkdir_p dir unless Dir.exist? dir
30
+ send("setup_#{type}".to_sym, file) unless File.exist? file
31
+ YAML.load_file(file).each do |k, v|
32
+ new_ostruct_member(k)
33
+ send("#{k}=", v)
15
34
  end
16
- YAML.load_file configfile
17
- end
18
-
19
- def setup(configfile, input = STDIN, output = STDOUT)
20
- config = {}
21
- FileUtils.mkdir_p File.dirname(configfile)
22
- output.puts 'We need first to initialize your hackpad-cli configuration.'.blue
23
- output.puts 'Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/'.light_blue
24
- config['client_id'] = ask 'What is your Client ID?', input, output
25
- config['secret'] = ask 'What is your Secret Key?', input, output
26
- config['site'] = ask('What is the URI of your pad?', input, output).gsub(/\/$/, '')
27
- File.open(configfile, 'w') do |f|
28
- f.write YAML.dump(config)
35
+ end
36
+
37
+ def workspaces
38
+ w = Dir.glob(File.join(configdir, '*', 'config.yml')).reduce([]) do |a, path|
39
+ a << OpenStruct.new(name: File.basename(File.dirname(path)), site: YAML.load_file(path)['site'])
40
+ a
41
+ end
42
+ w.sort_by { |s| s.name }
43
+ end
44
+
45
+ def setup_config(file)
46
+ values = {}
47
+ output.puts Paint['Create a new hackpad-cli configuration:', :blue]
48
+ values['use_colors'] = guess 'HPCLI_COLORS', 'Do you want a colored output?', 'Yn'
49
+ values['workspace'] = guess 'HPCLI_WORKSPACE', 'What is the name of the default workspace?', 'default'
50
+ write(file, values)
51
+ end
52
+
53
+ def setup_workspace(file)
54
+ values = {}
55
+ output.puts Paint['Workspace configuration.', :blue]
56
+ output.puts Paint['Gather your information from https://<workspace>.hackpad.com/ep/account/settings/', :bold]
57
+ values['client_id'] = guess 'HPCLI_CLIENTID', 'What is your Client ID?'
58
+ values['secret'] = guess 'HPCLI_SECRET', 'What is your Secret Key?'
59
+ values['site'] = guess('HPCLI_URL', 'What is the URI of your workspace? (ex. https://xxx.hackapd.com)').gsub(/\/$/, '')
60
+ write(file, values)
61
+ end
62
+
63
+ def change_default
64
+ values = {}
65
+ values['use_colors'] = use_colors
66
+ values['workspace'] = ask 'What workspace do you want to use as default from now on?',
67
+ choices: workspaces.map(&:name),
68
+ default: workspace,
69
+ aslist: true
70
+ file = File.join(configdir, 'config.yml')
71
+ write(file, values)
72
+ end
73
+
74
+ def patch_1
75
+ if File.exist? File.join(configdir, "#{workspace}.yml")
76
+ FileUtils.mv File.join(configdir, "#{workspace}.yml"), File.join(configdir, workspace, 'config.yml')
29
77
  end
30
78
  end
31
79
 
32
- def ask(question, input, output)
33
- output.print "#{question} "
34
- back = input.gets.chomp
35
- output.flush
36
- back
80
+ def write(file, values)
81
+ File.open(file, 'w') do |f|
82
+ f.write YAML.dump(values)
83
+ end
37
84
  end
38
85
 
39
86
  end
@@ -1,3 +1,5 @@
1
+ require 'reverse_markdown'
2
+
1
3
  require_relative 'store'
2
4
  require_relative 'api'
3
5
 
@@ -28,39 +30,36 @@ module Hackpad
28
30
  @content.lines.count if @content
29
31
  end
30
32
 
31
- def load(ext, refresh = false, save = true)
33
+ def load(ext, refresh = false)
32
34
  fail UnknownFormat unless FORMATS.include? ext
33
35
  fail UndefinedPad unless @id
34
- if refresh || !Store.exists?(ext, @id)
35
- load_from_api ext, save
36
+ if refresh || !Store.exist?(ext, @id)
37
+ load_from_provider Api, ext
38
+ Store.save(self, ext)
39
+ Store.save_options(@id, @options)
36
40
  else
37
- load_from_cache ext
41
+ load_from_provider Store, ext
38
42
  end
39
43
  end
40
44
 
41
- def load_from_api(ext, dosave = true)
42
- @content = Api.read @id, ext
43
- dosave && Store.save(self, ext)
44
- options = Api.read_options @id
45
- @guest_policy = options['options']['guestPolicy']
46
- @moderated = options['options']['isModerated']
47
- options['cached_at'] = Time.now
48
- @cached_at = options['cached_at']
49
- dosave && Store.save_options(@id, options)
45
+ def load_from_provider(klass, ext)
46
+ @content = klass.read @id, ext
47
+ @options = klass.read_options(@id)
48
+ load_options @options
50
49
  end
51
50
 
52
- def load_from_cache(ext)
53
- @content = Store.read @id, ext
54
- options = Store.read_options @id
51
+ def load_options(options)
55
52
  @guest_policy = options['options']['guestPolicy']
56
53
  @moderated = options['options']['isModerated']
54
+ options['cached_at'] ||= Time.now
57
55
  @cached_at = options['cached_at']
58
56
  end
59
57
 
60
58
  def cached?
61
- Store.exists? 'meta', @id
59
+ Store.exist? 'meta', @id
62
60
  end
63
61
 
62
+
64
63
  end
65
64
  end
66
65
  end
@@ -10,7 +10,7 @@ module Hackpad
10
10
 
11
11
  def get_list(refresh = false, output = STDOUT)
12
12
  all = []
13
- if refresh || !Store.exists?('padlist')
13
+ if refresh || !Store.exist?('padlist')
14
14
  output.print 'Refreshing '
15
15
  list = Api.list
16
16
  list.each do |a|
@@ -31,13 +31,13 @@ module Hackpad
31
31
  OpenStruct.new(id: id, title: pad.title)
32
32
  end
33
33
 
34
- def check_list
34
+ def get_new
35
35
  all = []
36
36
  list = Api.list
37
37
  list.each do |a|
38
38
  pad = Pad.new a
39
39
  unless pad.cached?
40
- pad.load 'txt', false, false
40
+ pad.load 'txt'
41
41
  all << OpenStruct.new(id: a, title: pad.title)
42
42
  end
43
43
  end
@@ -43,6 +43,16 @@ module Hackpad
43
43
 
44
44
  default_task :help
45
45
 
46
+ desc 'workspaces', 'Lists configurated hackpad workspaces.'
47
+ def workspaces
48
+ Hackpad::Cli::Client.new(options).workspaces
49
+ end
50
+
51
+ desc 'default', 'change the default workspace.'
52
+ def default
53
+ Hackpad::Cli::Client.new(options).default
54
+ end
55
+
46
56
  desc 'stats', 'Lists configuration values.'
47
57
  def stats
48
58
  Hackpad::Cli::Client.new(options).stats
@@ -61,10 +71,10 @@ module Hackpad
61
71
  Hackpad::Cli::Client.new(options).list
62
72
  end
63
73
 
64
- desc 'check', 'Checks differences between local cache and remote list (options: -u to show urls).'
74
+ desc 'getnew', 'Downloads the new pads the are not cached yet (options: -u to show urls).'
65
75
  method_option(*url_option)
66
- def check
67
- Hackpad::Cli::Client.new(options).check
76
+ def getnew
77
+ Hackpad::Cli::Client.new(options).getnew
68
78
  end
69
79
 
70
80
  desc 'info [pad_id]', 'gets info for the pad <pad_id>.'
@@ -83,12 +93,6 @@ module Hackpad
83
93
  puts Hackpad::Cli::VERSION
84
94
  end
85
95
 
86
- desc 'colors', 'displays colorize color matrix.', hide: true
87
- def colors
88
- require 'colorize'
89
- String.color_matrix ' xoxo '
90
- end
91
-
92
96
  end
93
97
  end
94
98
  end
@@ -1,6 +1,8 @@
1
1
  require 'json'
2
2
  require 'ostruct'
3
+
3
4
  require_relative '../cli'
5
+ require_relative 'config'
4
6
 
5
7
  module Hackpad
6
8
  module Cli
@@ -8,9 +10,9 @@ module Hackpad
8
10
  module_function
9
11
 
10
12
  def prepare(config)
11
- @refresh = config[:refresh]
12
- dir = File.join(config[:configdir], config[:workspace])
13
- @pads_dir = File.join(dir, 'pads')
13
+ @refresh = config.refresh
14
+ @configdir = config.configdir
15
+ @pads_dir = File.join(config.workspacedir, 'pads')
14
16
  @list_cache = File.join(@pads_dir, 'padlist')
15
17
  prepare_dirs @pads_dir
16
18
  end
@@ -19,7 +21,7 @@ module Hackpad
19
21
  (Hackpad::Cli::FORMATS + ['meta']).each { |f| FileUtils.mkdir_p File.join(base, f) }
20
22
  end
21
23
 
22
- def exists?(*path)
24
+ def exist?(*path)
23
25
  !@refresh && File.exist?(File.join(@pads_dir, *path))
24
26
  end
25
27
 
@@ -1,5 +1,5 @@
1
1
  module Hackpad
2
2
  module Cli
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -7,9 +7,9 @@ require 'hackpad/cli/api'
7
7
  WebMock.disable_net_connect!(allow: 'codeclimate.com')
8
8
 
9
9
  describe Hackpad::Cli::Api do
10
+ let(:config) { OpenStruct.new(site: 'http://x.hackpad.com', client_id: '123', secret: 'aaa') }
10
11
 
11
12
  describe '.search' do
12
- let(:config) { { 'site' => 'http://x.hackpad.com', 'client_id' => '123', 'secret' => 'aaa' } }
13
13
  before { Hackpad::Cli::Api.prepare config }
14
14
  context 'when just a simple term is provided,' do
15
15
  it 'returns expected json' do
@@ -25,7 +25,6 @@ describe Hackpad::Cli::Api do
25
25
  end
26
26
 
27
27
  describe '.list' do
28
- let(:config) { { 'site' => 'http://x.hackpad.com', 'client_id' => '123', 'secret' => 'aaa' } }
29
28
  before { Hackpad::Cli::Api.prepare config }
30
29
  it 'returns expected json' do
31
30
  stub_request(:get, 'http://x.hackpad.com/api/1.0/pads/all')
@@ -35,7 +34,6 @@ describe Hackpad::Cli::Api do
35
34
  end
36
35
 
37
36
  describe '.read_options' do
38
- let(:config) { { 'site' => 'http://x.hackpad.com', 'client_id' => '123', 'secret' => 'aaa' } }
39
37
  before { Hackpad::Cli::Api.prepare config }
40
38
  it 'returns expected json' do
41
39
  stub_request(:get, 'http://x.hackpad.com/api/1.0/pad/aaa/options')
@@ -45,7 +43,6 @@ describe Hackpad::Cli::Api do
45
43
  end
46
44
 
47
45
  describe '.read' do
48
- let(:config) { { 'site' => 'http://x.hackpad.com', 'client_id' => '123', 'secret' => 'aaa' } }
49
46
  before { Hackpad::Cli::Api.prepare config }
50
47
  it 'returns expected json' do
51
48
  stub_request(:get, 'http://x.hackpad.com/api/1.0/pad/aaa/content.html')
@@ -55,7 +52,6 @@ describe Hackpad::Cli::Api do
55
52
  end
56
53
 
57
54
  describe '.get' do
58
- let(:config) { { 'site' => 'http://x.hackpad.com', 'client_id' => '123', 'secret' => 'aaa' } }
59
55
  before { Hackpad::Cli::Api.prepare config }
60
56
  context 'when proper crendential are provided,' do
61
57
  it 'all goes well' do
@@ -2,45 +2,88 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'hackpad/cli/client'
5
+ require 'pp'
5
6
 
6
7
  describe Hackpad::Cli::Client do
7
8
  let(:configdir) { File.expand_path('../../../../files', __FILE__) }
9
+ let(:configfile) { File.join(configdir, 'config.yml') }
10
+ let(:workspacedir) { File.join(configdir, 'default') }
11
+ let(:workspacefile) { File.join(workspacedir, 'config.yml') }
12
+ let(:configvars) { { 'use_colors' => true, 'workspace' => 'default' } }
13
+ let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
8
14
  let(:options) { { configdir: configdir, workspace: 'default' } }
9
15
  let(:format) { "%-20s %s\n" }
16
+ let(:input) { StringIO.new }
17
+ let(:output) { StringIO.new }
18
+ before { FileUtils.mkdir_p configdir }
19
+ before { FileUtils.mkdir_p workspacedir }
20
+ before { File.open(configfile, 'w') { |f| f.puts YAML.dump(configvars) } }
21
+ before { File.open(workspacefile, 'w') { |f| f.puts YAML.dump(workspacevars) } }
22
+ after { FileUtils.rm configfile if File.exist?(configfile) }
23
+ after { FileUtils.rm workspacefile if File.exist?(workspacefile) }
10
24
 
11
25
  describe '.new' do
12
26
  before { Hackpad::Cli::Api.stub(:prepare) }
13
27
  before { Hackpad::Cli::Store.stub(:prepare) }
14
- before { Hackpad::Cli::Config.stub(:load) }
15
28
 
16
29
  context 'when default options are passed,' do
17
30
  let(:client) { Hackpad::Cli::Client.new options }
18
31
  it { expect(client).to be_a Hackpad::Cli::Client }
19
- context 'when colorization is expected,' do
20
- it { expect('x'.blue).to eq "\e[0;34;49mx\e[0m" }
21
- end
22
32
  end
23
33
 
24
34
  context 'when plain text is required,' do
25
35
  context 'when colorization is not expected,' do
26
36
  before { Hackpad::Cli::Client.new options.merge(plain: true) }
27
- after { load 'colorize.rb' }
28
- it { expect('x'.blue).to eq 'x' }
37
+ it { expect(Paint.mode).to eq 0 }
29
38
  end
30
39
  end
31
40
  end
32
41
 
42
+ describe '.workspaces' do
43
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
44
+ let(:workspacedir2) { File.join(configdir, 'default2') }
45
+ let(:workspacefile2) { File.join(workspacedir2, 'config.yml') }
46
+ let(:workspacevars2) { { 'client_id' => '321', 'secret' => 'otot', 'site' => 'http://2.example.com' } }
47
+ before { FileUtils.mkdir_p workspacedir2 }
48
+ before { File.open(workspacefile2, 'w') { |f| f.puts YAML.dump(workspacevars2) } }
49
+ after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) }
50
+
51
+ it do
52
+ expect(output).to receive(:printf).with(format, 'default', 'http://example.com')
53
+ expect(output).to receive(:printf).with(format, 'default2', 'http://2.example.com')
54
+ client.workspaces
55
+ end
56
+ end
57
+
58
+ describe '.default' do
59
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
60
+ let(:workspacedir2) { File.join(configdir, 'default2') }
61
+ let(:workspacefile2) { File.join(workspacedir2, 'config.yml') }
62
+ let(:workspacevars2) { { 'client_id' => '321', 'secret' => 'otot', 'site' => 'http://2.example.com' } }
63
+ before { input.stub(:gets).and_return('1') }
64
+ before { FileUtils.mkdir_p workspacedir2 }
65
+ before { File.open(workspacefile2, 'w') { |f| f.puts YAML.dump(workspacevars2) } }
66
+ after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) }
67
+
68
+ it do
69
+ expect(output).to receive(:puts).with('What workspace do you want to use as default from now on?')
70
+ expect(output).to receive(:printf).with("> %-3s %s\n", 0, "default")
71
+ expect(output).to receive(:printf).with(" %-3s %s\n", 1, "default2")
72
+ client.default
73
+ expect(YAML.load_file(configfile)['workspace']).to eq 'default2'
74
+ end
75
+ end
76
+
33
77
  describe '.stats' do
34
78
  let(:timestamp) { Time.new(2013, 10, 2) }
35
79
  before { Hackpad::Cli::Store.stub(:prepare) }
36
- before { Hackpad::Cli::Config.stub(:load).and_return('site' => 'http://test.dev') }
37
80
  before { Hackpad::Cli::Store.stub(:count_pads).and_return(12) }
38
81
  before { Hackpad::Cli::Store.stub(:last_refresh).and_return(timestamp) }
39
- let(:client) { Hackpad::Cli::Client.new options }
82
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
40
83
  it do
41
- expect(STDOUT).to receive(:printf).with(format, 'Site', "\e[0;34;49mhttp://test.dev\e[0m")
42
- expect(STDOUT).to receive(:printf).with(format, 'Cached Pads', 12)
43
- expect(STDOUT).to receive(:printf).with(format, 'Last Refresh', timestamp)
84
+ expect(output).to receive(:printf).with(format, 'Site', Paint[workspacevars['site'], :blue])
85
+ expect(output).to receive(:printf).with(format, 'Cached Pads', 12)
86
+ expect(output).to receive(:printf).with(format, 'Last Refresh', timestamp)
44
87
  client.stats
45
88
  end
46
89
  end
@@ -48,7 +91,6 @@ describe Hackpad::Cli::Client do
48
91
  describe '.search' do
49
92
  before { Hackpad::Cli::Api.stub(:prepare) }
50
93
  before { Hackpad::Cli::Store.stub(:prepare) }
51
- before { Hackpad::Cli::Config.stub(:load).and_return('site' => 'http://test.dev') }
52
94
  before do
53
95
  Hackpad::Cli::Api.stub(:search)
54
96
  .with('xxx', 0)
@@ -61,18 +103,18 @@ describe Hackpad::Cli::Client do
61
103
  )
62
104
  end
63
105
  context 'when default options are used,' do
64
- let(:client) { Hackpad::Cli::Client.new options }
106
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
65
107
  it do
66
- expect(STDOUT).to receive(:puts).with("\e[1;39;49mxxxxxx\e[0m - \e[0;33;49mxtitle\e[0m")
67
- expect(STDOUT).to receive(:puts).with(" context \e[1;36;49mx\e[0m context")
108
+ expect(output).to receive(:puts).with("#{Paint['xxxxxx', :bold]} - #{Paint['xtitle', :yellow]}")
109
+ expect(output).to receive(:puts).with(" context #{Paint['x', :cyan, :bold]} context")
68
110
  client.search 'xxx'
69
111
  end
70
112
  end
71
113
  context 'when options sets urls to true,' do
72
- let(:client) { Hackpad::Cli::Client.new options.merge(urls: true) }
114
+ let(:client) { Hackpad::Cli::Client.new(options.merge(urls: true), input, output) }
73
115
  it do
74
- expect(STDOUT).to receive(:puts).with("http://test.dev/\e[1;39;49mxxxxxx\e[0m - \e[0;33;49mxtitle\e[0m")
75
- expect(STDOUT).to receive(:puts).with(" context \e[1;36;49mx\e[0m context")
116
+ expect(output).to receive(:puts).with("#{workspacevars['site']}/#{Paint['xxxxxx', :bold]} - #{Paint['xtitle', :yellow]}")
117
+ expect(output).to receive(:puts).with(" context #{Paint['x', :cyan, :bold]} context")
76
118
  client.search 'xxx'
77
119
  end
78
120
  end
@@ -81,61 +123,59 @@ describe Hackpad::Cli::Client do
81
123
  describe '.list' do
82
124
  before { Hackpad::Cli::Api.stub(:prepare) }
83
125
  before { Hackpad::Cli::Store.stub(:prepare) }
84
- before { Hackpad::Cli::Config.stub(:load).and_return('site' => 'http://test.dev') }
85
126
  before do
86
127
  Hackpad::Cli::Padlist.stub(:get_list)
87
128
  .and_return([OpenStruct.new(id: 'xxxxxx', title: 'xtitle')])
88
129
  end
89
130
  context 'when default options are used,' do
90
- let(:client) { Hackpad::Cli::Client.new options }
131
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
91
132
  it do
92
- expect(STDOUT).to receive(:puts).with(['xxxxxx - xtitle'])
133
+ expect(output).to receive(:puts).with(['xxxxxx - xtitle'])
93
134
  client.list
94
135
  end
95
136
  end
96
137
  context 'when options sets urls to true,' do
97
- let(:client) { Hackpad::Cli::Client.new options.merge(urls: true) }
138
+ let(:client) { Hackpad::Cli::Client.new(options.merge(urls: true), input, output) }
98
139
  it do
99
- expect(STDOUT).to receive(:puts).with(['http://test.dev/xxxxxx - xtitle'])
140
+ expect(output).to receive(:puts).with(["#{workspacevars['site']}/xxxxxx - xtitle"])
100
141
  client.list
101
142
  end
102
143
  end
103
144
  end
104
145
 
105
- describe '.check' do
146
+ describe '.getnew' do
106
147
  before { Hackpad::Cli::Api.stub(:prepare) }
107
148
  before { Hackpad::Cli::Store.stub(:prepare) }
108
- before { Hackpad::Cli::Config.stub(:load).and_return('site' => 'http://test.dev') }
109
149
 
110
150
  context 'when there is a new pad,' do
111
151
  before do
112
- Hackpad::Cli::Padlist.stub(:check_list)
152
+ Hackpad::Cli::Padlist.stub(:get_new)
113
153
  .and_return([OpenStruct.new(id: 'xxxxxx', title: 'xtitle')])
114
154
  end
115
155
  context 'when default options are used,' do
116
- let(:client) { Hackpad::Cli::Client.new options }
156
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
117
157
  it do
118
- expect(STDOUT).to receive(:puts).with('New pads:')
119
- expect(STDOUT).to receive(:puts).with(['xxxxxx - xtitle'])
120
- client.check
158
+ expect(output).to receive(:puts).with('New pads:')
159
+ expect(output).to receive(:puts).with(['xxxxxx - xtitle'])
160
+ client.getnew
121
161
  end
122
162
  end
123
163
  context 'when options sets urls to true,' do
124
- let(:client) { Hackpad::Cli::Client.new options.merge(urls: true) }
164
+ let(:client) { Hackpad::Cli::Client.new(options.merge(urls: true), input, output) }
125
165
  it do
126
- expect(STDOUT).to receive(:puts).with('New pads:')
127
- expect(STDOUT).to receive(:puts).with(['http://test.dev/xxxxxx - xtitle'])
128
- client.check
166
+ expect(output).to receive(:puts).with('New pads:')
167
+ expect(output).to receive(:puts).with(["#{workspacevars['site']}/xxxxxx - xtitle"])
168
+ client.getnew
129
169
  end
130
170
  end
131
171
  end
132
172
  context 'when there is no new pad,' do
133
- before { Hackpad::Cli::Padlist.stub(:check_list).and_return([]) }
134
- let(:client) { Hackpad::Cli::Client.new options }
173
+ before { Hackpad::Cli::Padlist.stub(:get_new).and_return([]) }
174
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
135
175
  it do
136
- expect(STDOUT).to receive(:puts).with('New pads:')
137
- expect(STDOUT).to receive(:puts).with('There is no new pad.')
138
- client.check
176
+ expect(output).to receive(:puts).with('New pads:')
177
+ expect(output).to receive(:puts).with('There is no new pad.')
178
+ client.getnew
139
179
  end
140
180
  end
141
181
  end
@@ -143,8 +183,7 @@ describe Hackpad::Cli::Client do
143
183
  describe '.info' do
144
184
  before { Hackpad::Cli::Api.stub(:prepare) }
145
185
  before { Hackpad::Cli::Store.stub(:prepare) }
146
- before { Hackpad::Cli::Config.stub(:load).and_return('site' => 'http://test.dev') }
147
- let(:client) { Hackpad::Cli::Client.new options }
186
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
148
187
  let(:pad) { double Hackpad::Cli::Pad }
149
188
  before { Hackpad::Cli::Pad.stub(:new).with('123').and_return pad }
150
189
 
@@ -162,14 +201,14 @@ describe Hackpad::Cli::Client do
162
201
  before { pad.stub(:moderated).and_return('false') }
163
202
  before { pad.stub(:cached_at).and_return }
164
203
  it do
165
- expect(STDOUT).to receive(:printf).with(format, 'Id', "\e[1;39;49m123\e[0m")
166
- expect(STDOUT).to receive(:printf).with(format, 'Title', "\e[0;33;49mtitle1\e[0m")
167
- expect(STDOUT).to receive(:printf).with(format, 'URI', 'http://test.dev/123')
168
- expect(STDOUT).to receive(:printf).with(format, 'Chars', '20')
169
- expect(STDOUT).to receive(:printf).with(format, 'Lines', '2')
170
- expect(STDOUT).to receive(:printf).with(format, 'Guest Policy', 'open')
171
- expect(STDOUT).to receive(:printf).with(format, 'Moderated', 'false')
172
- expect(STDOUT).to receive(:printf).with(format, 'Cached', 'unknown')
204
+ expect(output).to receive(:printf).with(format, 'Id', Paint["123", :bold])
205
+ expect(output).to receive(:printf).with(format, 'Title', Paint['title1', :yellow])
206
+ expect(output).to receive(:printf).with(format, 'URI', "#{workspacevars['site']}/123")
207
+ expect(output).to receive(:printf).with(format, 'Chars', '20')
208
+ expect(output).to receive(:printf).with(format, 'Lines', '2')
209
+ expect(output).to receive(:printf).with(format, 'Guest Policy', 'open')
210
+ expect(output).to receive(:printf).with(format, 'Moderated', 'false')
211
+ expect(output).to receive(:printf).with(format, 'Cached', 'unknown')
173
212
  client.info '123'
174
213
  end
175
214
  end
@@ -179,8 +218,7 @@ describe Hackpad::Cli::Client do
179
218
  describe '.show' do
180
219
  before { Hackpad::Cli::Api.stub(:prepare) }
181
220
  before { Hackpad::Cli::Store.stub(:prepare) }
182
- before { Hackpad::Cli::Config.stub(:load).and_return('site' => 'http://test.dev') }
183
- let(:client) { Hackpad::Cli::Client.new options }
221
+ let(:client) { Hackpad::Cli::Client.new(options, input, output) }
184
222
  let(:pad) { double Hackpad::Cli::Pad }
185
223
  before { Hackpad::Cli::Pad.stub(:new).with('123').and_return pad }
186
224
  before { pad.stub(:load) }
@@ -188,7 +226,7 @@ describe Hackpad::Cli::Client do
188
226
  context 'when a txt version is asked,' do
189
227
  before { pad.stub(:content).and_return('this is content') }
190
228
  it do
191
- expect(STDOUT).to receive(:puts).with('this is content')
229
+ expect(output).to receive(:puts).with('this is content')
192
230
  client.show '123', 'txt'
193
231
  end
194
232
  end
@@ -196,7 +234,7 @@ describe Hackpad::Cli::Client do
196
234
  context 'when a html version is asked,' do
197
235
  before { pad.stub(:content).and_return('<ul><li>this is content</li></ul>') }
198
236
  it do
199
- expect(STDOUT).to receive(:puts).with('<ul><li>this is content</li></ul>')
237
+ expect(output).to receive(:puts).with('<ul><li>this is content</li></ul>')
200
238
  client.show '123', 'html'
201
239
  end
202
240
  end
@@ -209,7 +247,7 @@ describe Hackpad::Cli::Client do
209
247
  .and_return('- this is content')
210
248
  end
211
249
  it do
212
- expect(STDOUT).to receive(:puts).with('- this is content')
250
+ expect(output).to receive(:puts).with('- this is content')
213
251
  client.show '123', 'md'
214
252
  end
215
253
  end
@@ -6,42 +6,51 @@ require 'hackpad/cli/config'
6
6
  describe Hackpad::Cli::Config do
7
7
 
8
8
  let(:configdir) { File.expand_path('../../../../files', __FILE__) }
9
- let(:configfile) { File.join(configdir, 'default.yml') }
9
+ let(:configfile) { File.join(configdir, 'config.yml') }
10
+ let(:workspacedir) { File.join(configdir, 'default') }
11
+ let(:workspacefile) { File.join(workspacedir, 'config.yml') }
10
12
  let(:options) { { configdir: configdir, workspace: 'default' } }
11
-
12
- before :each do
13
- FileUtils.mkdir_p configdir unless Dir.exist?(configdir)
14
- end
15
-
16
- after :each do
17
- FileUtils.rm configfile if File.exist?(configfile)
18
- end
19
-
20
- describe '.load' do
21
- let(:config) { { 'xx' => 'oo' } }
22
-
23
- context 'when there is no config file,' do
24
- it 'calls for setup' do
25
- Dir.stub(:exists?).and_return false
26
- subject.stub(:setup).with(configfile, STDIN, STDOUT)
27
- File.open(configfile, 'w') do |f|
28
- f.write YAML.dump(config)
29
- end
30
- expect(subject.load options).to eq config
31
- end
13
+ let(:input) { StringIO.new }
14
+ let(:output) { StringIO.new }
15
+
16
+ before { FileUtils.mkdir_p configdir unless Dir.exist?(configdir) }
17
+ before { FileUtils.mkdir_p workspacedir unless Dir.exist?(workspacedir) }
18
+
19
+ after { FileUtils.rm configfile if File.exist?(configfile) }
20
+ after { FileUtils.rm workspacefile if File.exist?(workspacefile) }
21
+
22
+ describe '.new' do
23
+ context 'when there is already config files created,' do
24
+ let(:configvars) { { 'use_colors' => true, 'workspace' => 'default' } }
25
+ let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
26
+ before { File.open(configfile, 'w') { |f| f.puts YAML.dump(configvars) } }
27
+ before { File.open(workspacefile, 'w') { |f| f.puts YAML.dump(workspacevars) } }
28
+ let(:config) { Hackpad::Cli::Config.new(options) }
29
+ it {
30
+ expect(config.secret).to eq 'toto'
31
+ expect(config.site).to eq 'http://example.com'
32
+ }
33
+ end
34
+ context 'when there is no config files created,' do
35
+ before { input.stub(:gets).and_return('y', 'default', '123', 'toto','http://example.com') }
36
+ let(:config) { Hackpad::Cli::Config.new(options, input, output) }
37
+ it {
38
+ expect(config.secret).to eq 'toto'
39
+ expect(config.site).to eq 'http://example.com'
40
+ }
32
41
  end
33
-
34
42
  end
35
43
 
36
- describe '.setup' do
37
- context 'when normal input is provided,' do
38
- let(:input) { StringIO.new }
39
- let(:output) { StringIO.new }
40
- it 'handles setup interactively' do
41
- input.stub(:gets).and_return('client_id', 'secret', 'site')
42
- subject.send :setup, configfile, input, output
43
- expect(File.read configfile).to eq "---\nclient_id: client_id\nsecret: secret\nsite: site\n"
44
- end
44
+ describe '.patch_1' do
45
+ let(:oldconfigfile) { File.join(configdir, 'default.yml') }
46
+ let(:oldconfigvars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
47
+ before { File.open(oldconfigfile, 'w') { |f| f.puts YAML.dump(oldconfigvars) } }
48
+ before { input.stub(:gets).and_return('y', 'default') }
49
+ after { FileUtils.rm oldconfigfile if File.exist?(oldconfigfile) }
50
+ it do
51
+ Hackpad::Cli::Config.new(options, input, output)
52
+ expect(File.exist? oldconfigfile).to be_false
53
+ expect(File.exist? configfile).to be_true
45
54
  end
46
55
  end
47
56
 
@@ -15,7 +15,7 @@ describe Hackpad::Cli::Pad do
15
15
  end
16
16
 
17
17
  describe '.cached?' do
18
- before { Hackpad::Cli::Store.stub(:exists?).and_return true }
18
+ before { Hackpad::Cli::Store.stub(:exist?).and_return true }
19
19
  it { expect(pad.cached?).to be_true }
20
20
  end
21
21
 
@@ -45,7 +45,7 @@ describe Hackpad::Cli::Pad do
45
45
  end
46
46
 
47
47
  context 'when a pad is cached,' do
48
- before { Hackpad::Cli::Store.stub(:exists?).and_return true }
48
+ before { Hackpad::Cli::Store.stub(:exist?).and_return true }
49
49
  context "when we don't want a refresh," do
50
50
  describe '.load' do
51
51
  context 'when unknown format is asked,' do
@@ -56,7 +56,7 @@ describe Hackpad::Cli::Pad do
56
56
  it { expect { pad.load 'txt' }.to raise_error(Hackpad::Cli::UndefinedPad) }
57
57
  end
58
58
  context 'when all is ok,' do
59
- before { pad.stub(:load_from_cache) }
59
+ before { pad.stub(:load_from_provider).with(Hackpad::Cli::Store, 'txt') }
60
60
  it { expect { pad.load 'txt' }.not_to raise_error }
61
61
  end
62
62
  end
@@ -64,7 +64,7 @@ describe Hackpad::Cli::Pad do
64
64
  let(:meta) { { 'options' => { 'guestPolicy' => 'open', 'isModerated' => false }, 'cached_at' => 'some time' } }
65
65
  before { Hackpad::Cli::Store.stub(:read).with('123', 'txt').and_return("This\nis\nInformation!") }
66
66
  before { Hackpad::Cli::Store.stub(:read_options).with('123').and_return(meta) }
67
- before { pad.load_from_cache 'txt' }
67
+ before { pad.load_from_provider Hackpad::Cli::Store, 'txt' }
68
68
  it { expect(pad.content).to eq "This\nis\nInformation!" }
69
69
  it { expect(pad.guest_policy).to eq 'open' }
70
70
  it { expect(pad.moderated).to be_false }
@@ -73,7 +73,9 @@ describe Hackpad::Cli::Pad do
73
73
  end
74
74
  context 'when we want a refresh,' do
75
75
  describe '.load' do
76
- before { pad.stub(:load_from_api) }
76
+ before { pad.stub(:load_from_provider).with(Hackpad::Cli::Api, 'txt') }
77
+ before { Hackpad::Cli::Store.stub(:save) }
78
+ before { Hackpad::Cli::Store.stub(:save_options) }
77
79
  it { expect { pad.load 'txt', true }.not_to raise_error }
78
80
  end
79
81
  describe '.load_from_api' do
@@ -83,11 +85,7 @@ describe Hackpad::Cli::Pad do
83
85
  context 'when we want to save to cache,' do
84
86
  before { Hackpad::Cli::Store.stub(:save) }
85
87
  before { Hackpad::Cli::Store.stub(:save_options) }
86
- before { pad.load_from_api 'txt' }
87
- it { expect(pad.content).to eq "This\nis\nInformation!" }
88
- end
89
- context "when we don't want to save to cache," do
90
- before { pad.load_from_api 'txt', false }
88
+ before { pad.load_from_provider Hackpad::Cli::Api, 'txt' }
91
89
  it { expect(pad.content).to eq "This\nis\nInformation!" }
92
90
  end
93
91
  end
@@ -9,7 +9,7 @@ describe Hackpad::Cli::Padlist do
9
9
  let(:output) { StringIO.new }
10
10
 
11
11
  context 'when no refresh is asked and cache exists,' do
12
- before { Hackpad::Cli::Store.stub(:exists?).and_return(true) }
12
+ before { Hackpad::Cli::Store.stub(:exist?).and_return(true) }
13
13
  before { Hackpad::Cli::Store.stub(:read_list).and_return(Array.new) }
14
14
  it { expect(subject.get_list).to be_an(Array) }
15
15
  end
@@ -18,7 +18,7 @@ describe Hackpad::Cli::Padlist do
18
18
  let(:pad1) { OpenStruct.new(id: '123', title: 'title1') }
19
19
  let(:pad2) { OpenStruct.new(id: '456', title: 'title2') }
20
20
  before { Hackpad::Cli::Api.stub(:list).and_return(%w(123 456)) }
21
- before { Hackpad::Cli::Store.stub(:exists?).and_return(false, false) }
21
+ before { Hackpad::Cli::Store.stub(:exist?).and_return(false, false) }
22
22
  before { Hackpad::Cli::Padlist.stub(:get_pad).and_return(pad1, pad2) }
23
23
  before { Hackpad::Cli::Store.stub(:save_list) }
24
24
  it { expect(subject.get_list(false, output)).to be_an(Array) }
@@ -39,14 +39,14 @@ describe Hackpad::Cli::Padlist do
39
39
  end
40
40
  end
41
41
 
42
- describe '.check_list' do
42
+ describe '.get_new' do
43
43
  before { Hackpad::Cli::Api.stub(:list).and_return(%w(123 456)) }
44
44
  let(:pad) { double Hackpad::Cli::Pad }
45
45
  before { Hackpad::Cli::Pad.stub(:new).and_return(pad, pad) }
46
46
 
47
47
  context 'when there is no new pad,' do
48
48
  before { pad.stub(:cached?).and_return(true, true) }
49
- it { expect(subject.check_list).to eq [] }
49
+ it { expect(subject.get_new).to eq [] }
50
50
  end
51
51
 
52
52
  context 'when there is no one new pad,' do
@@ -54,7 +54,7 @@ describe Hackpad::Cli::Padlist do
54
54
  before { pad.stub(:cached?).and_return(true, false) }
55
55
  before { pad.stub(:load) }
56
56
  before { pad.stub(:title).and_return('title2') }
57
- it { expect(subject.check_list).to eq [pad2] }
57
+ it { expect(subject.get_new).to eq [pad2] }
58
58
  end
59
59
 
60
60
  context 'when there is no 2 new pads,' do
@@ -63,7 +63,7 @@ describe Hackpad::Cli::Padlist do
63
63
  before { pad.stub(:cached?).and_return(false, false) }
64
64
  before { pad.stub(:load).and_return(nil, nil) }
65
65
  before { pad.stub(:title).and_return('title1', 'title2') }
66
- it { expect(subject.check_list).to eq [pad1, pad2] }
66
+ it { expect(subject.get_new).to eq [pad1, pad2] }
67
67
  end
68
68
  end
69
69
 
@@ -26,10 +26,17 @@ describe Hackpad::Cli::Runner do
26
26
  end
27
27
  end
28
28
 
29
- it 'calls the list method in client class' do
30
- Object.stub(:list)
29
+ it 'calls the workspaces method in client class' do
30
+ Object.stub(:workspaces)
31
31
  cli.shell.mute do
32
- cli.list
32
+ cli.workspaces
33
+ end
34
+ end
35
+
36
+ it 'calls the default method in client class' do
37
+ Object.stub(:default)
38
+ cli.shell.mute do
39
+ cli.default
33
40
  end
34
41
  end
35
42
 
@@ -40,10 +47,10 @@ describe Hackpad::Cli::Runner do
40
47
  end
41
48
  end
42
49
 
43
- it 'calls the check method in client class' do
44
- Object.stub(:check)
50
+ it 'calls the getnew method in client class' do
51
+ Object.stub(:getnew)
45
52
  cli.shell.mute do
46
- cli.check
53
+ cli.getnew
47
54
  end
48
55
  end
49
56
 
@@ -68,11 +75,4 @@ describe Hackpad::Cli::Runner do
68
75
  end
69
76
  end
70
77
 
71
- it 'calls the colors method in client class' do
72
- String.stub(:color_matrix).with(' xoxo ')
73
- cli.shell.mute do
74
- cli.colors
75
- end
76
- end
77
-
78
78
  end
@@ -7,7 +7,12 @@ require 'hackpad/cli/pad'
7
7
  describe Hackpad::Cli::Store do
8
8
 
9
9
  let(:configdir) { File.expand_path('../../../../files', __FILE__) }
10
- let(:options) { { configdir: configdir, workspace: 'default' } }
10
+ let(:options) { OpenStruct.new(
11
+ configdir: configdir,
12
+ workspace: 'default',
13
+ workspacedir: File.join(configdir, 'default')
14
+ )
15
+ }
11
16
 
12
17
  before :each do
13
18
  subject.prepare options
@@ -25,27 +30,33 @@ describe Hackpad::Cli::Store do
25
30
  it { expect(list[2].cached_at).to eq 'some time' }
26
31
  end
27
32
 
28
- describe '.exists?' do
33
+ describe '.exist?' do
29
34
 
30
35
  context 'when refresh option is set,' do
31
- let(:options) { { configdir: configdir, workspace: 'default', refresh: true } }
36
+ let(:options) { OpenStruct.new(
37
+ configdir: configdir,
38
+ workspace: 'default',
39
+ workspacedir: File.join(configdir, 'default'),
40
+ refresh: true
41
+ )
42
+ }
32
43
  before do
33
44
  subject.prepare options
34
45
  FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx')
35
46
  end
36
47
  after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
37
- it { expect(subject.exists? 'txt', 'xxx').to be false }
48
+ it { expect(subject.exist? 'txt', 'xxx').to be false }
38
49
  end
39
50
 
40
51
  context 'when refresh option is not set,' do
41
52
  context "when config file don't exist," do
42
- it { expect(subject.exists? 'txt', 'xxx').to be false }
53
+ it { expect(subject.exist? 'txt', 'xxx').to be false }
43
54
  end
44
55
 
45
56
  context 'when configfile exists,' do
46
57
  before { FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
47
58
  after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
48
- it { expect(subject.exists? 'txt', 'xxx').to be true }
59
+ it { expect(subject.exist? 'txt', 'xxx').to be true }
49
60
  end
50
61
  end
51
62
 
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,21 @@ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
2
  require 'rubygems'
3
3
  require 'bundler'
4
4
 
5
- require 'coveralls'
6
- Coveralls.wear!
7
5
 
8
- # require "codeclimate-test-reporter"
9
- # CodeClimate::TestReporter.start
6
+ if ENV['COV']
7
+ require 'simplecov'
8
+ SimpleCov.profiles.define :hpcli do
9
+ add_filter '/vendor/'
10
+ add_filter '/spec/'
11
+ end
12
+ SimpleCov.start :hpcli
13
+ else
14
+ require 'coveralls'
15
+ Coveralls.wear!
16
+
17
+ # require "codeclimate-test-reporter"
18
+ # CodeClimate::TestReporter.start
19
+ end
10
20
 
11
21
  RSpec.configure do |config|
12
22
  config.mock_with :rspec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackpad-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: colorize
28
+ name: cliprompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: paint
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -177,7 +191,6 @@ files:
177
191
  - lib/hackpad/cli/config.rb
178
192
  - lib/hackpad/cli/pad.rb
179
193
  - lib/hackpad/cli/padlist.rb
180
- - lib/hackpad/cli/plain_colors.rb
181
194
  - lib/hackpad/cli/runner.rb
182
195
  - lib/hackpad/cli/store.rb
183
196
  - lib/hackpad/cli/version.rb
@@ -1,13 +0,0 @@
1
- require 'colorize'
2
-
3
- class String
4
- def colorize(_)
5
- self
6
- end
7
- end
8
-
9
- String.send(:remove_const, :COLORS)
10
- String.send(:remove_const, :MODES)
11
- String.send(:remove_const, :REGEXP_PATTERN)
12
- String.send(:remove_const, :COLOR_OFFSET)
13
- String.send(:remove_const, :BACKGROUND_OFFSET)