Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sawyer_patch_spec.rb « initializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9fcdc9583aac91b6f71c2b2abb1efc64b410482f (plain)
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
# frozen_string_literal: true

require 'spec_helper'
require 'sawyer'

require_relative '../../config/initializers/sawyer_patch'

RSpec.describe 'sawyer_patch' do
  it 'raises error when acessing Sawyer Resource dynamic methods' do
    sawyer_resource = Sawyer::Resource.new(
      Sawyer::Agent.new(''),
      {
        to_s: 'Overriding method',
        nil?: 'value',
        login: 'Login',
        user: { to_s: 'Overriding method', name: 'User name' }
      }
    )

    expect { sawyer_resource.to_s }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.to_s? }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.to_s = 'new value' }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.nil? }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.user.to_s }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.login }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.login? }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.login = 'New value' }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.user.name }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.user.name? }.to raise_error(Sawyer::Error)
    expect { sawyer_resource.user.name = 'New value' }.to raise_error(Sawyer::Error)
  end

  it 'raises error when acessing a method that expects an argument' do
    sawyer_resource = Sawyer::Resource.new(
      Sawyer::Agent.new(''),
      {
        'user': 'value',
        'user=': 'value',
        '==': 'value',
        '!=': 'value',
        '+': 'value'
      }
    )

    expect { sawyer_resource == true }.to raise_error(ArgumentError)
    expect { sawyer_resource != true }.to raise_error(ArgumentError)
    expect { sawyer_resource + 1 }.to raise_error(ArgumentError)
  end
end