Module: Caliph::CommandLineExampleGroup

Includes:
CommandLineDSL
Defined in:
lib/caliph/testing/mock-command-line.rb

Defined Under Namespace

Modules: MockingExecute

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommandLineDSL

#cmd, #escaped_command

Class Method Details

.included(group) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/caliph/testing/mock-command-line.rb', line 45

def self.included(group)
  group.before :each do
    @original_execute = Caliph::Shell.instance_method(:execute)
    @reporting_stream = StringIO.new
    unless MockingExecute > Caliph::Shell
      Caliph::Shell.send(:include, MockingExecute)
    end
    Caliph::Shell.send(:remove_method, :execute)
    Caliph::Shell.any_instance.stub(:output_stream => @reporting_stream)
  end

  group.after :each do
    Caliph::Shell.send(:define_method, :execute, @original_execute)
  end
end

Instance Method Details

#expect_command(cmd, *result) ⇒ Object

Registers an expectation about a command being run - expectations are ordered



68
69
70
# File 'lib/caliph/testing/mock-command-line.rb', line 68

def expect_command(cmd, *result)
  Caliph::MockShell.should_receive(:execute_string, :expected_from => caller(1)[0]).with(cmd).ordered.and_return(MockCommandResult.create(*result))
end

#expect_some_commandsObject

Registers indifference as to exactly what commands get called



62
63
64
# File 'lib/caliph/testing/mock-command-line.rb', line 62

def expect_some_commands
  Caliph::MockShell.should_receive(:execute_string).any_number_of_times.and_return(MockCommandResult.create(0))
end