wgif 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -22,12 +22,14 @@ describe WGif::Downloader do
22
22
  end
23
23
 
24
24
  it 'throws an error if the video is not found' do
25
- ViddlRb.should_receive(:get_urls).with(clip_url).and_return(['http://lol.wut'])
26
- expect{ downloader.get_video(clip_url) }.to raise_error(WGif::VideoNotFoundException)
25
+ ViddlRb.should_receive(:get_urls).with(clip_url)
26
+ .and_return(['http://lol.wut'])
27
+ expect { downloader.get_video(clip_url) }
28
+ .to raise_error(WGif::VideoNotFoundException)
27
29
  end
28
30
 
29
31
  it 'extracts a YouTube ID from a URL' do
30
- downloader.video_id("https://www.youtube.com/watch?v=tmNXKqeUtJM").should eq("tmNXKqeUtJM")
32
+ downloader.video_id('http://lol.wut?v=id').should eq('id')
31
33
  end
32
34
 
33
35
  context 'downloading videos' do
@@ -36,7 +38,8 @@ describe WGif::Downloader do
36
38
  ViddlRb.stub(:get_urls).and_return([clip_url])
37
39
  fake_request = double('Typhoeus::Request')
38
40
  fake_response = double('Typhoeus::Response')
39
- Typhoeus::Request.should_receive(:new).once.with(clip_url).and_return(fake_request)
41
+ Typhoeus::Request.should_receive(:new).once
42
+ .with(clip_url).and_return(fake_request)
40
43
  fake_request.should_receive(:on_headers)
41
44
  fake_request.should_receive(:on_body)
42
45
  fake_request.should_receive(:run).and_return(fake_response)
@@ -45,9 +48,9 @@ describe WGif::Downloader do
45
48
 
46
49
  it 'downloads a clip' do
47
50
  video = double(name: 'video')
48
- WGif::Video.should_receive(:new).with('roflcopter', "/tmp/wgif/roflcopter").
49
- and_return(video)
50
- video = downloader.get_video(clip_url)
51
+ WGif::Video.should_receive(:new)
52
+ .with('roflcopter', '/tmp/wgif/roflcopter').and_return(video)
53
+ downloader.get_video(clip_url)
51
54
  end
52
55
 
53
56
  it 'does not download the clip when already cached' do
@@ -60,11 +63,13 @@ describe WGif::Downloader do
60
63
 
61
64
  it 'throws an exception when the download URL is not found' do
62
65
  ViddlRb.stub(:get_urls).and_raise(RuntimeError)
63
- expect{ downloader.video_url('invalid url') }.to raise_error(WGif::VideoNotFoundException)
66
+ expect { downloader.video_url('invalid url') }
67
+ .to raise_error(WGif::VideoNotFoundException)
64
68
  end
65
69
 
66
70
  it 'throws an exception when the download URL is invalid' do
67
- expect{ downloader.video_id(nil) }.to raise_error(WGif::InvalidUrlException)
71
+ expect { downloader.video_id(nil) }
72
+ .to raise_error(WGif::InvalidUrlException)
68
73
  end
69
74
 
70
75
  end
File without changes
@@ -16,14 +16,14 @@ describe WGif::Installer do
16
16
  context 'checking for Homebrew' do
17
17
 
18
18
  it 'finds Homebrew when it exists' do
19
- expect(Kernel).to receive(:system).with('brew info > /dev/null').
20
- and_return(true)
19
+ expect(Kernel).to receive(:system).with('brew info > /dev/null')
20
+ .and_return(true)
21
21
  expect(installer.homebrew_installed?).to eq(true)
22
22
  end
23
23
 
24
24
  it 'returns false when Homebrew does not exist' do
25
- expect(Kernel).to receive(:system).with('brew info > /dev/null').
26
- and_return(false)
25
+ expect(Kernel).to receive(:system).with('brew info > /dev/null')
26
+ .and_return(false)
27
27
  expect(installer.homebrew_installed?).to eq(false)
28
28
  end
29
29
 
@@ -32,18 +32,18 @@ describe WGif::Installer do
32
32
  context 'checking for dependencies' do
33
33
 
34
34
  it 'returns true if dependencies are installed' do
35
- expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').
36
- and_return(true)
37
- expect(Kernel).to receive(:system).with('which convert > /dev/null').
38
- and_return(true)
35
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null')
36
+ .and_return(true)
37
+ expect(Kernel).to receive(:system).with('which convert > /dev/null')
38
+ .and_return(true)
39
39
  expect(installer.dependencies_installed?).to eq(true)
40
40
  end
41
41
 
42
42
  it 'returns false if dependencies are not installed' do
43
- expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').
44
- and_return(true)
45
- expect(Kernel).to receive(:system).with('which convert > /dev/null').
46
- and_return(false)
43
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null')
44
+ .and_return(true)
45
+ expect(Kernel).to receive(:system).with('which convert > /dev/null')
46
+ .and_return(false)
47
47
  expect(installer.dependencies_installed?).to eq(false)
48
48
  end
49
49
 
@@ -52,23 +52,23 @@ describe WGif::Installer do
52
52
  context 'installing dependencies' do
53
53
 
54
54
  it 'does not install dependencies if they are found' do
55
- expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').
56
- and_return(true)
55
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null')
56
+ .and_return(true)
57
57
  expect(Kernel).not_to receive(:system).with('brew install ffmpeg')
58
58
  installer.install('ffmpeg', 'ffmpeg')
59
59
  end
60
60
 
61
61
  it 'installs dependencies' do
62
- expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').
63
- and_return(false)
62
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null')
63
+ .and_return(false)
64
64
  expect(Kernel).to receive(:system).with('brew install ffmpeg')
65
65
  installer.install('ffmpeg', 'ffmpeg')
66
66
  end
67
67
 
68
68
  it 'has a list of its dependencies' do
69
- expect(installer.class::DEPENDENCIES).
70
- to eq([['ffmpeg', 'ffmpeg'],
71
- ['imagemagick', 'convert']])
69
+ expect(installer.class::DEPENDENCIES)
70
+ .to eq([['ffmpeg', 'ffmpeg'],
71
+ ['imagemagick', 'convert']])
72
72
  end
73
73
 
74
74
  it 'checks if a dependency exists' do
@@ -81,26 +81,36 @@ describe WGif::Installer do
81
81
  context 'running' do
82
82
 
83
83
  it 'installs all dependencies' do
84
- expect(Kernel).to receive(:system).with('brew info > /dev/null').
85
- and_return(true)
86
- expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').twice.
87
- and_return(true)
88
- expect(Kernel).to receive(:system).with('which convert > /dev/null').twice.
89
- and_return(false)
84
+ expect(Kernel).to receive(:system).with('brew info > /dev/null')
85
+ .and_return(true)
86
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').twice
87
+ .and_return(true)
88
+ expect(Kernel).to receive(:system).with('which convert > /dev/null').twice
89
+ .and_return(false)
90
90
  expect(Kernel).to receive(:system).with('brew install imagemagick')
91
- expect{ installer.run }.to raise_error(SystemExit)
91
+ expect { installer.run }.to raise_error(SystemExit)
92
92
  end
93
93
 
94
94
  it 'prints a helpful error if homebrew is not found' do
95
- expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null').
96
- and_return(true)
97
- expect(Kernel).to receive(:system).with('which convert > /dev/null').
98
- and_return(false)
99
- expect(Kernel).to receive(:system).with('brew info > /dev/null').
100
- and_return(false)
101
- expect{ installer.run }.to raise_error(SystemExit)
102
- expect(@mock_stdout.string).to eq("WGif can't find Homebrew. Visit http://brew.sh/ to get it.\n")
95
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null')
96
+ .and_return(true)
97
+ expect(Kernel).to receive(:system).with('which convert > /dev/null')
98
+ .and_return(false)
99
+ expect(Kernel).to receive(:system).with('brew info > /dev/null')
100
+ .and_return(false)
101
+ expect { installer.run }.to raise_error(SystemExit)
102
+ expect(@mock_stdout.string)
103
+ .to eq("WGif can't find Homebrew. Visit http://brew.sh/ to get it.\n")
103
104
  end
104
- end
105
105
 
106
+ it 'prints a helpful message if all dependencies are installed' do
107
+ expect(Kernel).to receive(:system).with('which ffmpeg > /dev/null')
108
+ .and_return(true)
109
+ expect(Kernel).to receive(:system).with('which convert > /dev/null')
110
+ .and_return(true)
111
+ expect { installer.run }.to raise_error(SystemExit)
112
+ expect(@mock_stdout.string)
113
+ .to eq("All dependencies are installed. Go make a gif.\n")
114
+ end
115
+ end
106
116
  end
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+ require 'spec_helper'
3
+ require 'typhoeus'
4
+ require 'wgif/uploader'
5
+
6
+ describe WGif::Uploader do
7
+ let(:api_key) { 'api-key' }
8
+ let(:uploader) { WGif::Uploader.new(api_key) }
9
+ let(:success) do
10
+ Typhoeus::Response.new(
11
+ response_code: 200,
12
+ return_code: :ok,
13
+ body: { data: { link: 'foo' } }.to_json
14
+ )
15
+ end
16
+ let(:failure) do
17
+ Typhoeus::Response.new(
18
+ response_code: 400,
19
+ return_code: :error,
20
+ body: { data: { error: 'You broke everything!' } }.to_json
21
+ )
22
+ end
23
+ let(:tempfile) { Tempfile.new('whatever') }
24
+ let(:request_params) do
25
+ { body: { image: tempfile },
26
+ headers: { Authorization: "Client-ID #{api_key}" } }
27
+ end
28
+
29
+ it 'sends an authorized POST request to Imgur with image file data' do
30
+ File.stub(:open).and_yield(tempfile)
31
+ expect(Typhoeus).to receive(:post)
32
+ .with('https://api.imgur.com/3/image', request_params).and_return(success)
33
+ uploader.upload(tempfile.path)
34
+ end
35
+
36
+ it 'raises an exception if request is not successful' do
37
+ Typhoeus.stub(/http/).and_return(failure)
38
+ expect { uploader.upload(tempfile.path) }
39
+ .to raise_error(WGif::ImgurException, 'You broke everything!')
40
+ end
41
+
42
+ it 'returns the url when successful' do
43
+ File.stub(:open).and_yield(tempfile)
44
+ expect(Typhoeus).to receive(:post)
45
+ .with('https://api.imgur.com/3/image', request_params).and_return(success)
46
+ expect(uploader.upload(tempfile.path)).to eq('foo')
47
+ end
48
+ end
File without changes
@@ -10,36 +10,37 @@ describe WGif::Video do
10
10
 
11
11
  it 'has a name and filepath' do
12
12
  clip.stub(:path).and_return('/tmp/wgif/bjork.mp4')
13
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
14
- video.name.should eq("bjork")
15
- video.clip.path.should eq("/tmp/wgif/bjork.mp4")
13
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
14
+ video.name.should eq('bjork')
15
+ video.clip.path.should eq('/tmp/wgif/bjork.mp4')
16
16
  end
17
17
 
18
18
  it 'sets up a logger' do
19
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
20
- video.logger.instance_variable_get(:@logdev).filename.should eq("/tmp/wgif/bjork.log")
19
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
20
+ video.logger.instance_variable_get(:@logdev).filename
21
+ .should eq('/tmp/wgif/bjork.log')
21
22
  end
22
23
 
23
24
  it 'redirects FFMPEG log output to a file' do
24
25
  expect(FFMPEG).to receive(:logger=).with(an_instance_of(Logger))
25
- video = described_class.new "penguin", "spec/fixtures/penguin.mp4"
26
+ described_class.new 'penguin', 'spec/fixtures/penguin.mp4'
26
27
  end
27
28
 
28
29
  it 'is trimmable' do
29
30
  clip.stub(:duration).and_return(5.0)
30
31
  expect(clip).to receive(:transcode)
31
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
32
- video = video.trim("00:00:00", 5.0)
32
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
33
+ video = video.trim('00:00:00', 5.0)
33
34
  video.clip.duration.should eq(5.0)
34
35
  end
35
36
 
36
37
  it 'returns its frames' do
37
38
  expect(clip).to receive(:transcode)
38
39
  FileUtils.stub(:rm)
39
- fake_frames = ["one", "two", "three"]
40
- expect(Dir).to receive(:glob).with('/tmp/wgif/frames/*.png').twice.
41
- and_return(fake_frames)
42
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
40
+ fake_frames = ['one', 'two', 'three']
41
+ expect(Dir).to receive(:glob).with('/tmp/wgif/frames/*.png').twice
42
+ .and_return(fake_frames)
43
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
43
44
  frames = video.to_frames
44
45
  frames.count.should eq(3)
45
46
  end
@@ -51,26 +52,30 @@ describe WGif::Video do
51
52
  FileUtils.stub(:rm)
52
53
  expect(clip).to receive(:duration).and_return 2
53
54
  expect(Dir).to receive(:glob).with('/tmp/wgif/frames/*.png').twice
54
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
55
- frames = video.to_frames(frames: 10)
55
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
56
+ video.to_frames(frames: 10)
56
57
  end
57
58
 
58
59
  it 'catches transcode errors and raises an exception' do
59
60
  expect(clip).to receive(:transcode).and_raise(FFMPEG::Error)
60
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
61
- expect{ video.trim("00:00:00", 5.0) }.to raise_error(WGif::ClipEncodingException)
61
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
62
+ expect { video.trim('00:00:00', 5.0) }
63
+ .to raise_error(WGif::ClipEncodingException)
62
64
  end
63
65
 
64
66
  it 'silences transcode errors from ripping frames' do
65
- expect(clip).to receive(:transcode).and_raise(FFMPEG::Error.new "no output file created")
66
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
67
- expect{ video.trim("00:00:00", 5.0) }.not_to raise_error
67
+ expect(clip).to receive(:transcode)
68
+ .and_raise(FFMPEG::Error.new 'no output file created')
69
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
70
+ expect { video.trim('00:00:00', 5.0) }
71
+ .not_to raise_error
68
72
  end
69
73
 
70
74
  it 'silences transcode errors from ripping frames when input is invalid' do
71
- message = "no output file created. Invalid data found when processing input"
75
+ message = 'no output file created. Invalid data found when processing input'
72
76
  expect(clip).to receive(:transcode).and_raise(FFMPEG::Error.new message)
73
- video = described_class.new "bjork", "/tmp/wgif/bjork.mp4"
74
- expect{ video.trim("00:00:00", 5.0) }.to raise_error(WGif::ClipEncodingException)
77
+ video = described_class.new 'bjork', '/tmp/wgif/bjork.mp4'
78
+ expect { video.trim('00:00:00', 5.0) }
79
+ .to raise_error(WGif::ClipEncodingException)
75
80
  end
76
81
  end
data/wgif.gemspec CHANGED
@@ -4,30 +4,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'wgif/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "wgif"
7
+ spec.name = 'wgif'
8
8
  spec.version = WGif::VERSION
9
- spec.authors = ["Connor Mendenhall"]
10
- spec.email = ["ecmendenhall@gmail.com"]
11
- spec.description = %q{A command-line tool for creating animated GIFs.}
12
- spec.summary = %q{A command-line tool for creating animated GIFs from YouTube videos. Uses FFmpeg and ImageMagick.}
13
- spec.homepage = "https://github.com/ecmendenhall/wgif"
14
- spec.license = "MIT"
9
+ spec.authors = ['Connor Mendenhall']
10
+ spec.email = ['ecmendenhall@gmail.com']
11
+ spec.description = %q(A command-line tool for creating animated GIFs.)
12
+ spec.summary = %q(A command-line tool for creating animated GIFs from YouTube videos. Uses FFmpeg and ImageMagick.)
13
+ spec.homepage = 'https://github.com/ecmendenhall/wgif'
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($/) << 'lib/wgif/uploader.rb'
17
- spec.executables = ["wgif"]
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ['wgif']
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
20
 
21
+ spec.add_dependency 'rmagick'
22
+ spec.add_dependency 'ruby-progressbar'
23
+ spec.add_dependency 'streamio-ffmpeg'
24
+ spec.add_dependency 'typhoeus', '~> 0.6'
25
+ spec.add_dependency 'viddl-rb'
21
26
 
22
- spec.add_dependency "rmagick"
23
- spec.add_dependency "ruby-progressbar"
24
- spec.add_dependency "streamio-ffmpeg"
25
- spec.add_dependency "typhoeus", "~> 0.6"
26
- spec.add_dependency "viddl-rb"
27
-
28
- spec.add_development_dependency "bundler", "~> 1.3"
29
- spec.add_development_dependency "pry"
30
- spec.add_development_dependency "rake"
31
- spec.add_development_dependency "rspec", "~> 2.14"
32
- spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency 'bundler', '~> 1.3'
28
+ spec.add_development_dependency 'codeclimate-test-reporter'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rspec', '~> 2.14'
32
+ spec.add_development_dependency 'simplecov'
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wgif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connor Mendenhall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: pry
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +182,7 @@ files:
168
182
  - Rakefile
169
183
  - bin/wgif
170
184
  - lib/wgif.rb
185
+ - lib/wgif/argument_parser.rb
171
186
  - lib/wgif/cli.rb
172
187
  - lib/wgif/download_bar.rb
173
188
  - lib/wgif/downloader.rb
@@ -178,15 +193,17 @@ files:
178
193
  - lib/wgif/version.rb
179
194
  - lib/wgif/video.rb
180
195
  - lib/wgif/video_cache.rb
196
+ - spec/integration/empty_image_list_spec.rb
181
197
  - spec/spec_helper.rb
182
- - spec/wgif/cli_spec.rb
183
- - spec/wgif/download_bar_spec.rb
184
- - spec/wgif/downloader_spec.rb
185
- - spec/wgif/gif_maker_spec.rb
186
- - spec/wgif/installer_spec.rb
187
- - spec/wgif/uploader_spec.rb
188
- - spec/wgif/video_cache_spec.rb
189
- - spec/wgif/video_spec.rb
198
+ - spec/unit/wgif/argument_parser_spec.rb
199
+ - spec/unit/wgif/cli_spec.rb
200
+ - spec/unit/wgif/download_bar_spec.rb
201
+ - spec/unit/wgif/downloader_spec.rb
202
+ - spec/unit/wgif/gif_maker_spec.rb
203
+ - spec/unit/wgif/installer_spec.rb
204
+ - spec/unit/wgif/uploader_spec.rb
205
+ - spec/unit/wgif/video_cache_spec.rb
206
+ - spec/unit/wgif/video_spec.rb
190
207
  - wgif.gemspec
191
208
  homepage: https://github.com/ecmendenhall/wgif
192
209
  licenses:
@@ -214,12 +231,14 @@ specification_version: 4
214
231
  summary: A command-line tool for creating animated GIFs from YouTube videos. Uses
215
232
  FFmpeg and ImageMagick.
216
233
  test_files:
234
+ - spec/integration/empty_image_list_spec.rb
217
235
  - spec/spec_helper.rb
218
- - spec/wgif/cli_spec.rb
219
- - spec/wgif/download_bar_spec.rb
220
- - spec/wgif/downloader_spec.rb
221
- - spec/wgif/gif_maker_spec.rb
222
- - spec/wgif/installer_spec.rb
223
- - spec/wgif/uploader_spec.rb
224
- - spec/wgif/video_cache_spec.rb
225
- - spec/wgif/video_spec.rb
236
+ - spec/unit/wgif/argument_parser_spec.rb
237
+ - spec/unit/wgif/cli_spec.rb
238
+ - spec/unit/wgif/download_bar_spec.rb
239
+ - spec/unit/wgif/downloader_spec.rb
240
+ - spec/unit/wgif/gif_maker_spec.rb
241
+ - spec/unit/wgif/installer_spec.rb
242
+ - spec/unit/wgif/uploader_spec.rb
243
+ - spec/unit/wgif/video_cache_spec.rb
244
+ - spec/unit/wgif/video_spec.rb