File: interface_spec.rb

package info (click to toggle)
ruby-fogbugz 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: ruby: 199; makefile: 3
file content (51 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download
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
RSpec.describe 'Interface' do
  let(:credentials) { { email: 'test@example.com', password: 'seekrit', uri: 'https://fogbugz.example.com' } }

  context 'initialization' do
    it 'options are publicly available' do
      fogbugz = Fogbugz::Interface.new(credentials)
      expect(fogbugz.options).to eq(credentials)
    end

    it 'raises exception without URI' do
      expect { Fogbugz::Interface.new }.to raise_error(Fogbugz::Interface::InitializationError)
    end
  end

  context 'when credentials are valid' do
    let(:fogbugz) { Fogbugz::Interface.new(credentials) }

    it '#authenticate returns a token' do
      token = fogbugz.authenticate
      expect(token).not_to be_nil
    end

    it '#command returns result' do
      fogbugz.token = 'abcdefabcdefabcdef'
      fogbugz.command(:search, q: '1')
    end
  end

  context 'when credentials are invalid' do
    let(:credentials) { super().merge(password: 'invalid') }
    let(:fogbugz) { Fogbugz::Interface.new(credentials) }

    it '#authenticate raises an exception' do
      expect { fogbugz.authenticate }.to raise_error(Fogbugz::AuthenticationException, 'Incorrect password or username')
    end

    it '#command raises an exception' do
      fogbugz.token = nil
      expect { fogbugz.command(:search, q: 'case') }.to raise_error(Fogbugz::Interface::RequestError)
    end
  end

  context 'when server does not reply as expected' do
    let(:credentials) { super().merge(uri: 'https://notfogbugz.example.com') }
    let(:fogbugz) { Fogbugz::Interface.new(credentials) }

    it '#authenticate raises an exception' do
      expect { fogbugz.authenticate }.to raise_error(Fogbugz::AuthenticationException)
    end
  end
end