gyaazle 0.1.0 → 0.2.0

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: e9fcb4b5a8c115bc19de388ee9a16611d396208a
4
- data.tar.gz: dcb1e78fdd812a5c080ec784c799c0a2bb398ed2
3
+ metadata.gz: 4bf8c6b6d331040b41feb688abb4d2f1bb43e424
4
+ data.tar.gz: 99a4581ba42a3641727235d0d2173916e0c13a12
5
5
  SHA512:
6
- metadata.gz: 7432d5148cbb9d3e868dc1877d777270f15007f588665a233b6b4cc215b22d16660c67718cc286b94165b29c41ca6cc6619c94c3e66d7fdb4f66123b8fa83364
7
- data.tar.gz: 1d19d6a111e70dc291fbca2b8b26d6288ce39e7e4bccb0d02a053a7695c11c9cea843797a569408cc3af4f32f28274438d6bb9d32d9a1e12f09331af9cecbf2e
6
+ metadata.gz: 64fa2b8d4dde26d1172a82a7eb2b05226b212676cf104622547f9c2899464587887b9bbca16778dc3b1c49af54927c3bd0e44a94f35b53bc02bfb3c3c7aeb28d
7
+ data.tar.gz: 1ccc3ae4c85ea328d9c941add3e3ed111c35dc1a780a47a4e90faf98716173a8bc187dac835a68e647a31920c53216041d882493c9ddcac24a2cc4a6baa83412
data/lib/gyaazle/cli.rb CHANGED
@@ -29,16 +29,16 @@ TEXT
29
29
  if @opts[:edit]
30
30
  edit_config
31
31
  else
32
- if @opts[:capture]
32
+ if @opts[:capture] || @argv.empty?
33
33
  @argv = [capture]
34
34
  end
35
+
36
+ check_credentials!
35
37
  upload
36
38
  end
37
39
  end
38
40
 
39
41
  def upload
40
- check_credentials!
41
-
42
42
  @argv.each do |file|
43
43
  fileobj = client.upload(file)
44
44
  puts "#{file}:"
@@ -55,13 +55,7 @@ TEXT
55
55
 
56
56
  def capture
57
57
  tmpfile = "/tmp/gyaazle_capture_#{Time.now.strftime("%F %T")}.png"
58
- capture_cmd = case RUBY_PLATFORM
59
- when /darwin/
60
- "screencapture -i '#{tmpfile}'"
61
- else
62
- "import '#{tmpfile}'"
63
- end
64
- system capture_cmd
58
+ system capture_cmd(tmpfile)
65
59
  tmpfile
66
60
  end
67
61
 
@@ -89,5 +83,16 @@ TEXT
89
83
  client.refresh_token!
90
84
  end
91
85
  end
86
+
87
+ private
88
+
89
+ def capture_cmd(save_to)
90
+ case RUBY_PLATFORM
91
+ when /darwin/
92
+ "screencapture -i '#{save_to}'"
93
+ else
94
+ "import '#{save_to}'"
95
+ end
96
+ end
92
97
  end
93
98
  end
@@ -1,3 +1,3 @@
1
1
  module Gyaazle
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,77 +5,95 @@ require "spec_helper"
5
5
  describe Gyaazle::CLI do
6
6
  let(:cli) { Gyaazle::CLI.new([]) }
7
7
 
8
- describe "ensure oauth token" do
9
- before do
10
- cli.stub(:authorize).and_return("verification code")
11
- end
12
-
13
- it "invoke #check_credentials! before #upload" do
14
- cli.should_receive(:check_credentials!)
8
+ describe "#run!" do
9
+ it "invoke #capture when ARGV is empty" do
10
+ cli.stub(:check_credentials!)
11
+ cli.stub(:upload)
12
+ cli.should_receive(:capture)
15
13
  cli.run!
16
14
  end
17
15
 
18
- context "config file does not exists" do
19
- before do
20
- cli.config.stub(:load).and_return(nil)
16
+ describe "options" do
17
+ context "-e" do
18
+ let(:cli) { Gyaazle::CLI.new(%w!-e!) }
19
+ before do
20
+ cli.stub(:edit_config)
21
+ end
22
+
23
+ it "invoke #edit_config" do
24
+ cli.should_receive(:edit_config)
25
+ cli.run!
26
+ end
27
+
28
+ it "not invoke #upload and #check_credentials!" do
29
+ cli.should_not_receive(:check_credentials!)
30
+ cli.should_not_receive(:upload)
31
+ cli.run!
32
+ end
21
33
  end
22
34
 
23
- it "invoke #initialize_tokens" do
24
- cli.should_receive(:initialize_tokens)
25
- cli.run!
26
- end
27
- end
35
+ context "--config filepath" do
36
+ let(:file) { File.join("/tmp", rand.to_s) }
37
+ let(:cli) { Gyaazle::CLI.new(%W!--config #{file}!) }
28
38
 
29
- context "config file is sane" do
30
- before do
31
- cli.config.stub(:load).and_return(:client_id => "id", :client_secret => "secret", :refresh_token => "refresh")
39
+ it "config.file == file" do
40
+ cli.config.file.should == file
41
+ File.unlink(file) if File.exists?(file)
42
+ end
32
43
  end
33
44
 
34
- it "invoke #refresh_token!" do
35
- cli.client.should_receive(:refresh_token!)
36
- cli.run!
45
+ context "--capture" do
46
+ let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
47
+ before do
48
+ cli.stub(:check_credentials!)
49
+ cli.stub(:upload)
50
+ end
51
+
52
+ it "invoke #capture" do
53
+ cli.should_receive(:capture)
54
+ cli.run!
55
+ end
37
56
  end
38
57
  end
39
58
  end
40
59
 
41
- describe "options" do
42
- context "-e" do
43
- let(:cli) { Gyaazle::CLI.new(%w!-e!) }
44
- before do
45
- cli.stub(:edit_config)
46
- end
60
+ describe "#check_credentials!" do
61
+ let(:verifier) { "verification code" }
47
62
 
48
- it "invoke #edit_config" do
49
- cli.should_receive(:edit_config)
50
- cli.run!
63
+ before do
64
+ cli.stub(:authorize).and_return(verifier)
65
+ end
66
+
67
+ context "when config is nil" do
68
+ before do
69
+ cli.config.stub(:load).and_return(nil)
51
70
  end
52
71
 
53
- it "not invoke #upload and #check_credentials!" do
54
- cli.should_not_receive(:check_credentials!)
55
- cli.should_not_receive(:upload)
56
- cli.run!
72
+ it "invoke #initialize_tokens" do
73
+ cli.should_receive(:initialize_tokens).with(verifier)
74
+ cli.check_credentials!
57
75
  end
58
76
  end
59
77
 
60
- context "--config filepath" do
61
- let(:file) { File.join("/tmp", rand.to_s) }
62
- let(:cli) { Gyaazle::CLI.new(%W!--config #{file}!) }
78
+ context "when config is broken" do
79
+ before do
80
+ cli.config.stub(:load).and_return(:foo => :bar)
81
+ end
63
82
 
64
- it "set config file" do
65
- cli.config.file.should == file
66
- File.unlink(file) if File.exists?(file)
83
+ it "invoke #initialize_tokens" do
84
+ cli.should_receive(:initialize_tokens).with(verifier)
85
+ cli.check_credentials!
67
86
  end
68
87
  end
69
88
 
70
- context "--capture" do
71
- let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
89
+ context "when config is fine" do
72
90
  before do
73
- cli.stub(:upload)
91
+ cli.config.stub(:load).and_return(:client_id => "id", :client_secret => "secret", :refresh_token => "refresh")
74
92
  end
75
93
 
76
- it "invoke #capture" do
77
- cli.should_receive(:capture)
78
- cli.run!
94
+ it "invoke client#refresh_token!" do
95
+ cli.client.should_receive(:refresh_token!)
96
+ cli.check_credentials!
79
97
  end
80
98
  end
81
99
  end
@@ -111,5 +129,30 @@ describe Gyaazle::CLI do
111
129
  cli.upload
112
130
  end
113
131
  end
132
+
133
+ describe "#edit_config" do
134
+ let(:conf) { "dummy_config_file" }
135
+ let(:cli) { Gyaazle::CLI.new(%W!-e --config #{conf}!) }
136
+
137
+ it "invoke #system with $EDITOR" do
138
+ cli.should_receive(:system).with(ENV["EDITOR"], conf)
139
+ cli.edit_config
140
+ File.unlink(conf) if File.exists?(conf)
141
+ end
142
+ end
143
+
144
+ describe "#capture" do
145
+ let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
146
+ let(:cmd) { "my-capture-cmd tmpfile" }
147
+
148
+ before do
149
+ cli.stub(:capture_cmd).and_return(cmd)
150
+ end
151
+
152
+ it "invoke #system with #capture_cmd" do
153
+ cli.should_receive(:system).with(cmd)
154
+ cli.capture
155
+ end
156
+ end
114
157
  end
115
158
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyaazle
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
  - uu59
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-25 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient