ironment 0.0.4 → 0.0.5

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: 5dac68a95a13d3a4b6bd5b7374ea73fedad5e60d
4
- data.tar.gz: 94c783c5aade35b7a0167b3f7fddcc281eee1faf
3
+ metadata.gz: 0e22103ee32450e82906177426670ee179a4783f
4
+ data.tar.gz: 34771f4603e957fa89df5487e3e77135ae4cfb66
5
5
  SHA512:
6
- metadata.gz: 74ffdf0ddf2ddb209f02ae2a88ed0a641760b43d05eedf5fdbcd8857e6dc64bfe1a827d2f16107b5bd8419e90f0b83dd8404f2a26997e5997c2bceb95081da39
7
- data.tar.gz: 70f6a7f0dcebb804d9d0c83af9971b296a511a86bc996490341996afa3e5f6a1eea83138e4286fbcc09df6362145704a58c6b983a5ab27c2607fc42ea9208481
6
+ metadata.gz: 481b3985f1e6603d067b9333798b970d349b5f1a42f7b0c0e030714086947819d07ededc5ddada9d67fe0d5925bcd922ef2bf8a8509987ccc36dabb2c75872b6
7
+ data.tar.gz: 5d6746488c1fe5066de1fca7b8d35b09d997dd65dffc2a45f47b13537a4cc1a1031f2aacebd5f0d2c3c862c01b2db2b271a32746c7824697e732e7e584391f23
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Ironment
2
2
  ========
3
3
 
4
- [![Build Status](https://travis-ci.org/badeball/ironment.svg)](https://travis-ci.org/badeball/ironment)
4
+ [![Build Status](https://travis-ci.org/badeball/ironment.svg?branch=master)](https://travis-ci.org/badeball/ironment)
5
5
  [![Code Climate](https://codeclimate.com/github/badeball/ironment/badges/gpa.svg)](https://codeclimate.com/github/badeball/ironment)
6
6
  [![Test Coverage](https://codeclimate.com/github/badeball/ironment/badges/coverage.svg)](https://codeclimate.com/github/badeball/ironment/coverage)
7
7
 
@@ -43,6 +43,11 @@ $ yaourt -S ruby-ironment
43
43
 
44
44
  ## Changelog
45
45
 
46
+ ### 0.0.5
47
+
48
+ * `iron exec` now handles EACCES, ENOENT & EISDIR like `iron trust` and `iron untrust` does.
49
+ * `iron exec` now handles malformed runcom files.
50
+
46
51
  ### 0.0.4
47
52
 
48
53
  * Correcting a bug under ruby-1.9.3.
data/lib/ironment/cl.rb CHANGED
@@ -1,14 +1,21 @@
1
1
  class Ironment
2
2
  class CL
3
3
  def initialize(options = {})
4
- @ironment = options[:ironment] || Ironment.new
4
+ @ironment = options[:ironment] || Ironment.new(options)
5
5
  @prompter = options[:prompter] || Prompter.new
6
- @truster = options[:truster] || Truster.new
7
- @stderr = options[:stderr] || $stderr
6
+ @err = options[:err] || $stderr
8
7
  end
9
8
 
10
9
  def exec_with_environment(command, *args)
11
10
  @ironment.exec_with_environment command, *args
11
+ rescue Errno::EACCES
12
+ @err.puts "ironment: Permission denied"
13
+ rescue Errno::ENOENT
14
+ @err.puts "ironment: No such file or directory"
15
+ rescue Errno::EISDIR
16
+ @err.puts "ironment: Is a directory"
17
+ rescue Ironment::MalformedRuncom
18
+ @err.puts "ironment: Malformed runcom"
12
19
  rescue Truster::NotTrusted => e
13
20
  if @prompter.not_trusted e.runcom
14
21
  exec_with_environment command, *args
@@ -20,39 +27,23 @@ class Ironment
20
27
  end
21
28
 
22
29
  def trust(file)
23
- @truster.trust Runcom.new(file)
24
-
25
- true
30
+ @ironment.trust file
26
31
  rescue Errno::EACCES
27
- @stderr.puts "ironment: Permission denied"
28
-
29
- false
32
+ @err.puts "ironment: Permission denied"
30
33
  rescue Errno::ENOENT
31
- @stderr.puts "ironment: No such file or directory"
32
-
33
- false
34
+ @err.puts "ironment: No such file or directory"
34
35
  rescue Errno::EISDIR
35
- @stderr.puts "ironment: Is a directory"
36
-
37
- false
36
+ @err.puts "ironment: Is a directory"
38
37
  end
39
38
 
40
39
  def untrust(file)
41
- @truster.untrust Runcom.new(file)
42
-
43
- true
40
+ @ironment.untrust file
44
41
  rescue Errno::EACCES
45
- @stderr.puts "ironment: Permission denied"
46
-
47
- false
42
+ @err.puts "ironment: Permission denied"
48
43
  rescue Errno::ENOENT
49
- @stderr.puts "ironment: No such file or directory"
50
-
51
- false
44
+ @err.puts "ironment: No such file or directory"
52
45
  rescue Errno::EISDIR
53
- @stderr.puts "ironment: Is a directory"
54
-
55
- false
46
+ @err.puts "ironment: Is a directory"
56
47
  end
57
48
  end
58
49
  end
@@ -34,6 +34,7 @@ class Ironment
34
34
  Hash[*content.split(/\n/).reject { |line|
35
35
  /^\s*#/ =~line
36
36
  }.map { |line|
37
+ raise MalformedRuncom unless line.include? "="
37
38
  line.split(/=/)
38
39
  }.flatten]
39
40
  end
@@ -1,3 +1,3 @@
1
1
  class Ironment
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/ironment.rb CHANGED
@@ -8,6 +8,8 @@ require "ironment/runcom"
8
8
  require "ironment/truster"
9
9
 
10
10
  class Ironment
11
+ class MalformedRuncom < StandardError; end
12
+
11
13
  class << self
12
14
  attr_writer :runcom
13
15
 
@@ -32,6 +34,16 @@ class Ironment
32
34
  @executor.exec command, *args
33
35
  end
34
36
 
37
+ def trust(file)
38
+ @truster.trust Runcom.new file
39
+ end
40
+
41
+ def untrust(file)
42
+ @truster.untrust Runcom.new file
43
+ end
44
+
45
+ private
46
+
35
47
  def load_environment
36
48
  @finder.find.each do |runcom|
37
49
  @truster.validate runcom
data/test/cl_test.rb CHANGED
@@ -1,88 +1,88 @@
1
1
  require "test_helper"
2
2
  require "stringio"
3
3
 
4
- def test_exception_handling(exception, method, message)
5
- truster = Object.new
4
+ def test_exception_handling(exception, message, method, *args)
5
+ ironment = Object.new
6
6
 
7
- truster.define_singleton_method method do |*|
7
+ ironment.define_singleton_method method do |*|
8
8
  raise exception
9
9
  end
10
10
 
11
11
  describe "upon receiving #{exception.inspect}" do
12
- it "should return false" do
13
- result = Ironment::CL.new(truster: truster, stderr: StringIO.new).send(method, ".envrc")
14
-
15
- assert_equal false, result
16
- end
17
-
18
12
  it "should write #{message.inspect} to :stderr" do
19
- stderr = StringIO.new
13
+ err = StringIO.new
20
14
 
21
- Ironment::CL.new(truster: truster, stderr: stderr).send(method, ".envrc")
15
+ Ironment::CL.new(ironment: ironment, err: err).send(method, *args)
22
16
 
23
- assert_includes stderr.string, message
17
+ assert_includes err.string, message
24
18
  end
25
19
 
26
20
  it ":stderr should end with a newline" do
27
- stderr = StringIO.new
21
+ err = StringIO.new
28
22
 
29
- Ironment::CL.new(truster: truster, stderr: stderr).send(method, ".envrc")
23
+ Ironment::CL.new(ironment: ironment, err: err).send(method, *args)
30
24
 
31
- assert_equal "\n", stderr.string[-1]
25
+ assert_equal "\n", err.string[-1]
32
26
  end
33
27
  end
34
28
  end
35
29
 
36
30
  describe Ironment::CL do
37
- describe "#trust" do
38
- describe "when succesfully trusting a file" do
39
- it "should return true" do
40
- truster = Minitest::Mock.new
41
- truster.expect :trust, true, [Ironment::Runcom.new(".envrc")]
31
+ describe "#exec_with_environment" do
32
+ describe "when successfully execing with a command" do
33
+ it "should not write to :stderr" do
34
+ ironment = Minitest::Mock.new
35
+ ironment.expect :exec_with_environment, true, ["foo"]
36
+
37
+ err = StringIO.new
38
+
39
+ Ironment::CL.new(ironment: ironment, err: err).exec_with_environment("foo")
42
40
 
43
- assert_equal true, Ironment::CL.new(truster: truster).trust(".envrc")
41
+ assert_equal "", err.string
44
42
  end
43
+ end
44
+
45
+ test_exception_handling Errno::EACCES, "ironment: Permission denied", :exec_with_environment, "foo"
46
+ test_exception_handling Errno::ENOENT, "ironment: No such file or directory", :exec_with_environment, "foo"
47
+ test_exception_handling Errno::EISDIR, "ironment: Is a directory", :exec_with_environment, "foo"
48
+ test_exception_handling Ironment::MalformedRuncom, "ironment: Malformed runcom", :exec_with_environment, "foo"
49
+ end
45
50
 
51
+ describe "#trust" do
52
+ describe "when succesfully trusting a file" do
46
53
  it "should not write to :stderr" do
47
54
  truster = Minitest::Mock.new
48
55
  truster.expect :trust, true, [Ironment::Runcom.new(".envrc")]
49
56
 
50
- stderr = StringIO.new
57
+ err = StringIO.new
51
58
 
52
- Ironment::CL.new(truster: truster, stderr: stderr).trust(".envrc")
59
+ Ironment::CL.new(truster: truster, err: err).trust(".envrc")
53
60
 
54
- assert_equal "", stderr.string
61
+ assert_equal "", err.string
55
62
  end
56
63
  end
57
64
 
58
- test_exception_handling Errno::EACCES, :trust, "ironment: Permission denied"
59
- test_exception_handling Errno::ENOENT, :trust, "ironment: No such file or directory"
60
- test_exception_handling Errno::EISDIR, :trust, "ironment: Is a directory"
65
+ test_exception_handling Errno::EACCES, "ironment: Permission denied", :trust, ".envrc"
66
+ test_exception_handling Errno::ENOENT, "ironment: No such file or directory", :trust, ".envrc"
67
+ test_exception_handling Errno::EISDIR, "ironment: Is a directory", :trust, ".envrc"
61
68
  end
62
69
 
63
70
  describe "#untrust" do
64
71
  describe "when succesfully untrusting a file" do
65
- it "should return true" do
66
- truster = Minitest::Mock.new
67
- truster.expect :untrust, true, [Ironment::Runcom.new(".envrc")]
68
-
69
- assert_equal true, Ironment::CL.new(truster: truster).untrust(".envrc")
70
- end
71
-
72
72
  it "should not write to :stderr" do
73
73
  truster = Minitest::Mock.new
74
74
  truster.expect :untrust, true, [Ironment::Runcom.new(".envrc")]
75
75
 
76
- stderr = StringIO.new
76
+ err = StringIO.new
77
77
 
78
- Ironment::CL.new(truster: truster, stderr: stderr).untrust(".envrc")
78
+ Ironment::CL.new(truster: truster, err: err).untrust(".envrc")
79
79
 
80
- assert_equal "", stderr.string
80
+ assert_equal "", err.string
81
81
  end
82
82
  end
83
83
 
84
- test_exception_handling Errno::EACCES, :untrust, "ironment: Permission denied"
85
- test_exception_handling Errno::ENOENT, :untrust, "ironment: No such file or directory"
86
- test_exception_handling Errno::EISDIR, :untrust, "ironment: Is a directory"
84
+ test_exception_handling Errno::EACCES, "ironment: Permission denied", :untrust, ".envrc"
85
+ test_exception_handling Errno::ENOENT, "ironment: No such file or directory", :untrust, ".envrc"
86
+ test_exception_handling Errno::EISDIR, "ironment: Is a directory", :untrust, ".envrc"
87
87
  end
88
88
  end
@@ -27,4 +27,26 @@ describe Ironment do
27
27
  [finder, truster, populator, executor].each &:verify
28
28
  end
29
29
  end
30
+
31
+ describe "#trust" do
32
+ it "should invoke Ironment::Truster#trust with a runcom" do
33
+ truster = MiniTest::Mock.new
34
+ truster.expect :trust, nil, [Ironment::Runcom.new("foo")]
35
+
36
+ Ironment.new(truster: truster).trust "foo"
37
+
38
+ truster.verify
39
+ end
40
+ end
41
+
42
+ describe "#untrust" do
43
+ it "should invoke Ironment::Truster#untrust with a runcom" do
44
+ truster = MiniTest::Mock.new
45
+ truster.expect :untrust, nil, [Ironment::Runcom.new("foo")]
46
+
47
+ Ironment.new(truster: truster).untrust "foo"
48
+
49
+ truster.verify
50
+ end
51
+ end
30
52
  end
data/test/runcom_test.rb CHANGED
@@ -66,6 +66,16 @@ describe Ironment::Runcom do
66
66
 
67
67
  assert_equal 0, enum.count
68
68
  end
69
+
70
+ it "should raise MalformedRuncom upon reading a malformed file" do
71
+ File.write(".envrc", <<-DAT.gsub(/^\s+/, ""))
72
+ FOO+1
73
+ DAT
74
+
75
+ assert_raises Ironment::MalformedRuncom do
76
+ Ironment::Runcom.new(".envrc").each_pair
77
+ end
78
+ end
69
79
  end
70
80
 
71
81
  describe "#==" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ironment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Amundsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-07 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.6.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.4.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.4.4
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: minitest
57
85
  requirement: !ruby/object:Gem::Requirement