firebrew 0.2.0 → 0.3.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: cfb18b86ed200214495e26c35083760ee06adbfa
4
- data.tar.gz: 5d06456d51c4d55ac9cc11355a38b6fe0de60599
3
+ metadata.gz: 1d7c07821b8298bda0079dd30bdde6dc71cb3f5c
4
+ data.tar.gz: 1b9f7daf7f567a3748d28b139427f1cbae6a1af7
5
5
  SHA512:
6
- metadata.gz: b466f350381f97a8ae2e178d3d0a08fa3379ccff2524dfec7f72b14d8945fc33333a787ee839c137b8b6d536f659fff2c452137b1661b3fb4e177085319f0e40
7
- data.tar.gz: 54367c7cb733c9a08466ef91a6ef2142783fb7924d0a7e8336a7afea1153e8d5d95915df33b1e7ed0a2fcd87c14b71dae4fe720a1c3c440efe6cb46ae9970e78
6
+ metadata.gz: 9d81f90568ef3ac06350cf0c82f68f3798a8b49571955f25da2eb221c6ca83bc3bccba1b2377ecc9bb29dcf6e9d06e77bb19a5e03c0b486553e23d86d17579d4
7
+ data.tar.gz: b78494beacbcb8dd6154964a600fced0b866acb39b217baed1d1c7f92823517d93a151baf06930e3ce66f4f9958282e31a9c9691bc0fdf9ad940280a72e8c703
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0](https://github.com/mrk21/firebrew/tree/v0.3.0) - 2014-09-30
4
+
5
+ * Future [#36](https://github.com/mrk21/firebrew/issues/36): Implement the `os` gem
6
+ * Future [#18](https://github.com/mrk21/firebrew/issues/18): Make it possible to display a download progress of the extension
7
+
3
8
  ## [0.2.0](https://github.com/mrk21/firebrew/tree/v0.2.0) - 2014-08-31
4
9
 
5
10
  * Future [#35](https://github.com/mrk21/firebrew/issues/35): Add the subcommand help
@@ -21,8 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "webmock", "~> 1.19"
24
25
 
25
26
  spec.add_dependency "inifile", "~> 2.0"
26
27
  spec.add_dependency "rubyzip", "~> 1.1"
27
28
  spec.add_dependency "faraday", "~> 0.9"
29
+ spec.add_dependency "os", "~> 0.9"
30
+ spec.add_dependency "ruby-progressbar", "~> 1.6"
28
31
  end
@@ -151,7 +151,7 @@ module Firebrew
151
151
  end
152
152
 
153
153
  def execute
154
- runner = Runner.new(self.arguments[:config])
154
+ runner = Runner.new(self.arguments[:config], true)
155
155
 
156
156
  case self.arguments[:command]
157
157
  when :search, :list then
@@ -0,0 +1,106 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'ruby-progressbar'
4
+
5
+ module Firebrew
6
+ class Downloader
7
+ def self.normalize_uri(uri)
8
+ begin
9
+ uri = URI.parse(uri)
10
+ rescue URI::InvalidURIError
11
+ uri = URI.parse(URI.encode uri)
12
+ end
13
+
14
+ uri.normalize!
15
+
16
+ case uri.scheme
17
+ when 'http','https','file' then
18
+ # do nothing
19
+ when nil then
20
+ uri.scheme = 'file'
21
+ path = File.expand_path(uri.path)
22
+ path = "/#{path}" if path =~ /^[a-zA-Z]:/
23
+ uri.path = path
24
+ when /^[a-zA-Z]$/ then
25
+ uri.path = "/#{uri.scheme.upcase}:#{uri.path}"
26
+ uri.scheme = 'file'
27
+ else
28
+ raise Firebrew::NetworkError, "Don't support the scheme: #{uri.scheme}"
29
+ end
30
+
31
+ uri
32
+ end
33
+
34
+ def initialize(uri, out, progress_options={})
35
+ @uri = self.class.normalize_uri(uri)
36
+ @out = out
37
+ @progress_options = progress_options
38
+ end
39
+
40
+ def exec
41
+ case @uri.scheme
42
+ when 'http','https' then
43
+ @size = loop do
44
+ response = self.http_connection do |http, path|
45
+ http.head(path)
46
+ end
47
+ if response.code.to_i == 302 then
48
+ @uri = self.class.normalize_uri(response['Location'])
49
+ next
50
+ end
51
+ break response['Content-Length'].to_i
52
+ end
53
+
54
+ progress_bar = self.create_progress_bar
55
+
56
+ self.http_connection do |http, path|
57
+ http.get(path) do |chunk|
58
+ progress_bar.progress += chunk.size
59
+ @out.write chunk
60
+ end
61
+ end
62
+
63
+ when 'file' then
64
+ @size = self.file_connection do |file|
65
+ file.size
66
+ end
67
+
68
+ progress_bar = self.create_progress_bar
69
+
70
+ self.file_connection do |file|
71
+ loop do
72
+ chunk = file.read(1000)
73
+ break if chunk.nil?
74
+ progress_bar.progress += chunk.size
75
+ @out.write chunk
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ protected
82
+
83
+ def http_connection(&block)
84
+ Net::HTTP.start(@uri.host, @uri.port, use_ssl: @uri.scheme == 'https') do |http|
85
+ block[http, @uri.request_uri]
86
+ end
87
+ end
88
+
89
+ def file_connection(&block)
90
+ path = @uri.path.gsub(%r{/([a-zA-Z]:)},'\1')
91
+ open(URI.decode(path), &block)
92
+ end
93
+
94
+ def create_progress_bar
95
+ options = {
96
+ format: "%e |%B| [%j%%]",
97
+ progress_mark: '=',
98
+ remainder_mark: '・',
99
+ }
100
+ options.merge! @progress_options
101
+ options.merge! total: @size
102
+ options[:output] = File.open(File::NULL,'w') unless options[:output]
103
+ ProgressBar.create(options)
104
+ end
105
+ end
106
+ end
@@ -1,4 +1,5 @@
1
1
  require 'shellwords'
2
+ require 'os'
2
3
 
3
4
  module Firebrew::Firefox
4
5
  class Command
@@ -12,10 +13,10 @@ module Firebrew::Firefox
12
13
  @config = config
13
14
  @executer = executer
14
15
  begin
15
- result = if ENV['OS'].nil? then
16
- @executer.exec('%{firefox} --version' % self.escaped_config)
17
- else
16
+ result = if OS.windows? then
18
17
  @executer.exec('"%{firefox}" --version' % @config)
18
+ else
19
+ @executer.exec('%{firefox} --version' % self.escaped_config)
19
20
  end
20
21
  raise Firebrew::FirefoxCommandError, 'Command is not Firefox: %{firefox}' % @config unless result[0] =~ /Mozilla Firefox/
21
22
  raise Firebrew::FirefoxCommandError, 'Command is not Firefox: %{firefox}' % @config unless result[1] == 0
@@ -26,10 +27,10 @@ module Firebrew::Firefox
26
27
 
27
28
  def version
28
29
  return @version unless @version.nil?
29
- result = if ENV['OS'].nil? then
30
- @executer.exec('%{firefox} --version' % self.escaped_config)[0]
31
- else
30
+ result = if OS.windows? then
32
31
  @executer.exec('"%{firefox}" --version' % @config)[0]
32
+ else
33
+ @executer.exec('%{firefox} --version' % self.escaped_config)[0]
33
34
  end
34
35
  @version = result.match(/[0-9.]+/)[0]
35
36
  end
@@ -2,8 +2,10 @@ require 'fileutils'
2
2
  require 'open-uri'
3
3
  require 'json'
4
4
  require 'rexml/document'
5
+ require 'rake/pathmap'
5
6
  require 'zip'
6
7
  require 'firebrew/firefox/basic_extension'
8
+ require 'firebrew/downloader'
7
9
 
8
10
  module Firebrew::Firefox
9
11
  class Extension < BasicExtension
@@ -39,35 +41,42 @@ module Firebrew::Firefox
39
41
  result
40
42
  end
41
43
 
42
- def install(extension)
44
+ def install(extension, is_displaying_progress = false)
43
45
  dir = File.join(self.profile.path, 'extensions')
44
46
  FileUtils.mkdir_p dir
47
+ xpi_path = '%s.xpi' % File.join(dir, extension.guid)
45
48
 
46
- open([extension.uri].flatten.first, 'rb') do |r|
47
- xpi = Zip::File.open(r)
48
- install_manifests = xpi.find_entry('install.rdf')
49
- install_manifests = install_manifests.get_input_stream.read
50
- install_manifests = REXML::Document.new(install_manifests)
51
- is_unpacking = REXML::XPath.match(install_manifests, '/RDF/Description/em:unpack/text()').first
52
- is_unpacking = is_unpacking.nil? ? false : is_unpacking.value.strip == 'true'
49
+ File.open(xpi_path,'wb') do |out|
50
+ uri = [extension.uri].flatten.first
51
+ pout = is_displaying_progress ? $stdout : nil
52
+ Firebrew::Downloader.new(uri, out, output: pout).exec
53
+ end
54
+
55
+ xpi = Zip::File.open(File.open(xpi_path,'rb'))
56
+ install_manifests = xpi.find_entry('install.rdf')
57
+ install_manifests = install_manifests.get_input_stream.read
58
+ install_manifests = REXML::Document.new(install_manifests)
59
+ is_unpacking = REXML::XPath.match(install_manifests, '/RDF/Description/em:unpack/text()').first
60
+ is_unpacking = is_unpacking.nil? ? false : is_unpacking.value.strip == 'true'
61
+
62
+ if is_unpacking then
63
+ extension.uri = xpi_path.pathmap('%X')
64
+ FileUtils.mkdir_p(extension.uri)
53
65
 
54
- if is_unpacking then
55
- extension.uri = File.join(dir, extension.guid)
56
- FileUtils.mkdir_p(extension.uri)
57
- xpi.each do |entry|
58
- next if entry.ftype == :directory
59
- content = entry.get_input_stream.read
60
- Dir.chdir(extension.uri) do
61
- FileUtils.mkdir_p File.dirname(entry.name)
62
- File.write(entry.name, content)
63
- end
64
- end
65
- else
66
- extension.uri = '%s.xpi' % File.join(dir, extension.guid)
67
- open(extension.uri, 'wb') do |w|
68
- w.write r.read
66
+ xpi.each do |entry|
67
+ next if entry.ftype == :directory
68
+ content = entry.get_input_stream.read
69
+ Dir.chdir(extension.uri) do
70
+ FileUtils.mkdir_p File.dirname(entry.name)
71
+ File.write(entry.name, content)
69
72
  end
70
73
  end
74
+
75
+ xpi.close
76
+ FileUtils.rm_rf(xpi_path)
77
+ else
78
+ extension.uri = xpi_path
79
+ xpi.close
71
80
  end
72
81
 
73
82
  self.add(extension)
@@ -75,7 +84,7 @@ module Firebrew::Firefox
75
84
  end
76
85
 
77
86
  def uninstall(extension)
78
- FileUtils.rm_rf extension.uri
87
+ FileUtils.rm_r extension.uri
79
88
  self.remove(extension)
80
89
  self.push
81
90
  end
@@ -7,25 +7,24 @@ module Firebrew
7
7
  class Runner
8
8
  attr_accessor :config, :profile
9
9
 
10
- def self.default_config(platform = RUBY_PLATFORM)
10
+ def self.default_config
11
11
  result = {
12
12
  base_dir: ENV['FIREBREW_FIREFOX_PROFILE_BASE_DIR'],
13
13
  firefox: ENV['FIREBREW_FIREFOX'],
14
14
  profile: ENV['FIREBREW_FIREFOX_PROFILE'] || 'default',
15
15
  }
16
16
 
17
- case platform
18
- when /darwin/ then
17
+ if OS.mac? then
19
18
  result[:base_dir] ||= '~/Library/Application Support/Firefox'
20
19
  result[:firefox] ||= '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
21
20
  result[:os] = 'darwin'
22
21
 
23
- when /linux/ then
22
+ elsif OS.linux? then
24
23
  result[:base_dir] ||= '~/.mozilla/firefox'
25
24
  result[:firefox] ||= '/usr/bin/firefox'
26
25
  result[:os] = 'linux'
27
26
 
28
- when /mswin(?!ce)|mingw|cygwin|bccwin/ then
27
+ elsif OS.windows? then
29
28
  appdata = ENV['APPDATA'].to_s.gsub('\\','/')
30
29
  programfiles = (ENV['PROGRAMFILES(X86)'] || ENV['PROGRAMFILES']).to_s.gsub('\\','/')
31
30
  result[:base_dir] ||= File.join(appdata, 'Mozilla/Firefox')
@@ -36,8 +35,9 @@ module Firebrew
36
35
  result
37
36
  end
38
37
 
39
- def initialize(config={})
38
+ def initialize(config={}, is_displaying_progress = false)
40
39
  self.config = self.class.default_config.merge(config)
40
+ @is_displaying_progress = is_displaying_progress
41
41
 
42
42
  @profile_manager = Firefox::Profile::Manager.new(
43
43
  base_dir: self.config[:base_dir],
@@ -56,7 +56,7 @@ module Firebrew
56
56
  extension = self.profile.extensions.find(params[:term])
57
57
  raise Firebrew::OperationAlreadyCompletedError, "Already installed: #{params[:term]}" unless extension.nil?
58
58
  result = self.fetch_api(term: params[:term], max: 1).first
59
- self.profile.extensions.install(result)
59
+ self.profile.extensions.install(result, @is_displaying_progress)
60
60
  end
61
61
 
62
62
  def uninstall(params={})
@@ -1,3 +1,3 @@
1
1
  module Firebrew
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'digest/md5'
4
+ require 'webmock/rspec'
5
+ require 'os'
6
+
7
+ module Firebrew
8
+ describe Downloader do
9
+ describe '::normalize_uri(uri)' do
10
+ subject do
11
+ Downloader.normalize_uri(self.uri)
12
+ end
13
+
14
+ context 'when the uri contained spaces and unicode characters etc' do
15
+ let(:uri){'http://www.example.com/a b/あ.html'}
16
+ let(:expected_uri){URI.parse('http://www.example.com/a%20b/%E3%81%82.html')}
17
+
18
+ it 'should be encoded by percent-encoding' do
19
+ is_expected.to eq(self.expected_uri)
20
+ end
21
+ end
22
+
23
+ context 'when the uri path was empty' do
24
+ let(:uri){'http://www.example.com'}
25
+ it 'path should be "/"' do
26
+ expect(subject.path).to eq('/')
27
+ end
28
+ end
29
+
30
+ context 'when the uri scheme was "http"' do
31
+ let(:uri){'http://www.example.com/a/b.html'}
32
+ let(:expected_uri){URI.parse('http://www.example.com/a/b.html')}
33
+ it { is_expected.to eq(self.expected_uri) }
34
+ end
35
+
36
+ context 'when the uri scheme was "https"' do
37
+ let(:uri){'https://www.example.com/a/b.html'}
38
+ let(:expected_uri){URI.parse('https://www.example.com/a/b.html')}
39
+ it { is_expected.to eq(self.expected_uri) }
40
+ end
41
+
42
+ context 'when the uri scheme was "file"' do
43
+ if OS.windows? then
44
+ let(:uri){'file:///C:/a/b.html'}
45
+ let(:expected_uri){URI.parse('file:///C:/a/b.html')}
46
+ else
47
+ let(:uri){'file:///a/b.html'}
48
+ let(:expected_uri){URI.parse('file:///a/b.html')}
49
+ end
50
+ it { is_expected.to eq(self.expected_uri) }
51
+ end
52
+
53
+ context 'when the uri scheme was empty' do
54
+ if OS.windows? then
55
+ let(:uri){'C:/a/b.html'}
56
+ let(:expected_uri){URI.parse('file:///C:/a/b.html')}
57
+ else
58
+ let(:uri){'/a/b.html'}
59
+ let(:expected_uri){URI.parse('file:///a/b.html')}
60
+ end
61
+
62
+ it 'should convert a file scheme' do
63
+ is_expected.to eq(self.expected_uri)
64
+ end
65
+
66
+ context 'when the path was relative' do
67
+ let(:uri){'./a/b.html'}
68
+
69
+ if OS.windows? then
70
+ let(:expected_uri){URI.parse("file:///#{Dir.pwd}/a/b.html")}
71
+ else
72
+ let(:expected_uri){URI.parse("file://#{Dir.pwd}/a/b.html")}
73
+ end
74
+
75
+ it 'should be an absolute path from the current dir' do
76
+ is_expected.to eq(self.expected_uri)
77
+ end
78
+ end
79
+ end
80
+
81
+ context 'when the uri scheme was not "http", "https" and "file"' do
82
+ let(:uri){'hoge:///a/b/c'}
83
+
84
+ it 'should throw Firebrew::NetworkError' do
85
+ expect{subject}.to raise_error(Firebrew::NetworkError, "Don't support the scheme: hoge")
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#initialize(uri, out[, progress_options]) -> #exec()' do
91
+ before do
92
+ self.before_callback[]
93
+ Downloader.new(self.uri, self.out).exec
94
+ self.out.rewind
95
+ end
96
+
97
+ let(:before_callback){->{}}
98
+ let(:uri){''}
99
+ let(:out){StringIO.new}
100
+
101
+ context 'when the uri scheme was "file"' do
102
+ let(:uri){'./spec/fixtures/firefox/extension/unpack_false.xpi'}
103
+
104
+ it 'should download a content which is referenced by the uri' do
105
+ md5, path = File.read(self.uri.pathmap('%X.md5')).split(/\s+/)
106
+ expect(Digest::MD5.hexdigest(self.out.read)).to eq(md5)
107
+ end
108
+ end
109
+
110
+ context 'when the uri scheme was "http" or "https"' do
111
+ let(:before_callback){->{
112
+ response = File.open(self.response_path, 'rb').read
113
+ stub_request(:head, 'www.example.com').to_return(headers: {
114
+ 'Content-Length'=> response.size
115
+ })
116
+ stub_request(:get, 'www.example.com').to_return(body: response)
117
+ }}
118
+
119
+ let(:uri){'http://www.example.com'}
120
+ let(:response_path){'./spec/fixtures/firefox/extension/unpack_false.xpi'}
121
+
122
+ it 'should download a content which is referenced by the uri' do
123
+ md5, path = File.read(self.response_path.pathmap('%X.md5')).split(/\s+/)
124
+ expect(Digest::MD5.hexdigest(self.out.read)).to eq(md5)
125
+ end
126
+
127
+ context 'when the response status code was 302' do
128
+ let(:before_callback){->{
129
+ response = File.open(self.response_path, 'rb').read
130
+ stub_request(:head, 'www.example.com').to_return(status: 302, headers: {
131
+ 'Location'=> 'http://dl.example.com/'
132
+ })
133
+ stub_request(:head, 'dl.example.com').to_return(headers: {
134
+ 'Content-Length'=> response.size
135
+ })
136
+ stub_request(:get, 'dl.example.com').to_return(body: response)
137
+ }}
138
+
139
+ let(:uri){'http://www.example.com'}
140
+ let(:response_path){'./spec/fixtures/firefox/extension/unpack_false.xpi'}
141
+
142
+ it 'should download a content which is referenced by the uri' do
143
+ md5, path = File.read(self.response_path.pathmap('%X.md5')).split(/\s+/)
144
+ expect(Digest::MD5.hexdigest(self.out.read)).to eq(md5)
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -7,7 +7,7 @@ module Firebrew::Firefox
7
7
  let(:manager) do
8
8
  Extension::Manager.new(
9
9
  profile: Profile.new(
10
- path: File.join(Dir.pwd, 'tmp')
10
+ path: './tmp'
11
11
  )
12
12
  )
13
13
  end
@@ -17,13 +17,13 @@ module Firebrew::Firefox
17
17
  name: 'Japanese Language Pack',
18
18
  guid: 'langpack-ja@firefox.mozilla.org',
19
19
  version: '30.0',
20
- uri: File.join(Dir.pwd, 'tmp/extensions/langpack-ja@firefox.mozilla.org.xpi')
20
+ uri: './tmp/extensions/langpack-ja@firefox.mozilla.org.xpi'
21
21
  }, self.manager),
22
22
  Extension.new({
23
23
  name: 'Vimperator',
24
24
  guid: 'vimperator@mozdev.org',
25
25
  version: '3.8.2',
26
- uri: File.join(Dir.pwd, 'tmp/extensions/vimperator@mozdev.org.xpi')
26
+ uri: './tmp/extensions/vimperator@mozdev.org.xpi'
27
27
  }, self.manager)
28
28
  ]}
29
29
 
@@ -88,14 +88,15 @@ module Firebrew::Firefox
88
88
  end
89
89
  end
90
90
 
91
- describe '#install(extension)' do
91
+ describe '#install(extension[, is_displaying_progress])' do
92
92
  subject { self.instance.install(self.extension) }
93
93
 
94
94
  let(:extension) do
95
- Extension.new({
96
- guid: 'hoge@example.org',
97
- uri: File.join(Dir.pwd, 'spec/fixtures/firefox/extension/unpack_false.xpi')
98
- }, self.manager)
95
+ Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager)
96
+ end
97
+
98
+ let(:extension_uri) do
99
+ './spec/fixtures/firefox/extension/unpack_false.xpi'
99
100
  end
100
101
 
101
102
  let(:expected_path) do
@@ -104,14 +105,15 @@ module Firebrew::Firefox
104
105
 
105
106
  it 'should copy the `path/to/profile/extensions/<GUID>.xpi`' do
106
107
  subject
107
- expect(File.exists? self.expected_path).to be_truthy
108
+ md5, path = File.read(self.extension_uri.pathmap('%X.md5')).split(/\s+/)
109
+ expect(Digest::MD5.hexdigest(File.open(self.expected_path,'rb').read)).to eq(md5)
108
110
  end
109
111
 
110
112
  it 'should add the `extension` extension' do
111
113
  subject
112
114
  all = self.instance.all
113
115
  extension = self.extension
114
- extension.uri = File.join(Dir.pwd, 'tmp/extensions/hoge@example.org.xpi')
116
+ extension.uri = './tmp/extensions/hoge@example.org.xpi'
115
117
  expect(all.size).to eq(3)
116
118
  expect(all[0]).to eq(self.extensions[0])
117
119
  expect(all[1]).to eq(self.extensions[1])
@@ -120,13 +122,14 @@ module Firebrew::Firefox
120
122
 
121
123
  context 'when an `uri` of the `extension` was equal or greater than two' do
122
124
  let(:extension) do
123
- Extension.new({
124
- guid: 'hoge@example.org',
125
- uri: [
126
- File.join(Dir.pwd, 'spec/fixtures/firefox/extension/unpack_false.xpi'),
127
- File.join(Dir.pwd, 'spec/fixtures/firefox/extension/not_exists.xpi'),
128
- ]
129
- }, self.manager)
125
+ Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager)
126
+ end
127
+
128
+ let(:extension_uri) do
129
+ [
130
+ './spec/fixtures/firefox/extension/unpack_false.xpi',
131
+ './spec/fixtures/firefox/extension/not_exists.xpi'
132
+ ]
130
133
  end
131
134
 
132
135
  it 'should not throw exceptions' do
@@ -136,22 +139,24 @@ module Firebrew::Firefox
136
139
 
137
140
  context 'when an `em:unpack` value of the `install.rdf` in the XPI package not exsisted' do
138
141
  let(:extension) do
139
- Extension.new({
140
- guid: 'hoge@example.org',
141
- uri: File.join(Dir.pwd, 'spec/fixtures/firefox/extension/unpack_null.xpi')
142
- }, self.manager)
142
+ Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager)
143
+ end
144
+
145
+ let(:extension_uri) do
146
+ './spec/fixtures/firefox/extension/unpack_null.xpi'
143
147
  end
144
148
 
145
149
  it 'should copy the `path/to/profile/extensions/<GUID>.xpi`' do
146
150
  subject
147
- expect(File.exists? self.expected_path).to be_truthy
151
+ md5, path = File.read(self.extension_uri.pathmap('%X.md5')).split(/\s+/)
152
+ expect(Digest::MD5.hexdigest(File.open(self.expected_path,'rb').read)).to eq(md5)
148
153
  end
149
154
 
150
155
  it 'should add the `extension` extension' do
151
156
  subject
152
157
  all = self.instance.all
153
158
  extension = self.extension
154
- extension.uri = File.join(Dir.pwd, 'tmp/extensions/hoge@example.org.xpi')
159
+ extension.uri = './tmp/extensions/hoge@example.org.xpi'
155
160
  expect(all.size).to eq(3)
156
161
  expect(all[0]).to eq(self.extensions[0])
157
162
  expect(all[1]).to eq(self.extensions[1])
@@ -161,10 +166,11 @@ module Firebrew::Firefox
161
166
 
162
167
  context 'when an `em:unpack` value of the `install.rdf` in the XPI package was true' do
163
168
  let(:extension) do
164
- Extension.new({
165
- guid: 'hoge@example.org',
166
- uri: './spec/fixtures/firefox/extension/unpack_true.xpi'
167
- }, self.manager)
169
+ Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager)
170
+ end
171
+
172
+ let(:extension_uri) do
173
+ './spec/fixtures/firefox/extension/unpack_true.xpi'
168
174
  end
169
175
 
170
176
  let(:expected_path) do
@@ -178,7 +184,7 @@ module Firebrew::Firefox
178
184
 
179
185
  it 'should unzip all files in the XPI package' do
180
186
  subject
181
- md5list = File.read('./spec/fixtures/firefox/extension/unpack_true.md5')
187
+ md5list = File.read(self.extension_uri.pathmap('%X.md5'))
182
188
  Dir.chdir(self.expected_path) do
183
189
  md5list.each_line do |item|
184
190
  md5, path = item.split(/\s+/)
@@ -191,7 +197,7 @@ module Firebrew::Firefox
191
197
  subject
192
198
  all = self.instance.all
193
199
  extension = self.extension
194
- extension.uri = File.join(Dir.pwd, 'tmp/extensions/hoge@example.org')
200
+ extension.uri = './tmp/extensions/hoge@example.org'
195
201
  expect(all.size).to eq(3)
196
202
  expect(all[0]).to eq(self.extensions[0])
197
203
  expect(all[1]).to eq(self.extensions[1])
@@ -204,7 +210,7 @@ module Firebrew::Firefox
204
210
  let(:extension) do
205
211
  Extension.new({
206
212
  guid: 'hoge@example.org',
207
- uri: File.join(Dir.pwd, 'tmp/extensions/hoge@example.org.xpi')
213
+ uri: './tmp/extensions/hoge@example.org.xpi'
208
214
  }, self.manager)
209
215
  end
210
216
 
@@ -234,7 +240,7 @@ module Firebrew::Firefox
234
240
  let(:extension) do
235
241
  Extension.new({
236
242
  guid: 'hoge@example.org',
237
- uri: File.join(Dir.pwd, 'tmp/extensions/hoge@example.org')
243
+ uri: './tmp/extensions/hoge@example.org'
238
244
  }, self.manager)
239
245
  end
240
246
 
@@ -1,14 +1,13 @@
1
1
  require 'spec_helper'
2
+ require 'os'
2
3
 
3
4
  module Firebrew
4
5
  describe Firebrew::Runner do
5
- describe '::default_config(platform)' do
6
+ describe '::default_config' do
6
7
  subject do
7
- Runner.default_config(self.platform)
8
+ Runner.default_config
8
9
  end
9
10
 
10
- let(:platform){'x86_64-darwin13.0'}
11
-
12
11
  before do
13
12
  ENV['FIREBREW_FIREFOX_PROFILE_BASE_DIR'] = nil
14
13
  ENV['FIREBREW_FIREFOX_PROFILE'] = nil
@@ -21,8 +20,7 @@ module Firebrew
21
20
  ENV['FIREBREW_FIREFOX'] = nil
22
21
  end
23
22
 
24
- context 'when the `platform` was "MacOS"' do
25
- let(:platform){'x86_64-darwin13.0'}
23
+ if OS.mac? then
26
24
  it do
27
25
  is_expected.to eq(
28
26
  base_dir: '~/Library/Application Support/Firefox',
@@ -31,10 +29,8 @@ module Firebrew
31
29
  os: 'darwin'
32
30
  )
33
31
  end
34
- end
35
-
36
- context 'when the `platform` was "Linux"' do
37
- let(:platform){'x86_64-linux'}
32
+
33
+ elsif OS.linux? then
38
34
  it do
39
35
  is_expected.to eq(
40
36
  base_dir: '~/.mozilla/firefox',
@@ -43,11 +39,8 @@ module Firebrew
43
39
  os: 'linux'
44
40
  )
45
41
  end
46
- end
47
-
48
- context 'when the `platform` was "Windows"' do
49
- let(:platform){'x64-mingw32'}
50
42
 
43
+ elsif OS.windows? then
51
44
  before do
52
45
  ENV['APPDATA'] = nil
53
46
  ENV['PROGRAMFILES'] = nil
@@ -123,13 +116,10 @@ module Firebrew
123
116
  ENV['FIREBREW_FIREFOX'] = 'path/to/firefox'
124
117
  end
125
118
 
126
- it do
127
- is_expected.to eq(
128
- base_dir: 'path/to/profile_base_directory',
129
- firefox: 'path/to/firefox',
130
- profile: 'profile-name',
131
- os: 'darwin'
132
- )
119
+ it 'should set the default_config' do
120
+ expect(subject[:base_dir]).to eq('path/to/profile_base_directory')
121
+ expect(subject[:firefox]).to eq('path/to/firefox')
122
+ expect(subject[:profile]).to eq('profile-name')
133
123
  end
134
124
  end
135
125
  end
@@ -141,7 +131,7 @@ module Firebrew
141
131
  Runner.new(
142
132
  base_dir: './tmp',
143
133
  data_file: 'profiles.ini',
144
- firefox: ENV['OS'].nil? ? './spec/double/firefox.rb' : './spec/double/firefox.bat'
134
+ firefox: OS.windows? ? './spec/double/firefox.bat' : './spec/double/firefox.rb'
145
135
  )
146
136
  end
147
137
 
@@ -0,0 +1 @@
1
+ dea866691da858b819c5850107b40e54 unpack_false.xpi
@@ -0,0 +1 @@
1
+ d4546ed68e68f494cba0b0c4fa67ea8b unpack_null.xpi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebrew
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
  - Yuichi Murata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-30 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.19'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.19'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: inifile
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,34 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: os
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: ruby-progressbar
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.6'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.6'
97
139
  description: Firefox add-ons manager for CUI.
98
140
  email:
99
141
  - mrk21info+rubygems@gmail.com
@@ -115,6 +157,7 @@ files:
115
157
  - lib/firebrew.rb
116
158
  - lib/firebrew/amo_api/search.rb
117
159
  - lib/firebrew/command_line.rb
160
+ - lib/firebrew/downloader.rb
118
161
  - lib/firebrew/entity.rb
119
162
  - lib/firebrew/firefox/basic_extension.rb
120
163
  - lib/firebrew/firefox/command.rb
@@ -126,6 +169,7 @@ files:
126
169
  - spec/double/firefox.rb
127
170
  - spec/firebrew/amo_api/search_spec.rb
128
171
  - spec/firebrew/command_line_spec.rb
172
+ - spec/firebrew/downloader_spec.rb
129
173
  - spec/firebrew/entity_spec.rb
130
174
  - spec/firebrew/firefox/command_spec.rb
131
175
  - spec/firebrew/firefox/extension_spec.rb
@@ -137,7 +181,9 @@ files:
137
181
  - spec/fixtures/amo_api/search/single.xml
138
182
  - spec/fixtures/firefox/extension/extensions.v16.json
139
183
  - spec/fixtures/firefox/extension/extensions_added_hoge.v16.json
184
+ - spec/fixtures/firefox/extension/unpack_false.md5
140
185
  - spec/fixtures/firefox/extension/unpack_false.xpi
186
+ - spec/fixtures/firefox/extension/unpack_null.md5
141
187
  - spec/fixtures/firefox/extension/unpack_null.xpi
142
188
  - spec/fixtures/firefox/extension/unpack_true.md5
143
189
  - spec/fixtures/firefox/extension/unpack_true.xpi
@@ -173,6 +219,7 @@ test_files:
173
219
  - spec/double/firefox.rb
174
220
  - spec/firebrew/amo_api/search_spec.rb
175
221
  - spec/firebrew/command_line_spec.rb
222
+ - spec/firebrew/downloader_spec.rb
176
223
  - spec/firebrew/entity_spec.rb
177
224
  - spec/firebrew/firefox/command_spec.rb
178
225
  - spec/firebrew/firefox/extension_spec.rb
@@ -184,7 +231,9 @@ test_files:
184
231
  - spec/fixtures/amo_api/search/single.xml
185
232
  - spec/fixtures/firefox/extension/extensions.v16.json
186
233
  - spec/fixtures/firefox/extension/extensions_added_hoge.v16.json
234
+ - spec/fixtures/firefox/extension/unpack_false.md5
187
235
  - spec/fixtures/firefox/extension/unpack_false.xpi
236
+ - spec/fixtures/firefox/extension/unpack_null.md5
188
237
  - spec/fixtures/firefox/extension/unpack_null.xpi
189
238
  - spec/fixtures/firefox/extension/unpack_true.md5
190
239
  - spec/fixtures/firefox/extension/unpack_true.xpi