eff 0.0.1 → 0.0.2

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: 64373ef4d04e08aa57e86223ecdfcdc894c42284
4
- data.tar.gz: caf6cb5718cd8f233544c6677f49986bca2a4918
3
+ metadata.gz: f0425334fa0adbd66e98d2b270d4eed0e0dd7000
4
+ data.tar.gz: 234c51413119612b6776ea5d0f789cb1930a94fc
5
5
  SHA512:
6
- metadata.gz: 1b64d1437efd27bbc7658343800eaf61861578639eb048e154131cdff4abfd583d5e83eae59d99057fcd91250e016aede19cd6128ebef267ed5721c8d1f2b06c
7
- data.tar.gz: 7d050694d14e74b32595793f48b9926ce1e0e99d3bb8651d78291083e551d4c946ecac25e67f8e7ce0a178ccbfdc046c223aacd4e38f8e5cf9859dacb30dbee2
6
+ metadata.gz: c3505f441176e2e01e3a7d636aecf5630fe576cb586173df3cd0dfcf4b1fc3f3a43e39a6336e1bf7307d9a2a45b5df3dc0dc15c858688a33f62ec84e8b49e739
7
+ data.tar.gz: d97639c74a95774d24f504f44c75a1cee841aa3f7b70c064ed812d9e650db1b07991d4bddbc13589bc03c88069e7ab344c5dd7bea822f04abe9cf21ba683c7f6
@@ -1,10 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
- - jruby-19mode
6
4
  - jruby-head
7
- - rbx-19mode
8
5
  script: bundle exec rspec spec
9
6
  branches:
10
7
  only:
@@ -12,6 +9,4 @@ branches:
12
9
  matrix:
13
10
  fast_finish: true
14
11
  allow_failures:
15
- - rvm: jruby-19mode
16
12
  - rvm: jruby-head
17
- - rvm: rbx-19mode
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Eff
2
2
 
3
- TODO: Write a gem description
3
+ [![Gem Version](https://badge.fury.io/rb/eff.png)](http://badge.fury.io/rb/eff) [![Build Status](https://travis-ci.org/Toady00/eff.png)](https://travis-ci.org/Toady00/eff) [![Code Climate](https://codeclimate.com/github/Toady00/eff.png)](https://codeclimate.com/github/Toady00/eff) [![Coverage Status](https://coveralls.io/repos/Toady00/eff/badge.png)](https://coveralls.io/r/Toady00/eff) [![Dependency Status](https://gemnasium.com/Toady00/eff.png)](https://gemnasium.com/Toady00/eff)
4
+
5
+ This gems aims to be a way to help simplify the task of building multiple packages with [FPM](https://github.com/jordansissel/fpm).
4
6
 
5
7
  ## Installation
6
8
 
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "pry"
31
31
  spec.add_development_dependency "pry-plus"
32
32
  spec.add_development_dependency "simplecov"
33
+ spec.add_development_dependency "coveralls"
33
34
  spec.add_development_dependency "fakefs"
34
35
  end
@@ -11,18 +11,11 @@ module Eff
11
11
 
12
12
  def get
13
13
  @response = Faraday.get(uri)
14
+ save
14
15
  end
15
16
 
16
- def save
17
- File.open(file, 'wb') do |f|
18
- f.write(response_body)
19
- end if success?
20
- end
21
-
22
- # TODO: should this really trigger it to download?
23
17
  def success?
24
- get unless response
25
- @response.success?
18
+ response ? response.success? : false
26
19
  end
27
20
 
28
21
  def file=(value)
@@ -36,6 +29,13 @@ module Eff
36
29
  end
37
30
 
38
31
  private
32
+ def save
33
+ File.open(file, 'wb') do |f|
34
+ f.write(response_body)
35
+ end if success?
36
+ success?
37
+ end
38
+
39
39
  def response_body
40
40
  response.body
41
41
  end
@@ -1,45 +1,65 @@
1
1
  require 'eff/downloader'
2
2
  require 'eff/template'
3
3
  require 'eff/package/semantic_version'
4
+ require 'eff/verifier'
4
5
 
5
6
  module Eff
6
7
  class Package
7
- attr_accessor :save_file, :version
8
+ attr_accessor :name, :save_file, :version, :checksum, :hash_function
8
9
 
9
10
  def initialize(options = {})
11
+ @name = options[:name]
10
12
  @url_template = options[:url_template]
11
- self.save_file = options[:save_file]
13
+ @file_template = options[:file_template]
12
14
  self.version = options[:version]
13
- new_downloader
15
+ @checksum = options[:checksum]
16
+ @hash_function = options[:hash_function]
17
+
18
+ after_init_hook
14
19
  end
15
20
 
16
21
  def download
17
22
  downloader.get
18
23
  end
19
24
 
20
- def save
21
- downloader.save
22
- end
23
-
24
- # TODO: should this really trigger it to download?
25
25
  def downloaded?
26
- downloader.success?
26
+ downloader_success?
27
27
  end
28
28
 
29
29
  def url
30
- template = Eff::Template.new(@url_template, version)
31
- template.result
30
+ template_for(:url).result
32
31
  end
33
32
 
34
- def save_file=(value)
35
- @save_file = File.expand_path(value, Dir.pwd)
33
+ def file_name
34
+ template_for(:file).result
35
+ end
36
+
37
+ def save_file
38
+ File.expand_path(file_name, Dir.pwd)
36
39
  end
37
40
 
38
41
  def version=(value)
39
42
  @version = SemanticVersion.new(value)
43
+ clear_download!
44
+ end
45
+
46
+ def ==(other)
47
+ (name == other.name) && (version == other.version)
48
+ end
49
+
50
+ def verified?
51
+ verifiable? ? Verifier.check(save_file, checksum, hash_function) : false
52
+ end
53
+
54
+ def verifiable?
55
+ checksum && hash_function
40
56
  end
41
57
 
42
58
  private
59
+ def after_init_hook
60
+ new_downloader
61
+ end
62
+
43
63
  def downloader
44
64
  @downloader
45
65
  end
@@ -48,8 +68,17 @@ module Eff
48
68
  @downloader = Eff::Downloader.new(url, save_file)
49
69
  end
50
70
 
51
- def download_response
52
- downloader.response
71
+ def downloader_success?
72
+ downloader.success?
73
+ end
74
+
75
+ def clear_download!
76
+ new_downloader if downloader
77
+ end
78
+
79
+ def template_for(sym)
80
+ template = instance_variable_get("@#{sym}_template".to_sym)
81
+ Eff::Template.new(template, version)
53
82
  end
54
83
  end
55
84
  end
@@ -1,7 +1,10 @@
1
1
  module Eff
2
2
  class Package
3
3
  class SemanticVersion
4
- PARTS = %i(major minor patch release identity)
4
+ include Comparable
5
+
6
+ BASE_PARTS = %i(major minor patch)
7
+ PARTS = BASE_PARTS + %i(release identity)
5
8
 
6
9
  PARTS.each do |part|
7
10
  attr_accessor part
@@ -18,6 +21,15 @@ module Eff
18
21
  ]
19
22
  end
20
23
 
24
+ def <=>(other)
25
+ result = 0
26
+ BASE_PARTS.each do |part|
27
+ result = self.public_send(part).to_i <=> other.public_send(part).to_i
28
+ break unless result == 0
29
+ end
30
+ result
31
+ end
32
+
21
33
  private
22
34
  def parse!
23
35
  remaining, @identity = @version_string.split("+")
@@ -1,10 +1,18 @@
1
1
  module Eff
2
2
  class Verifier
3
3
  class << self
4
- def check(file, checksum, algo = Digest::SHA1)
5
- file_digest = algo.file(File.expand_path(file)).hexdigest
4
+ def check(file, checksum, hash_function)
5
+ return unless File.exists?(file)
6
+ function = function_const_get(hash_function)
7
+ file_digest = function.file(file).hexdigest
6
8
  file_digest == checksum
7
9
  end
10
+
11
+ private
12
+ def function_const_get(value)
13
+ hash_function = value.to_s.upcase
14
+ Digest.const_get(hash_function)
15
+ end
8
16
  end
9
17
  end
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module Eff
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'eff/downloader'
3
+ require 'ostruct'
4
+ require 'fakefs/spec_helpers'
5
+
6
+ describe Eff::Downloader do
7
+ include FakeFS::SpecHelpers
8
+
9
+ let(:url) { "http://google.com" }
10
+ let(:file) { "test.tmp" }
11
+ let(:full_path) { File.expand_path(file, Dir.pwd) }
12
+ let(:fake_success) { OpenStruct.new(body: "I'm a fake response!", success?: true) }
13
+ let(:fake_failure) { OpenStruct.new(body: "I'm a fake response!", success?: false) }
14
+ let(:downloader) { Eff::Downloader.new(url, file) }
15
+
16
+ before do
17
+ Faraday.stub(:get).and_return(fake_success)
18
+ end
19
+
20
+ context 'for successfull request' do
21
+ before do
22
+ downloader.get
23
+ end
24
+
25
+ describe '#get' do
26
+ it 'saves the file' do
27
+ File.exists?(File.expand_path(file, Dir.pwd)).should be_true
28
+ end
29
+ end
30
+
31
+ describe '#success?' do
32
+ it 'returns true' do
33
+ downloader.should be_success
34
+ end
35
+ end
36
+ end
37
+
38
+ context 'for unsuccessfull request' do
39
+ before do
40
+ Faraday.stub(:get).and_return(fake_failure)
41
+ downloader.get
42
+ end
43
+
44
+ describe '#get' do
45
+ it 'does not save a file' do
46
+ File.exists?(File.expand_path(file, Dir.pwd)).should_not be_true
47
+ end
48
+ end
49
+
50
+ describe '#success?' do
51
+ it 'returns false' do
52
+ downloader.should_not be_success
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#uri=' do
58
+ let(:another_url) { "http://example.com" }
59
+ let(:another_uri) { URI(another_url) }
60
+
61
+ it 'resets response to nil' do
62
+ downloader.get
63
+ downloader.response.should_not be_nil
64
+ downloader.uri = another_url
65
+ downloader.response.should be_nil
66
+ end
67
+
68
+ it 'sets the new uri' do
69
+ downloader.uri = another_url
70
+ downloader.uri.should eq(another_uri)
71
+ end
72
+ end
73
+
74
+ describe '#file=' do
75
+ let(:another_file) { '~/some_other_file' }
76
+
77
+ it 'resets response to nil' do
78
+ downloader.get
79
+ downloader.response.should_not be_nil
80
+ downloader.file = another_file
81
+ downloader.response.should be_nil
82
+ end
83
+
84
+ it 'sets the new file' do
85
+ downloader.file = another_file
86
+ downloader.file.should eq(File.expand_path(another_file, Dir.pwd))
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'eff/package/semantic_version'
3
+
4
+ describe Eff::Package::SemanticVersion do
5
+ describe '#to_h' do
6
+ let(:version_hash) {
7
+ Hash[
8
+ :major, "1",
9
+ :minor, "2",
10
+ :patch, "3",
11
+ :release, "p456",
12
+ :identity, "7890"
13
+ ]
14
+ }
15
+ let(:valid_versions) { %w(1 1.2 1.2.3 1.2.3-p456 1.2.3-p456+7890) }
16
+
17
+ it 'should return the correct hash' do
18
+ valid_versions.each do |version_string|
19
+ semver = Eff::Package::SemanticVersion.new version_string
20
+ hash = semver.to_h
21
+ first_nil = false
22
+ version_hash.each do |part, value|
23
+ hash_value = hash[part]
24
+ first_nil ||= hash_value.nil?
25
+ if first_nil
26
+ hash[part].should be_nil
27
+ else
28
+ hash[part].should eq(value)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#<=>' do
36
+ before do
37
+ @versions = []
38
+ %w(0.0.1 0.0.5 0.1.0 1.0.0 1.0.1 1.2.0 2.0.0).each do |version|
39
+ @versions << Eff::Package::SemanticVersion.new(version)
40
+ end
41
+ end
42
+
43
+ it 'compares versions correctly' do
44
+ @versions.each_with_index do |version, index|
45
+ @versions.each_with_index do |other, other_index|
46
+ if index > other_index
47
+ (version > other).should be_true
48
+ (version < other).should be_false
49
+ (version == other).should be_false
50
+ (version != other).should be_true
51
+ elsif index < other_index
52
+ (version > other).should be_false
53
+ (version < other).should be_true
54
+ (version == other).should be_false
55
+ (version != other).should be_true
56
+ else
57
+ (version > other).should be_false
58
+ (version < other).should be_false
59
+ (version == other).should be_true
60
+ (version != other).should be_false
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ require 'eff/package'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe Eff::Package do
6
+ include FakeFS::SpecHelpers
7
+
8
+ let(:url_template) { '<%= "http://example.com/package-#{@major}.#{@minor}.#{@patch}.deb" %>' }
9
+ let(:file_template) { '<%= "package-#{@major}.#{@minor}.#{@patch}.deb" %>' }
10
+ let(:version) { '1.2.3'}
11
+ let(:options) { { url_template: url_template, file_template: file_template, version: version } }
12
+ let(:package) { Eff::Package.new options }
13
+
14
+ let(:fake_success) { OpenStruct.new(body: "I'm a fake response!", success?: true) }
15
+ let(:fake_failure) { OpenStruct.new(body: "I'm a fake response!", success?: false) }
16
+
17
+ subject { package }
18
+
19
+ before { Faraday.stub(:get).and_return(fake_success) }
20
+
21
+ it { should respond_to :name }
22
+ it { should respond_to :download }
23
+ it { should respond_to :downloaded? }
24
+ it { should respond_to :url }
25
+ it { should respond_to :file_name }
26
+ it { should respond_to :save_file }
27
+ it { should respond_to :version }
28
+ it { should respond_to :checksum }
29
+ it { should respond_to :hash_function }
30
+ it { should respond_to :verified? }
31
+ it { should respond_to :verifiable? }
32
+
33
+ describe 'downloader wrapper method' do
34
+ describe '#download' do
35
+ it 'calls Eff::Downloader#get' do
36
+ Eff::Downloader.any_instance.should_receive(:get)
37
+ package.download
38
+ end
39
+ end
40
+
41
+ describe '#downloaded?' do
42
+ it 'calls Eff::Downloader#success?' do
43
+ Eff::Downloader.stub(:previously_downloaded?)
44
+ Eff::Downloader.any_instance.should_receive(:success?)
45
+ package.downloaded?
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#url' do
51
+ let(:url) { 'http://example.com/package-1.2.3.deb' }
52
+
53
+ it 'returns the correct url' do
54
+ package.url.should eq(url)
55
+ end
56
+ end
57
+
58
+ describe '#version=' do
59
+ before do
60
+ package.download
61
+ package.should be_downloaded
62
+ end
63
+
64
+ let(:new_version) { '4.5.6' }
65
+ let(:package_name) { "package-#{new_version}.deb"}
66
+ let(:url) { "http://example.com/#{package_name}" }
67
+ let(:full_save_path) { File.expand_path(package_name, Dir.pwd) }
68
+
69
+ it 'forgets about previous downloads' do
70
+ package.version = new_version
71
+ package.should_not be_downloaded
72
+ end
73
+
74
+ it 'updates the url' do
75
+ old_url = package.url
76
+ package.version = new_version
77
+ package.url.should_not eq old_url
78
+ end
79
+
80
+ it 'creates a new downloader with the correct url' do
81
+ Eff::Downloader.should_receive(:new).with(url, full_save_path)
82
+ package.version = new_version
83
+ end
84
+ end
85
+
86
+ describe 'verification' do
87
+ let(:package) { Eff::Package.new @options }
88
+
89
+ describe '#verifiable?' do
90
+ it 'returns false without checksum or hash_function' do
91
+ @options = options
92
+ package.should_not be_verifiable
93
+ end
94
+
95
+ it 'returns false without checksum' do
96
+ @options = options.merge(hash_function: 'sha1')
97
+ package.should_not be_verifiable
98
+ end
99
+
100
+ it 'returns false without hash_function' do
101
+ @options = options.merge(checksum: 'some_string')
102
+ package.should_not be_verifiable
103
+ end
104
+
105
+ it 'returns tru with checksum and hash_function' do
106
+ @options = options.merge(checksum: 'some_string', hash_function: 'sha1')
107
+ package.should be_verifiable
108
+ end
109
+ end
110
+
111
+ describe '#verified?' do
112
+ it 'returns false if not verifiable' do
113
+ @options = options
114
+ package.should_not be_verified
115
+ end
116
+
117
+ it 'calls Verifier.check if verifiable' do
118
+ @options = options.merge(checksum: 'some_string', hash_function: 'sha1')
119
+ Eff::Verifier.should_receive(:check).with(package.save_file, package.checksum, package.hash_function)
120
+ package.verified?
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'eff/verifier'
3
+
4
+ describe Eff::Verifier do
5
+ let(:file) { "spec/support/static_file_for_digesting.txt" }
6
+ let(:sha1) { "75cfdde12aeb435fd0c68c99df1027190953997e" }
7
+ let(:md5) { "1c0b1fcddc0cd9677ecfb79e1d127e03" }
8
+ let(:hashes) { { sha1: sha1, md5: md5 } }
9
+
10
+ describe '.check' do
11
+ it 'returns true if the hashes match' do
12
+ hashes.each do |hash_function, value|
13
+ Eff::Verifier.check(file, value, hash_function).should be_true
14
+ end
15
+ end
16
+
17
+ it 'returns false if the hashes do not match' do
18
+ hashes.each do |hash_function, value|
19
+ Eff::Verifier.check(file, "this doesn't match", hash_function).should be_false
20
+ end
21
+ end
22
+
23
+ it 'returns false if the file does not exist' do
24
+ Eff::Verifier.check('non-existant-file.txt', sha1, :sha1).should be_false
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fpm
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: coveralls
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: fakefs
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -204,14 +218,14 @@ files:
204
218
  - lib/eff/template.rb
205
219
  - lib/eff/verifier.rb
206
220
  - lib/eff/version.rb
207
- - spec/downloader_spec.rb
221
+ - spec/eff/downloader_spec.rb
222
+ - spec/eff/package/semantic_version_spec.rb
223
+ - spec/eff/package_spec.rb
224
+ - spec/eff/template_spec.rb
225
+ - spec/eff/verifier_spec.rb
208
226
  - spec/eff_spec.rb
209
- - spec/package_semantic_version_spec.rb
210
- - spec/package_spec.rb
211
227
  - spec/spec_helper.rb
212
228
  - spec/support/static_file_for_digesting.txt
213
- - spec/template_spec.rb
214
- - spec/verifier_spec.rb
215
229
  homepage: ''
216
230
  licenses:
217
231
  - MIT
@@ -237,12 +251,12 @@ signing_key:
237
251
  specification_version: 4
238
252
  summary: Wrapper around fpm (effing package manager)
239
253
  test_files:
240
- - spec/downloader_spec.rb
254
+ - spec/eff/downloader_spec.rb
255
+ - spec/eff/package/semantic_version_spec.rb
256
+ - spec/eff/package_spec.rb
257
+ - spec/eff/template_spec.rb
258
+ - spec/eff/verifier_spec.rb
241
259
  - spec/eff_spec.rb
242
- - spec/package_semantic_version_spec.rb
243
- - spec/package_spec.rb
244
260
  - spec/spec_helper.rb
245
261
  - spec/support/static_file_for_digesting.txt
246
- - spec/template_spec.rb
247
- - spec/verifier_spec.rb
248
262
  has_rdoc:
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
- require 'eff/downloader'
3
- require 'ostruct'
4
- require 'fakefs/spec_helpers'
5
-
6
- describe Eff::Downloader do
7
- include FakeFS::SpecHelpers
8
-
9
- let(:url) { "http://google.com" }
10
- let(:file) { "test.tmp" }
11
- let(:full_path) { File.expand_path(file, Dir.pwd) }
12
- let(:fake_success) { OpenStruct.new(body: "I'm a fake response!", success?: true) }
13
- let(:fake_failure) { OpenStruct.new(body: "I'm a fake response!", success?: false) }
14
-
15
- # describe '.get' do
16
- # it 'returns the body if response is successful' do
17
- # Faraday.stub(:get).and_return(fake_success)
18
- # Eff::Downloader.get(url, file).should eq(fake_success.body)
19
- # end
20
-
21
- # it 'returns nil if the response is not successful' do
22
- # Faraday.stub(:get).and_return(fake_failure)
23
- # Eff::Downloader.get(url, file).should be_nil
24
- # end
25
- # end
26
-
27
- # describe '.get!' do
28
- # it 'writes the appropriate file' do
29
- # Faraday.stub(:get).and_return(fake_success)
30
- # Eff::Downloader.get!(url, file)
31
- # File.exists?(File.expand_path(file, Dir.pwd)).should be_true
32
- # end
33
-
34
- # it 'downloads the appropriate file' do
35
- # Faraday.should_receive(:get).with(URI(url)).and_return(fake_success)
36
- # Eff::Downloader.get!(url, file)
37
- # end
38
-
39
- # it 'returns the location of the saved file' do
40
- # Faraday.stub(:get).and_return(fake_success)
41
- # Eff::Downloader.get!(url, file).should be_true
42
- # end
43
- # end
44
-
45
- describe 'instance' do
46
- before { Faraday.stub(:get).and_return(fake_success) }
47
-
48
- let(:downloader) { Eff::Downloader.new(url, file) }
49
-
50
- describe '#get' do
51
- it 'returns a response' do
52
- downloader.get.should respond_to :success?
53
- end
54
- end
55
-
56
- describe '#uri=' do
57
- let(:another_url) { "http://example.com" }
58
- let(:another_uri) { URI(another_url) }
59
- it 'resets response to nil' do
60
- downloader.get
61
- downloader.response.should_not be_nil
62
- downloader.uri = another_url
63
- downloader.response.should be_nil
64
- end
65
-
66
- it 'sets the new uri' do
67
- downloader.uri = another_url
68
- downloader.uri.should eq(another_uri)
69
- end
70
- end
71
-
72
- describe '#file' do
73
- let(:another_file) { '~/some_other_file' }
74
-
75
- it 'resets response to nil' do
76
- downloader.get
77
- downloader.response.should_not be_nil
78
- downloader.file = another_file
79
- downloader.response.should be_nil
80
- end
81
-
82
- it 'sets the new file' do
83
- downloader.file = another_file
84
- downloader.file.should eq(File.expand_path(another_file, Dir.pwd))
85
- end
86
- end
87
-
88
- context 'successfully downloaded' do
89
- describe '#save' do
90
- it 'gets the response if it has not already' do
91
- Faraday.should_receive(:get).with(URI(url)).and_return(fake_success)
92
- downloader.save
93
- end
94
-
95
- it 'writes the file to disk' do
96
- downloader.save
97
- File.exists?(File.expand_path(file, Dir.pwd)).should be_true
98
- end
99
- end
100
-
101
- describe '#success?' do
102
- it 'returns true' do
103
- downloader.should be_success
104
- end
105
- end
106
- end
107
-
108
- context 'unsuccessfully downloaded' do
109
- before { Faraday.stub(:get).and_return(fake_failure) }
110
-
111
- describe '#save' do
112
- it 'gets the response if it has not already' do
113
- Faraday.should_receive(:get).with(URI(url)).and_return(fake_success)
114
- downloader.save
115
- end
116
-
117
- it 'does not write the file to disk' do
118
- downloader.save
119
- File.exists?(File.expand_path(file, Dir.pwd)).should_not be_true
120
- end
121
- end
122
-
123
- describe '#success?' do
124
- it 'returns false' do
125
- downloader.should_not be_success
126
- end
127
- end
128
- end
129
- end
130
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
- require 'eff/package/semantic_version'
3
-
4
- describe Eff::Package::SemanticVersion do
5
- describe '#to_h' do
6
- let(:version_hash) {
7
- Hash[
8
- :major, "1",
9
- :minor, "2",
10
- :patch, "3",
11
- :release, "p456",
12
- :identity, "7890"
13
- ]
14
- }
15
- let(:valid_versions) { %w(1 1.2 1.2.3 1.2.3-p456 1.2.3-p456+7890) }
16
-
17
- it 'should return the correct hash' do
18
- valid_versions.each do |version_string|
19
- semver = Eff::Package::SemanticVersion.new version_string
20
- hash = semver.to_h
21
- first_nil = false
22
- version_hash.each do |part, value|
23
- hash_value = hash[part]
24
- first_nil ||= hash_value.nil?
25
- if first_nil
26
- hash[part].should be_nil
27
- else
28
- hash[part].should eq(value)
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'eff/package'
3
- require 'fakefs/spec_helpers'
4
-
5
- describe Eff::Package do
6
- include FakeFS::SpecHelpers
7
-
8
- let(:url_template) { '<%= "http://example.com/package-#{@major}.#{@minor}.#{@patch}.deb" %>' }
9
- let(:url) { 'http://example.com/package-1.2.3.deb' }
10
- let(:save_file) { '~/example.txt' }
11
- let(:full_save_path) { File.expand_path(save_file, Dir.pwd) }
12
- let(:version) { '1.2.3'}
13
- let(:options) { { url_template: url_template, save_file: save_file, version: version } }
14
- let(:package) { Eff::Package.new options }
15
-
16
- let(:fake_success) { OpenStruct.new(body: "I'm a fake response!", success?: true) }
17
- let(:fake_failure) { OpenStruct.new(body: "I'm a fake response!", success?: false) }
18
-
19
- subject { package }
20
-
21
- before { Faraday.stub(:get).and_return(fake_success) }
22
-
23
- it { should respond_to :download }
24
- it { should respond_to :save }
25
- it { should respond_to :downloaded? }
26
- it { should respond_to :url }
27
- it { should respond_to :save_file }
28
- it { should respond_to :version }
29
-
30
- describe 'downloader wrapper method' do
31
- describe '#download' do
32
- it 'calls #get' do
33
- Eff::Downloader.any_instance.should_receive(:get)
34
- package.download
35
- end
36
- end
37
-
38
- describe '#save' do
39
- it 'calls #save' do
40
- Eff::Downloader.any_instance.should_receive(:save)
41
- package.save
42
- end
43
- end
44
-
45
- describe '#downloaded?' do
46
- it 'calls success?' do
47
- Eff::Downloader.any_instance.should_receive(:success?)
48
- package.downloaded?
49
- end
50
- end
51
- end
52
-
53
- describe '#url' do
54
- it 'returns the correct url' do
55
- package.url.should eq(url)
56
- end
57
- end
58
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'eff/verifier'
3
-
4
- describe Eff::Verifier do
5
- let(:file) { "spec/support/static_file_for_digesting.txt" }
6
- let(:sha1) { "75cfdde12aeb435fd0c68c99df1027190953997e" }
7
- let(:md5) { "1c0b1fcddc0cd9677ecfb79e1d127e03" }
8
-
9
- it 'returns true if the hashes match' do
10
- Eff::Verifier.check(file, sha1).should be_true
11
- end
12
-
13
- it 'returns false if the hashes do not match' do
14
- Eff::Verifier.check(file, "this doesn't match").should_not be_true
15
- end
16
-
17
- it 'can validate with md5' do
18
- Eff::Verifier.check(file, md5, Digest::MD5).should be_true
19
- end
20
- end