File: response_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 (92 lines) | stat: -rw-r--r-- 2,771 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'spec_helper'

describe Fission::Response do
  describe 'initialize' do
    it 'should allow you to set the code' do
      Fission::Response.new(:code => 1).code.should == 1
    end

    it 'should set the code to 1 if not provided' do
      Fission::Response.new.code.should == 1
    end

    it 'should allow you to set the message' do
      Fission::Response.new(:message => 'foobar').message.should == 'foobar'
    end

    it 'should set the message to an empty string if not provided' do
      Fission::Response.new.message.should == ''
    end

    it 'should set the data to nil if not provided' do
      Fission::Response.new.data.should be_nil
    end

  end

  describe 'code' do
    it 'should allow you to set the code' do
      @response = Fission::Response.new
      @response.code = 4
      @response.code.should == 4
    end
  end

  describe 'successful?' do
    it 'should return true if the code is 0' do
      Fission::Response.new(:code => 0).successful?.should == true
    end

    it 'should return false if the code is not 0' do
      Fission::Response.new(:code => 1).successful?.should == false
    end
  end

  describe 'message' do
    it 'should allow you to set the message' do
      @response = Fission::Response.new
      @response.message = 'foobar'
      @response.message.should == 'foobar'
    end
  end

  describe 'data' do
    it 'should allow you to set the data' do
      @response = Fission::Response.new
      @response.data = [1, 2, 3]
      @response.data.should == [1, 2, 3]
    end
  end

  describe 'self.from_shell_executor' do
    before do
      @process_status = double('process status')
    end

    it 'should return a response object' do
      @process_status.stub(:exitstatus).and_return(0)
      executor = {'process_status' => @process_status}
      Fission::Response.from_shell_executor(executor).should be_a Fission::Response
    end

    it 'should set the code to the exit status' do
      @process_status.stub(:exitstatus).and_return(55)
      executor = {'process_status' => @process_status}
      Fission::Response.from_shell_executor(executor).code.should == 55
    end

    it 'should set the message if the command was unsuccessful' do
      @process_status.stub(:exitstatus).and_return(55)
      executor = {'process_status' => @process_status,
                  'output'         => 'foo'}
      Fission::Response.from_shell_executor(executor).message.should == 'foo'
    end
    it 'should not set the message if the command was successful' do
      @process_status.stub(:exitstatus).and_return(0)
      executor = {'process_status' => @process_status,
                  'output'         => 'foo'}
      Fission::Response.from_shell_executor(executor).message.should == ''
    end

  end
end