pinup 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Pinup::Settings do
4
+ before do
5
+ @path = File.expand_path('~/netrc_test')
6
+ @settings_path = File.expand_path('~/.pinup')
7
+ @options = { path: @path }
8
+ @options_with_token = { path: @path, token: 'Foo:bar' }
9
+ end
10
+
11
+ after do
12
+ File.delete(@path) if File.exists?(@path)
13
+ File.delete(@settings_path) if File.exists?(@settings_path)
14
+ end
15
+
16
+ describe 'write_settings' do
17
+ before do
18
+ Pinup::Settings.write_settings(@options)
19
+ end
20
+
21
+ it 'should write the the correct file' do
22
+ expect(File.exists?(File.expand_path(@settings_path))).to be_true
23
+ end
24
+
25
+ it 'should contain the passed path' do
26
+ text = File.read(@settings_path)
27
+ expect(text).to match(/#{ @path }/)
28
+ expect(text).to match(/path/)
29
+ end
30
+ end
31
+
32
+ describe 'read_settings' do
33
+ describe 'if the file does not exist' do
34
+ it 'should return nil' do
35
+ expect(Pinup::Settings.read_settings).to be_nil
36
+ end
37
+ end
38
+
39
+ describe 'if the file is empty' do
40
+ before do
41
+ File.open(@settings_path, 'w') do |f|
42
+ f.write("")
43
+ end
44
+ end
45
+
46
+ it 'should return nil' do
47
+ expect(Pinup::Settings.read_settings).to be_nil
48
+ end
49
+ end
50
+
51
+ describe 'if the file does exist' do
52
+ before do
53
+ Pinup::Settings.write_settings(@options)
54
+ end
55
+
56
+ it 'should return the correct path' do
57
+ @settings = Pinup::Settings.read_settings
58
+ @same_path = @settings[:path] == @path
59
+ expect(@same_path).to be_true
60
+ end
61
+ end
62
+ end
63
+
64
+ describe 'save_token' do
65
+ describe 'when no options are passed' do
66
+ it 'should exit' do
67
+ expect(Pinup::Settings.save_token).to equal(nil)
68
+ end
69
+ end
70
+
71
+ describe 'when an invalid token is passed' do
72
+ it 'should return' do
73
+ expect(Pinup::Settings.save_token({ token: 'foobar' })).to equal(nil)
74
+ end
75
+ end
76
+
77
+ describe 'when a validish token and path is passed' do
78
+ before do
79
+ Pinup::Settings.save_token(@options_with_token)
80
+ end
81
+
82
+ it 'should return true' do
83
+ expect(Pinup::Settings.save_token(@options_with_token)).to eq(true)
84
+ end
85
+
86
+ it 'should create and save to the given file path' do
87
+ expect(File.exists?(@path)).to equal(true)
88
+ end
89
+
90
+ it 'should write the correct information to the file' do
91
+ @text = File.read(@path)
92
+ expect(@text).to match(/machine\s+pinboard\.in/)
93
+ expect(@text).to match(/login\s+Foo/)
94
+ expect(@text).to match(/password\s+bar/)
95
+ end
96
+ end
97
+ end
98
+
99
+ describe 'get_token' do
100
+ describe 'if there is a token' do
101
+ before do
102
+ Pinup::Settings.write_settings(@options)
103
+ Pinup::Settings.save_token(@options_with_token)
104
+ end
105
+
106
+ it 'should load the correct token' do
107
+ token = Pinup::Settings.get_token
108
+ result = token == 'Foo:bar'
109
+ expect(result).to be_true
110
+ end
111
+ end
112
+
113
+ describe 'if there is no token' do
114
+ before do
115
+ @local_path = File.expand_path('~/foobar')
116
+ Pinup::Settings.write_settings({ path: @local_path })
117
+ end
118
+
119
+ it 'should return nil' do
120
+ token = Pinup::Settings.get_token
121
+ expect(token).to be_nil
122
+ end
123
+ end
124
+
125
+ describe 'if there is only one attribute in the netrc' do
126
+ before do
127
+ @foopath = File.expand_path('~/foo')
128
+ Pinup::Settings.write_settings({ path: @foopath })
129
+ @netrc = Netrc.read(@foopath)
130
+ end
131
+
132
+ after do
133
+ File.delete(@foopath) if File.exists? @foopath
134
+ end
135
+
136
+ describe 'if there is only a username' do
137
+ before do
138
+ @netrc['pinboard.in'] = 'Foo', nil
139
+ @netrc.save
140
+ end
141
+
142
+ it 'should return nil' do
143
+ expect { Pinup::Settings.get_token }.to raise_error
144
+ end
145
+ end
146
+
147
+ describe 'if there is only a password' do
148
+ before do
149
+ @netrc['pinboard.in'] = nil, 'Foo'
150
+ @netrc.save
151
+ end
152
+
153
+ it 'should return nil' do
154
+ token = Pinup::Settings.get_token
155
+ expect(token).to be_nil
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ describe 'clear_settings' do
162
+ describe 'if there is a settings file' do
163
+ before do
164
+ @settings = ""
165
+ Pinup::Settings.write_settings(@settings)
166
+ end
167
+
168
+ after do
169
+ File.delete(@settings_path) if File.exists?(@settings_path)
170
+ end
171
+
172
+ it 'should remove the file' do
173
+ Pinup::Settings.clear_settings
174
+ expect(File.exists?(@settings_path)).to be_false
175
+ end
176
+ end
177
+
178
+ describe 'if ther eis no settings file' do
179
+ before do
180
+ File.delete(@settings_path) if File.exists?(@settings_path)
181
+ end
182
+
183
+ it 'should not create a file' do
184
+ Pinup::Settings.clear_settings
185
+ expect(File.exists?(@settings_path)).to be_false
186
+ end
187
+ end
188
+ end
189
+
190
+ describe 'token' do
191
+ describe 'if there is invalid information' do
192
+ it 'should return nil for an empty username' do
193
+ expect(Pinup::Settings.token(nil, 'bar')).to be_nil
194
+ expect(Pinup::Settings.token('', 'bar')).to be_nil
195
+ end
196
+
197
+ it 'should return nil for an empty password' do
198
+ expect(Pinup::Settings.token('foo', nil)).to be_nil
199
+ expect(Pinup::Settings.token('foo', '')).to be_nil
200
+ end
201
+ end
202
+
203
+ describe 'valid information' do
204
+ it 'should return the formatted token' do
205
+ name = 'Foo'
206
+ pass = 'Bar'
207
+ response = Pinup::Settings.token(name, pass)
208
+ result = response == "#{ name }:#{ pass }"
209
+ expect(result).to be_true
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ #
8
+
9
+ require 'pinup'
10
+ require 'pinup/version.rb'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keith Smiley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colored
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: netrc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: launchy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.13.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: gli
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 2.5.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 2.5.6
97
+ description: Allows you to open and delete your Pinboard bookmarks in bulk
98
+ email: keithbsmiley@gmail.com
99
+ executables:
100
+ - pinup
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - bin/pinup
112
+ - lib/pinup.rb
113
+ - lib/pinup/bookmark.rb
114
+ - lib/pinup/commands/authorize.rb
115
+ - lib/pinup/commands/list.rb
116
+ - lib/pinup/commands/open.rb
117
+ - lib/pinup/queries.rb
118
+ - lib/pinup/settings.rb
119
+ - lib/pinup/version.rb
120
+ - pinup.gemspec
121
+ - spec/integration/authorize_spec.rb
122
+ - spec/integration/bookmark_spec.rb
123
+ - spec/integration/queries_spec.rb
124
+ - spec/integration/settings_spec.rb
125
+ - spec/spec_helper.rb
126
+ homepage: http://keith.so/
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.9.3
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.0.3
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Digest your Pinboard bookmarks in bulk
150
+ test_files:
151
+ - spec/integration/authorize_spec.rb
152
+ - spec/integration/bookmark_spec.rb
153
+ - spec/integration/queries_spec.rb
154
+ - spec/integration/settings_spec.rb
155
+ - spec/spec_helper.rb