Module: CommandTest

Defined in:
lib/command_test.rb,
lib/command_test/tests.rb,
lib/command_test/parser.rb,
lib/command_test/matcher.rb,
lib/command_test/version.rb,
lib/command_test/adapters/rspec.rb,
lib/command_test/core_extensions.rb,
lib/command_test/adapters/test_unit.rb

Defined Under Namespace

Modules: Adapters, CoreExtensions, RSpec, Tests Classes: Matcher, Parser

Constant Summary collapse

VERSION =
[0, 0, 1]

Class Method Summary collapse

Class Method Details

.match?(expected, actual) ⇒ Boolean

Return true if the given actual command matches the expected spec.

The elements of expected may be one of these:

* A String in +expected+ matches the corresponding element in
  +actual+.
* A Regexp must match the corresponding element in +actual+.
* An Integer, n, matches the next n elements of +actual+.
* A Range, a...b, can match the next i elements of +actual+,
  for a <= i < b.
* :+ can match 1 or more elements in +actual+.
* :* can match any number of elements (including zero) in
  +actual+.

Returns:

  • (Boolean)


42
43
44
# File 'lib/command_test.rb', line 42

def match?(expected, actual)
  matcher.match?(expected, actual)
end

.recordObject

Return the list of commands run during the given block.

Each command is an Array of “words” (command and arguments).



15
16
17
18
19
20
21
22
23
24
# File 'lib/command_test.rb', line 15

def record
  commands = []
  recorders << lambda{|c| commands << c}
  begin
    yield
  ensure
    recorders.pop
  end
  commands
end

.record_command(command, *args) ⇒ Object

:nodoc:



46
47
48
49
# File 'lib/command_test.rb', line 46

def record_command(command, *args) # :nodoc:
  words = Shellwords.shellwords(command).concat(args)
  recorders.each{|r| r.call(words)}
end

.record_interpreted_command(command) ⇒ Object

:nodoc:



51
52
53
54
# File 'lib/command_test.rb', line 51

def record_interpreted_command(command) # :nodoc:
  words = parser.parse(command)
  recorders.each{|r| r.call(words)}
end