File: command_helpers_spec.rb

package info (click to toggle)
ruby-fission 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 4,664; makefile: 10
file content (52 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'spec_helper'

describe Fission::CommandHelpers do
  include_context 'command_setup'

  before do
    @object = Object.new
    @object.extend Fission::CommandHelpers
    @object.class.stub(:help).and_return('foo help')
  end

  describe 'incorrect_arguments' do
    before do
      @object.stub(:command_name)
      @object.stub(:output)
      @object.stub(:output_and_exit)
    end

    it "should output the command's help text" do
      @object.stub(:command_name)
      @object.should_receive(:output).with(/foo help/)
      @object.incorrect_arguments
    end

    it 'should output that the argumets are incorrect and exit' do
      @object.stub(:command_name).and_return('delete')
      @object.should_receive(:output_and_exit).
              with('Incorrect arguments for delete command', 1)
      @object.incorrect_arguments
    end
  end

  describe 'parse arguments' do
    before do
      @object.stub(:option_parser).and_return(@object)
    end

    it 'should parse the arguments' do
      @object.stub :parse!
      @object.parse_arguments
    end

    it 'should output the error with help' do
      error = OptionParser::InvalidOption.new 'bar is invalid'
      @object.should_receive(:output).with(error)
      @object.should_receive(:output_and_exit).with(/foo help/, 1)
      @object.stub(:parse!).and_raise(error)
      @object.parse_arguments
    end
  end

end