caliph 0.3.0 → 0.3.1

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: 8bc37eb0ffecf0d003a9144cf99d8f9a1c939615
4
- data.tar.gz: a01552b706ec5dd873175abe5d299716312bdcbc
3
+ metadata.gz: dc5ce22c06862354326d17dd565011e0a1400c2b
4
+ data.tar.gz: e807f8ba5aee6acbff65f4914e07a45cfe041e77
5
5
  SHA512:
6
- metadata.gz: 69b432bb2de573c7694ec6191afbf3ec103bf3cfa027e9022cec0c2e9a201774081819e5a1c5d6bf1e774ce88fe08b364bce6418f4dc01a95466071f21e6a6fe
7
- data.tar.gz: 72c5668ae540aee64b20db9eb55fcc7c19ed98ae9e96bb0938e83ae60f40bb390b8c307405058de795964a4a64e7543cd40084387c3127931441b53c290f4155
6
+ metadata.gz: 633740377edb77bc21209b85ef40fc0e12951e31deef6889311c34ba1e3175a355dc35105ee2bbe85f96681c3d5bbaea28bbd534f5eb76c297e2d7fc00119453
7
+ data.tar.gz: 36bf32376cd2e8bc619d133b0cae4e727bd64a8d7aff2ae78d5b7d8402f941d528272d861e51a00f97386842eb8b3c5a7d66bce27a2de90cce3bf8387ee9f36c
@@ -10,7 +10,13 @@ module Caliph
10
10
  end
11
11
 
12
12
  def escaped_command(*args, &block)
13
- ShellEscaped.new(CommandLine.new(*args, &block))
13
+ command = nil
14
+ if args.length == 1 and args.first.is_a? CommandLine
15
+ command = args.first
16
+ else
17
+ command = cmd(*args, &block)
18
+ end
19
+ ShellEscaped.new(command)
14
20
  end
15
21
  end
16
22
  end
@@ -56,6 +56,7 @@ module Caliph
56
56
  rescue
57
57
  return false
58
58
  end
59
+ alias succeeds? succeeded?
59
60
 
60
61
  # Nicely formatted output of stdout and stderr - won't be intermixed, which
61
62
  # may be different than what you'd see live in the shell
@@ -70,7 +71,7 @@ module Caliph
70
71
  when 0
71
72
  return exit_code
72
73
  else
73
- fail "Command #{@command.inspect} failed with exit status #{exit_code}: \n#{format_streams}"
74
+ fail "Command '#{@command.string_format}' failed with exit status #{exit_code}: \n#{format_streams}"
74
75
  end
75
76
  end
76
77
 
@@ -21,5 +21,9 @@ module Caliph
21
21
  def to_s
22
22
  command
23
23
  end
24
+
25
+ def valid?
26
+ @escaped.valid?
27
+ end
24
28
  end
25
29
  end
@@ -56,7 +56,7 @@ module Caliph
56
56
  end
57
57
  #raise InvalidCommand, "not a command line: #{command_line.inspect}"
58
58
  #unless command_line.is_a? CommandLine
59
- raise IncompleteCommand, "cannot run #{command_line}" unless command_line.valid?
59
+ raise IncompleteCommand, "cannot run #{command_line.inspect}" unless command_line.valid?
60
60
  command_line
61
61
  end
62
62
  protected :normalize_command_line
@@ -24,44 +24,49 @@ module Caliph
24
24
  alias exit_status exit_code
25
25
  end
26
26
 
27
- class CommandLine
28
- def self.execute(*args)
29
- fail "Command line executed in specs without 'expect_command' or 'expect_some_commands'"
27
+ class MockShell
28
+ def self.execute(command_line, *args)
29
+ execute_string(command_line.string_format)
30
+ end
31
+
32
+ def self.execute_string(string)
33
+ fail "Command line executed in specs without 'expect_command' or 'expect_some_commands' (string was: #{string})"
30
34
  end
31
35
  end
32
36
 
33
37
  module CommandLineExampleGroup
34
38
  include CommandLineDSL
35
39
  module MockingExecute
36
- def execute
37
- Caliph::CommandLine.execute(command)
40
+ def execute(command)
41
+ Caliph::MockShell.execute(command)
38
42
  end
39
43
  end
40
44
 
41
-
42
45
  def self.included(group)
43
46
  group.before :each do
44
- @original_execute = Caliph::CommandLine.instance_method(:execute)
45
- unless MockingExecute > Caliph::CommandLine
46
- Caliph::CommandLine.send(:include, MockingExecute)
47
+ @original_execute = Caliph::Shell.instance_method(:execute)
48
+ @reporting_stream = StringIO.new
49
+ unless MockingExecute > Caliph::Shell
50
+ Caliph::Shell.send(:include, MockingExecute)
47
51
  end
48
- Caliph::CommandLine.send(:remove_method, :execute)
52
+ Caliph::Shell.send(:remove_method, :execute)
53
+ Caliph::Shell.any_instance.stub(:output_stream => @reporting_stream)
49
54
  end
50
55
 
51
56
  group.after :each do
52
- Caliph::CommandLine.send(:define_method, :execute, @original_execute)
57
+ Caliph::Shell.send(:define_method, :execute, @original_execute)
53
58
  end
54
59
  end
55
60
 
56
61
  #Registers indifference as to exactly what commands get called
57
62
  def expect_some_commands
58
- Caliph::CommandLine.should_receive(:execute).any_number_of_times.and_return(MockCommandResult.create(0))
63
+ Caliph::MockShell.should_receive(:execute_string).any_number_of_times.and_return(MockCommandResult.create(0))
59
64
  end
60
65
 
61
66
  #Registers an expectation about a command being run - expectations are
62
67
  #ordered
63
68
  def expect_command(cmd, *result)
64
- Caliph::CommandLine.should_receive(:execute, :expected_from => caller(1)[0]).with(cmd).ordered.and_return(MockCommandResult.create(*result))
69
+ Caliph::MockShell.should_receive(:execute_string, :expected_from => caller(1)[0]).with(cmd).ordered.and_return(MockCommandResult.create(*result))
65
70
  end
66
71
  end
67
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caliph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Dorn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-16 00:00:00.000000000 Z
12
+ date: 2014-07-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |2
15
15
  TDD-suitable Ruby tool for generating command-line commands via an OOP interface.
@@ -102,7 +102,7 @@ rdoc_options:
102
102
  - --main
103
103
  - doc/README
104
104
  - --title
105
- - caliph-0.3.0 Documentation
105
+ - caliph-0.3.1 Documentation
106
106
  require_paths:
107
107
  - lib/
108
108
  required_ruby_version: !ruby/object:Gem::Requirement