spec/firebrew/firefox/extension_spec.rb in firebrew-0.2.0 vs spec/firebrew/firefox/extension_spec.rb in firebrew-0.3.0

- old
+ new

@@ -5,27 +5,27 @@ module Firebrew::Firefox describe Firebrew::Firefox::Extension do let(:manager) do Extension::Manager.new( profile: Profile.new( - path: File.join(Dir.pwd, 'tmp') + path: './tmp' ) ) end let(:extensions){[ Extension.new({ name: 'Japanese Language Pack', guid: 'langpack-ja@firefox.mozilla.org', version: '30.0', - uri: File.join(Dir.pwd, 'tmp/extensions/langpack-ja@firefox.mozilla.org.xpi') + uri: './tmp/extensions/langpack-ja@firefox.mozilla.org.xpi' }, self.manager), Extension.new({ name: 'Vimperator', guid: 'vimperator@mozdev.org', version: '3.8.2', - uri: File.join(Dir.pwd, 'tmp/extensions/vimperator@mozdev.org.xpi') + uri: './tmp/extensions/vimperator@mozdev.org.xpi' }, self.manager) ]} before do json = File.read('./spec/fixtures/firefox/extension/extensions.v16.json') @@ -86,89 +86,95 @@ let(:name){'hoge'} it { expect{subject}.to raise_error(Firebrew::ExtensionNotFoundError, 'Extension not found: hoge') } end end - describe '#install(extension)' do + describe '#install(extension[, is_displaying_progress])' do subject { self.instance.install(self.extension) } let(:extension) do - Extension.new({ - guid: 'hoge@example.org', - uri: File.join(Dir.pwd, 'spec/fixtures/firefox/extension/unpack_false.xpi') - }, self.manager) + Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager) end + let(:extension_uri) do + './spec/fixtures/firefox/extension/unpack_false.xpi' + end + let(:expected_path) do File.join(self.instance.profile.path, 'extensions/%s.xpi' % self.extension.guid) end it 'should copy the `path/to/profile/extensions/<GUID>.xpi`' do subject - expect(File.exists? self.expected_path).to be_truthy + md5, path = File.read(self.extension_uri.pathmap('%X.md5')).split(/\s+/) + expect(Digest::MD5.hexdigest(File.open(self.expected_path,'rb').read)).to eq(md5) end it 'should add the `extension` extension' do subject all = self.instance.all extension = self.extension - extension.uri = File.join(Dir.pwd, 'tmp/extensions/hoge@example.org.xpi') + extension.uri = './tmp/extensions/hoge@example.org.xpi' expect(all.size).to eq(3) expect(all[0]).to eq(self.extensions[0]) expect(all[1]).to eq(self.extensions[1]) expect(all[2]).to eq(self.extension) end context 'when an `uri` of the `extension` was equal or greater than two' do let(:extension) do - Extension.new({ - guid: 'hoge@example.org', - uri: [ - File.join(Dir.pwd, 'spec/fixtures/firefox/extension/unpack_false.xpi'), - File.join(Dir.pwd, 'spec/fixtures/firefox/extension/not_exists.xpi'), - ] - }, self.manager) + Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager) end + let(:extension_uri) do + [ + './spec/fixtures/firefox/extension/unpack_false.xpi', + './spec/fixtures/firefox/extension/not_exists.xpi' + ] + end + it 'should not throw exceptions' do expect{subject}.to_not raise_error end end context 'when an `em:unpack` value of the `install.rdf` in the XPI package not exsisted' do let(:extension) do - Extension.new({ - guid: 'hoge@example.org', - uri: File.join(Dir.pwd, 'spec/fixtures/firefox/extension/unpack_null.xpi') - }, self.manager) + Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager) end + let(:extension_uri) do + './spec/fixtures/firefox/extension/unpack_null.xpi' + end + it 'should copy the `path/to/profile/extensions/<GUID>.xpi`' do subject - expect(File.exists? self.expected_path).to be_truthy + md5, path = File.read(self.extension_uri.pathmap('%X.md5')).split(/\s+/) + expect(Digest::MD5.hexdigest(File.open(self.expected_path,'rb').read)).to eq(md5) end it 'should add the `extension` extension' do subject all = self.instance.all extension = self.extension - extension.uri = File.join(Dir.pwd, 'tmp/extensions/hoge@example.org.xpi') + extension.uri = './tmp/extensions/hoge@example.org.xpi' expect(all.size).to eq(3) expect(all[0]).to eq(self.extensions[0]) expect(all[1]).to eq(self.extensions[1]) expect(all[2]).to eq(self.extension) end end context 'when an `em:unpack` value of the `install.rdf` in the XPI package was true' do let(:extension) do - Extension.new({ - guid: 'hoge@example.org', - uri: './spec/fixtures/firefox/extension/unpack_true.xpi' - }, self.manager) + Extension.new({guid: 'hoge@example.org', uri: self.extension_uri}, self.manager) end + let(:extension_uri) do + './spec/fixtures/firefox/extension/unpack_true.xpi' + end + let(:expected_path) do File.join(self.instance.profile.path, 'extensions/%s' % self.extension.guid) end it 'should copy the `path/to/profile/extensions/<GUID>`' do @@ -176,11 +182,11 @@ expect(File.exists? self.expected_path).to be_truthy end it 'should unzip all files in the XPI package' do subject - md5list = File.read('./spec/fixtures/firefox/extension/unpack_true.md5') + md5list = File.read(self.extension_uri.pathmap('%X.md5')) Dir.chdir(self.expected_path) do md5list.each_line do |item| md5, path = item.split(/\s+/) expect(Digest::MD5.hexdigest(File.read path)).to eq(md5) end @@ -189,11 +195,11 @@ it 'should add the `extension` extension' do subject all = self.instance.all extension = self.extension - extension.uri = File.join(Dir.pwd, 'tmp/extensions/hoge@example.org') + extension.uri = './tmp/extensions/hoge@example.org' expect(all.size).to eq(3) expect(all[0]).to eq(self.extensions[0]) expect(all[1]).to eq(self.extensions[1]) expect(all[2]).to eq(self.extension) end @@ -202,11 +208,11 @@ describe '#uninstall(extension)' do let(:extension) do Extension.new({ guid: 'hoge@example.org', - uri: File.join(Dir.pwd, 'tmp/extensions/hoge@example.org.xpi') + uri: './tmp/extensions/hoge@example.org.xpi' }, self.manager) end let(:create_xpi_block){->{ File.write self.extension.uri, '' @@ -232,10 +238,10 @@ context 'when `em:unpack` value of the `install.rdf` in the `extension` was true' do let(:extension) do Extension.new({ guid: 'hoge@example.org', - uri: File.join(Dir.pwd, 'tmp/extensions/hoge@example.org') + uri: './tmp/extensions/hoge@example.org' }, self.manager) end let(:create_xpi_block){->{ FileUtils.mkdir_p self.extension.uri